Skip to content

Commit dfcc308

Browse files
committed
tests
1 parent 1f5e20e commit dfcc308

File tree

10 files changed

+32
-18
lines changed

10 files changed

+32
-18
lines changed

telegram/ext/basepersistence.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ class BasePersistence(ABC):
6666
store_chat_data (:obj:`bool`, optional): Whether chat_data should be saved by this
6767
persistence class. Default is :obj:`True` .
6868
store_bot_data (:obj:`bool`, optional): Whether bot_data should be saved by this
69-
persistence class. Default is :obj:`True` .
69+
persistence class. Default is :obj:`True`.
7070
store_callback_data (:obj:`bool`, optional): Whether callback_data should be saved by this
71-
persistence class. Default is ``True`` .
71+
persistence class. Default is :obj:`False`.
7272
7373
Attributes:
7474
store_user_data (:obj:`bool`): Optional, Whether user_data should be saved by this
@@ -121,7 +121,7 @@ def __init__(
121121
store_user_data: bool = True,
122122
store_chat_data: bool = True,
123123
store_bot_data: bool = True,
124-
store_callback_data: bool = True,
124+
store_callback_data: bool = False,
125125
):
126126
self.store_user_data = store_user_data
127127
self.store_chat_data = store_chat_data
@@ -325,7 +325,6 @@ def get_bot_data(self) -> Dict[Any, Any]:
325325
:obj:`dict`: The restored bot data.
326326
"""
327327

328-
@abstractmethod
329328
def get_callback_data(self) -> Dict[str, Any]:
330329
""" "Will be called by :class:`telegram.ext.Dispatcher` upon creation with a
331330
persistence object. It should return the callback_data if stored, or an empty
@@ -334,6 +333,7 @@ def get_callback_data(self) -> Dict[str, Any]:
334333
Returns:
335334
:obj:`dict`: The restored bot data.
336335
"""
336+
raise NotImplementedError
337337

338338
@abstractmethod
339339
def get_conversations(self, name: str) -> ConversationDict:
@@ -391,14 +391,14 @@ def update_bot_data(self, data: Dict) -> None:
391391
data (:obj:`dict`): The :attr:`telegram.ext.dispatcher.bot_data` .
392392
"""
393393

394-
@abstractmethod
395394
def update_callback_data(self, data: Dict[str, Any]) -> None:
396395
"""Will be called by the :class:`telegram.ext.Dispatcher` after a handler has
397396
handled an update.
398397
399398
Args:
400399
data (:obj:`dict`): The :attr:`telegram.ext.dispatcher.update_callback_data` .
401400
"""
401+
raise NotImplementedError
402402

