def test_delete_existing_group(client: BotIntegrationClient): client.send_message(text="test_delete_existing_group", chat_id=config('BOT_NAME')) group_name = create_group_command(client) menu = enter_group(client, group_name) delete_group_command(client, group_name, menu)
def test_create_group_with_valid_symbols(client: BotIntegrationClient): client.send_message(text="test_create_group_with_valid_symbols", chat_id=config('BOT_NAME')) group_name = create_group_command(client) assert group_is_existing( client, group_name), "Cannot find created group in the list"
def test_create_group_abort(client: BotIntegrationClient): client.send_message(text="test_create_group_abort", chat_id=config('BOT_NAME')) response = client.send_command_await("/create", num_expected=1) assert response.num_messages == 1 assert response.full_text.startswith("Ok, send the name of the group") response = client.send_command_await("/cancel", num_expected=1) assert response.num_messages == 1 assert response.full_text.startswith("Sure, what now?")
def test_add_members_to_existing_group(client: BotIntegrationClient): client.send_message(text="test_add_members_to_existing_group", chat_id=config('BOT_NAME')) group_name = create_group_command(client) group_name = enter_group(client, group_name) button = group_name.inline_keyboards[0].press_button_await( pattern=r'.*Add members', min_wait_consecutive=5) assert not button.empty, 'Pressing "Add members" button had no effect.' assert button.full_text.startswith( 'Ok, send'), "Adding users' message has been changed." user_name = generate_name() response = client.send_message_await(user_name, num_expected=1) assert response.full_text.startswith("Added") response = client.send_command_await("/done", num_expected=2) assert response[0].text.startswith('Saved new members') members = response[1].text.split('\n')[3:] members = [item.split()[1] for item in members] assert user_name in members, "User hasn't been added"
) from tgintegration import InvalidResponseError try: # The following instruction will raise an `InvalidResponseError` after # `service.max_wait_response` seconds. This is because we passed `raise_no_response = True` # in the service initialization. print("Expecting undefined command to raise InvalidResponseError...") client.send_command_await("ayylmao", raise_=True) except InvalidResponseError: print("Raised.") # Ok # The `BotController` is based off a regular Pyrogram Client, meaning that, in addition to # the `send_*_await` methods, all normal Pyro methods still work: print("Calling a normal `send_message` method...") client.send_message(client.bot_under_test, "Hello from Pyrogram") # Not waiting for response # `send_*_await` methods automatically use the `bot_under_test` as peer: res = client.send_message_await("Hello from TgIntegration", max_wait=2, raise_=False) # If `raise_` is explicitly set to False, no exception is raised: assert res.empty # Note that when no response is expected and no validation thereof is necessary, ... client.send_photo_await("_assets/photo.jpg", max_wait=0, raise_=False) client.send_voice_await("_assets/voice.ogg", max_wait=0, raise_=False) # ... it makes more sense to use the "unawaitable" methods: client.send_photo(client.bot_under_test, "_assets/photo.jpg") client.send_voice(client.bot_under_test, "_assets/voice.ogg") # Custom awaitable Actions
def test_start(client: BotIntegrationClient): client.send_message(text="test_start", chat_id=config('BOT_NAME')) response = client.send_command_await("/start", num_expected=1) assert response.num_messages == 1 assert response.full_text.startswith("Hello")