async def test_no_username_set(requests_mock): username = "" event = MockTelegramEvent.with_inline_query(query=f"gallery:{username}") inline = InlineFunctionality(MockExportAPI()) # mock export api doesn't do non-existent users, so mocking with requests inline.api = FAExportAPI("http://example.com", ignore_status=True) requests_mock.get( f"http://example.com/user/{username}/gallery.json?page=1&full=1", json={ "id": None, "name": "gallery", "profile": "https://www.furaffinity.net/user/gallery/" }) with pytest.raises(StopPropagation): await inline.call(event) event.answer.assert_called_once() args = event.answer.call_args[0] assert event.answer.call_args[1]['next_offset'] is None assert event.answer.call_args[1]['gallery'] is False assert isinstance(args[0], list) assert len(args[0]) == 1 assert isinstance(args[0][0], _MockInlineBuilder._MockInlineArticle) assert args[0][0].kwargs == { "title": "User does not exist.", "description": f"FurAffinity user does not exist by the name: \"{username}\".", "text": f"FurAffinity user does not exist by the name: \"{username}\".", }
async def test_username_with_colon(requests_mock): # FA doesn't allow usernames to have : in them username = "******" event = MockTelegramEvent.with_inline_query(query=f"gallery:{username}") inline = InlineFunctionality(MockExportAPI()) # mock export api doesn't do non-existent users, so mocking with requests inline.api = FAExportAPI("http://example.com", ignore_status=True) requests_mock.get(f"http://example.com/user/{username}/gallery.json", status_code=404) with pytest.raises(StopPropagation): await inline.call(event) event.answer.assert_called_once() args = event.answer.call_args[0] assert event.answer.call_args[1]['next_offset'] is None assert event.answer.call_args[1]['gallery'] is False assert isinstance(args[0], list) assert len(args[0]) == 1 assert isinstance(args[0][0], _MockInlineBuilder._MockInlineArticle) assert args[0][0].kwargs == { "title": "User does not exist.", "description": f"FurAffinity user does not exist by the name: \"{username}\".", "text": f"FurAffinity user does not exist by the name: \"{username}\".", }