Skip to content

Commit e33b2e3

Browse files
committed
None conditions
1 parent 7d1537f commit e33b2e3

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

telegram/utils/helpers.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ def create_deep_linked_url(bot_username, payload=None):
161161
Returns:
162162
:obj:`str`: An URL to start the bot with specific parameters
163163
"""
164+
if bot_username is None or len(bot_username) <= 3:
165+
raise ValueError("You must provide a valid bot_username.")
166+
164167
base_url = 'https://t.me/{}'.format(bot_username)
165168
if not payload:
166169
return base_url

tests/test_helpers.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@
1818
# along with this program. If not, see [http://www.gnu.org/licenses/].
1919
import pytest
2020

21-
from telegram import Update
22-
2321
from telegram import Sticker
22+
from telegram import Update
2423
from telegram import User
2524
from telegram.message import Message
2625
from telegram.utils import helpers
@@ -43,15 +42,22 @@ def test_create_deep_linked_url(self):
4342

4443
payload = ""
4544
expected = "https://t.me/{}".format(username)
46-
assert expected == helpers.create_deep_linked_url(username, payload)
4745
assert expected == helpers.create_deep_linked_url(username)
46+
assert expected == helpers.create_deep_linked_url(username, payload)
47+
payload = None
48+
assert expected == helpers.create_deep_linked_url(username, payload)
4849

4950
with pytest.raises(ValueError):
5051
helpers.create_deep_linked_url(username, 'text with spaces')
5152

5253
with pytest.raises(ValueError):
5354
helpers.create_deep_linked_url(username, '0' * 65)
5455

56+
with pytest.raises(ValueError):
57+
helpers.create_deep_linked_url(None, None)
58+
with pytest.raises(ValueError): # too short username (4 is minimum)
59+
helpers.create_deep_linked_url("abc", None)
60+
5561
def test_effective_message_type(self):
5662
test_message = Message(message_id=1,
5763
from_user=None,

0 commit comments

Comments
 (0)