def test_extract_message_links(self): test_entities = [ { 'length': 17, 'offset': 0, 'type': 'url', }, { 'length': 11, 'offset': 18, 'type': 'text_link', 'url': 'https://t.me/group_name/123456', }, { 'length': 12, 'offset': 30, 'type': 'text_link', 'url': 't.me/c/1173342352/256' }, { 'length': 11, 'offset': 43, 'type': 'text_link', 'url': 'https://t.me/joinchat/BHFkvxrbaIpgGsEJnO_pew', }, { 'length': 10, 'offset': 55, 'type': 'text_link', 'url': 'https://t.me/pythontelegrambotgroup', }, ] test_text = 'https://google.de public_link private_link invite_link group_link' test_message = Message( message_id=1, from_user=None, date=None, chat=None, text=test_text, entities=[MessageEntity(**e) for e in test_entities], ) results = extract_urls.extract_message_links(test_message) assert len(results) == 2 assert results[0] == test_entities[1]['url'] assert results[1] == test_entities[2]['url'] results = extract_urls.extract_message_links(test_message, private_only=True) assert len(results) == 1 assert results[0] == test_entities[2]['url'] results = extract_urls.extract_message_links(test_message, public_only=True) assert len(results) == 1 assert results[0] == test_entities[1]['url']
def test_extract_message_links_value_error(self): with pytest.raises(ValueError): extract_urls.extract_message_links(None, public_only=True, private_only=True)