403403
def flush(self) -> None:
404404
"""Will be called by :class:`telegram.ext.Updater` upon receiving a stop signal. Gives the

telegram/ext/dictpersistence.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ class DictPersistence(BasePersistence):
6262
store_chat_data (:obj:`bool`, optional): Whether user_data should be saved by this
6363
persistence class. Default is :obj:`True`.
6464
store_bot_data (:obj:`bool`, optional): Whether bot_data should be saved by this
65-
persistence class. Default is :obj:`True` .
65+
persistence class. Default is :obj:`True`.
6666
store_callback_data (:obj:`bool`, optional): Whether callback_data should be saved by this
67-
persistence class. Default is ``True`` .
67+
persistence class. Default is :obj:`False`.
6868
user_data_json (:obj:`str`, optional): Json string that will be used to reconstruct
6969
user_data on creating this persistence. Default is ``""``.
7070
chat_data_json (:obj:`str`, optional): Json string that will be used to reconstruct
@@ -94,7 +94,7 @@ def __init__(
9494
chat_data_json: str = '',
9595
bot_data_json: str = '',
9696
conversations_json: str = '',
97-
store_callback_data: bool = True,
97+
store_callback_data: bool = False,
9898
callback_data_json: str = '',
9999
):
100100
super().__init__(

telegram/ext/jobqueue.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def _build_args(self, job: 'Job') -> List[Union[CallbackContext, 'Bot', 'Job']]:
7676
def _tz_now(self) -> datetime.datetime:
7777
return datetime.datetime.now(self.scheduler.timezone)
7878

79-
def _update_persistence(self, event: JobEvent) -> None: # pylint: disable=W0613
79+
def _update_persistence(self, _: JobEvent) -> None:
8080
self._dispatcher.update_persistence()
8181

8282
def _dispatch_error(self, event: JobEvent) -> None:

telegram/ext/picklepersistence.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class PicklePersistence(BasePersistence):
4848
store_bot_data (:obj:`bool`, optional): Whether bot_data should be saved by this
4949
persistence class. Default is :obj:`True`.
5050
store_callback_data (:obj:`bool`, optional): Whether callback_data should be saved by this
51-
persistence class. Default is ``True``.
51+
persistence class. Default is :obj:`False`.
5252
single_file (:obj:`bool`, optional): When :obj:`False` will store 3 separate files of
5353
`filename_user_data`, `filename_chat_data` and `filename_conversations`. Default is
5454
:obj:`True`.
@@ -85,7 +85,7 @@ def __init__(
8585
store_bot_data: bool = True,
8686
single_file: bool = True,
8787
on_flush: bool = False,
88-
store_callback_data: bool = True,
88+
store_callback_data: bool = False,
8989
):
9090
super().__init__(
9191
store_user_data=store_user_data,

tests/test_dispatcher.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,9 @@ def get_bot_data(self):
727727
def get_user_data(self):
728728
pass
729729

730+
def get_callback_data(self):
731+
pass
732+
730733
def get_conversations(self, name):
731734
pass
732735

tests/test_error.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
ChatMigrated,
3232
RetryAfter,
3333
Conflict,
34+
InvalidCallbackData,
3435
)
3536

3637

@@ -112,6 +113,7 @@ def test_conflict(self):
112113
(RetryAfter(12), ["message", "retry_after"]),
113114
(Conflict("test message"), ["message"]),
114115
(TelegramDecryptionError("test message"), ["message"]),
116+
(InvalidCallbackData(789), ['update_id']),
115117
],
116118
)
117119
def test_errors_pickling(self, exception, attributes):
@@ -147,6 +149,7 @@ def make_assertion(cls):
147149
RetryAfter,
148150
Conflict,
149151
TelegramDecryptionError,
152+
InvalidCallbackData,
150153
},
151154
NetworkError: {BadRequest, TimedOut},
152155
}

tests/test_jobqueue.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ def test_run_monthly(self, job_queue, timezone):
314314
next_months_days = calendar.monthrange(now.year, now.month + 1)[1]
315315

316316
expected_reschedule_time += dtm.timedelta(this_months_days)
317-
if next_months_days < this_months_days:
317+
if day > next_months_days:
318318
expected_reschedule_time += dtm.timedelta(next_months_days)
319319

320320
expected_reschedule_time = timezone.normalize(expected_reschedule_time)

tests/test_message.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ def message(bot):
157157
]
158158
},
159159
},
160-
{'quote': True},
161160
{'dice': Dice(4, '🎲')},
162161
{'via_bot': User(9, 'A_Bot', True)},
163162
{

tests/test_persistence.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,17 +183,20 @@ def test_creation(self, base_persistence):
183183
assert base_persistence.store_user_data
184184
assert base_persistence.store_bot_data
185185

186-
def test_abstract_methods(self):
186+
def test_abstract_methods(self, base_persistence):
187187
with pytest.raises(
188188
TypeError,
189189
match=(
190190
'get_bot_data, get_chat_data, get_conversations, '
191191
'get_user_data, update_bot_data, update_chat_data, '
192-
'update_conversation, update_user_data, '
193-
'get_callback_data, update_callback_data'
192+
'update_conversation, update_user_data'
194193
),
195194
):
196195
BasePersistence()
196+
with pytest.raises(NotImplementedError):
197+
base_persistence.get_callback_data()
198+
with pytest.raises(NotImplementedError):
199+
base_persistence.update_callback_data({'foo': 'bar'})
197200

198201
def test_implementation(self, updater, base_persistence):
199202
dp = updater.dispatcher
@@ -2009,7 +2012,7 @@ def job_callback(context):
20092012
context.dispatcher.user_data[789]['test3'] = '123'
20102013
context.dispatcher.callback_data['test'] = 'Working3!'
20112014

2012-
dict_persistence = DictPersistence()
2015+
dict_persistence = DictPersistence(store_callback_data=True)
20132016
cdp.persistence = dict_persistence
20142017
job_queue.set_dispatcher(cdp)
20152018
job_queue.start()

tests/test_updater.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,13 @@ def test_webhook_invalid_callback_data(self, monkeypatch, updater):
347347
from_user=None,
348348
chat_instance=123,
349349
data='invalid data',
350-
message=Message(1, User(1, '', False), None, Chat(1, ''), text='Webhook'),
350+
message=Message(
351+
1,
352+
from_user=User(1, '', False),
353+
date=None,
354+
chat=Chat(1, ''),
355+
text='Webhook',
356+
),
351357
),
352358
)
353359
self._send_webhook_msg(ip, port, update.to_json(), 'TOKEN')

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy