-
Notifications
You must be signed in to change notification settings - Fork 45
Open
Description
Hi!
Thank you for the module!
I try to make my bot based on it. And I've met a problem. When I try to test bot creation, it tries to set a webhook in real telegram. But it uses hardcoded test token from https://github.com/jlmadurga/django-telegram-bot/blob/master/telegrambot/test/factories/bot.py
and test fails on it.
Here's stack trace:
ERROR: test_start (tests.test_commands.TestSimpleCommands)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/el/Projects/dj-tg-alpha-bot/.tox/py34/lib/python3.4/site-packages/telegram/utils/request.py", line 67, in decorator
return func(*args, **kwargs)
File "/Users/el/Projects/dj-tg-alpha-bot/.tox/py34/lib/python3.4/site-packages/telegram/utils/request.py", line 140, in post
result = urlopen(request, timeout=timeout).read()
File "/Users/el/.pyenv/versions/3.4.5/lib/python3.4/urllib/request.py", line 161, in urlopen
return opener.open(url, data, timeout)
File "/Users/el/.pyenv/versions/3.4.5/lib/python3.4/urllib/request.py", line 470, in open
response = meth(req, response)
File "/Users/el/.pyenv/versions/3.4.5/lib/python3.4/urllib/request.py", line 580, in http_response
'http', request, response, code, msg, hdrs)
File "/Users/el/.pyenv/versions/3.4.5/lib/python3.4/urllib/request.py", line 508, in error
return self._call_chain(*args)
File "/Users/el/.pyenv/versions/3.4.5/lib/python3.4/urllib/request.py", line 442, in _call_chain
result = func(*args)
File "/Users/el/.pyenv/versions/3.4.5/lib/python3.4/urllib/request.py", line 588, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 429: Too Many Requests
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/el/Projects/dj-tg-alpha-bot/tests/test_commands.py", line 24, in setUp
super().setUp()
File "/Users/el/Projects/dj-tg-alpha-bot/.tox/py34/lib/python3.4/site-packages/telegrambot/test/testcases.py", line 20, in setUp
self.bot = factories.BotFactory()
File "/Users/el/Projects/dj-tg-alpha-bot/.tox/py34/lib/python3.4/site-packages/factory/base.py", line 81, in __call__
return cls.create(**kwargs)
File "/Users/el/Projects/dj-tg-alpha-bot/.tox/py34/lib/python3.4/site-packages/factory/base.py", line 567, in create
return cls._generate(True, attrs)
File "/Users/el/Projects/dj-tg-alpha-bot/.tox/py34/lib/python3.4/site-packages/factory/base.py", line 492, in _generate
obj = cls._prepare(create, **attrs)
File "/Users/el/Projects/dj-tg-alpha-bot/.tox/py34/lib/python3.4/site-packages/factory/base.py", line 467, in _prepare
return cls._create(model_class, *args, **kwargs)
File "/Users/el/Projects/dj-tg-alpha-bot/.tox/py34/lib/python3.4/site-packages/factory/django.py", line 174, in _create
return manager.create(*args, **kwargs)
File "/Users/el/Projects/dj-tg-alpha-bot/.tox/py34/lib/python3.4/site-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/Users/el/Projects/dj-tg-alpha-bot/.tox/py34/lib/python3.4/site-packages/django/db/models/query.py", line 399, in create
obj.save(force_insert=True, using=self.db)
File "/Users/el/Projects/dj-tg-alpha-bot/.tox/py34/lib/python3.4/site-packages/django/db/models/base.py", line 796, in save
force_update=force_update, update_fields=update_fields)
File "/Users/el/Projects/dj-tg-alpha-bot/.tox/py34/lib/python3.4/site-packages/django/db/models/base.py", line 833, in save_base
update_fields=update_fields, raw=raw, using=using)
File "/Users/el/Projects/dj-tg-alpha-bot/.tox/py34/lib/python3.4/site-packages/django/dispatch/dispatcher.py", line 191, in send
response = receiver(signal=self, sender=sender, **named)
File "/Users/el/Projects/dj-tg-alpha-bot/.tox/py34/lib/python3.4/site-packages/telegrambot/models/bot.py", line 74, in set_api
certificate=cert)
File "/Users/el/Projects/dj-tg-alpha-bot/.tox/py34/lib/python3.4/site-packages/telegram/bot.py", line 127, in decorator
result = func(self, *args, **kwargs)
File "/Users/el/Projects/dj-tg-alpha-bot/.tox/py34/lib/python3.4/site-packages/telegram/bot.py", line 725, in setWebhook
result = request.post(url, data)
File "/Users/el/Projects/dj-tg-alpha-bot/.tox/py34/lib/python3.4/site-packages/telegram/utils/request.py", line 79, in decorator
raise TelegramError(message)
telegram.error.TelegramError: Too Many Requests: retry after 1
I think it's not very good to use your test bot :)
How to do better:
- Try to feed it with correct data of specially created bots?
- Mock call to real telegram? Do we need to check what real bot tried to call telegram api?
For a moment I've made a workaround to mock up calls and quietly ignore it - https://github.com/lisitsky/dj-tg-alpha-bot/blob/master/tests/test_commands.py#L16
If you wish I can make a patch and pull-request so we can not to call real api.
Thank you!
Metadata
Metadata
Assignees
Labels
No labels