async def test_create_timeouts_ko(self, ctx, registered_author): ctx.author = registered_author answers = [fake.word(), 'no', 'no'] ctx.bot = mocks.ClientMock(wait_for_anwsers=answers, raise_timeout=[True]) timeout_msg = 'Sorry, you took so long to reply.' command = self.command(ctx, 'create') await command.run() # `web`, `name`, `timeout` assert mocks.MemberMock.send.call_count == 3 mocks.MemberMock.send.assert_called_with(timeout_msg) # Reset calls mocks.MemberMock.send.call_count = 0 ctx.bot = mocks.ClientMock(wait_for_anwsers=answers, raise_timeout=[False, True]) command = self.command(ctx, 'create') await command.run() # `web`, `name`, `description`, `timeout` assert mocks.MemberMock.send.call_count == 4 mocks.MemberMock.send.assert_called_with(timeout_msg) # Reset calls mocks.MemberMock.send.call_count = 0 ctx.bot = mocks.ClientMock(wait_for_anwsers=answers, raise_timeout=[False, False, True]) command = self.command(ctx, 'create') await command.run() # `web`, `name`, `description`, `image`, `timeout` assert mocks.MemberMock.send.call_count == 5 mocks.MemberMock.send.assert_called_with(timeout_msg)
async def test_create_public_ok(self, ctx, registered_author, image, mocker): ctx.author = registered_author name = fake.word() description = fake.paragraph() ctx.bot = mocks.ClientMock(wait_for_anwsers=[ mocks.MessageMock(content=name), mocks.MessageMock(content=description), mocks.MessageMock(files=[image]) ]) command = self.command(ctx, 'create', 'public') await command.run() world_create = await sync_to_async(Place.objects.first)() create_url = await get_url_from('roleplay:world_create') edit_url = await get_url_from('roleplay:world_detail', kwargs={'pk': world_create.pk}) calls = [ mocker.call( f'Remember you can perform this action via web: {create_url}'), mocker.call('First we need a name'), mocker.call( 'Now tell us about your world, a description (You can avoid this by writting \'no\')' ), mocker.call( 'Maybe an image? (You can avoid this by writting \'no\')'), mocker.call('Congrats! Your world have been created!'), mocker.call(f'Check it out here: {edit_url}'), ] assert mocks.MemberMock.send.call_count == 6 assert all(call in mocks.MemberMock.send.mock_calls for call in calls) assert world_create.name == name assert world_create.description == description assert world_create.user is None
async def test_remove_messages_ko(self, ctx, registered_author, user, mocker): await async_create(Place, user=user, owner=user, site_type=SiteTypes.WORLD) ctx.author = registered_author # `Select world to remove`, `confirm?` ctx.bot = mocks.ClientMock(wait_for_anwsers=['0', 'no']) command = self.command(ctx, 'remove') deleted_world = await command.get_own_worlds_as_values(user) world = await command.get_world(deleted_world[0]['pk']) url = await get_url_from('roleplay:world_delete', kwargs={'pk': world.pk}) await command.run() calls = [ # We avoid embed because object hashing mocker.call(f'Are you sure you want to delete {world}? [yes/no]'), mocker.call(f'You can perform this action via web: {url}'), mocker.call('Okay!') ] mocks.MemberMock.send.assert_called() # `Embed`, `confirmation`, `web message`, `world deleted` assert mocks.MemberMock.send.call_count == 4 assert all(call in mocks.MemberMock.send.mock_calls for call in calls)
async def test_create_only_name_ok(self, ctx, registered_author): ctx.author = registered_author name = fake.word() ctx.bot = mocks.ClientMock( wait_for_anwsers=[mocks.MessageMock(content=name), 'no', 'no']) command = self.command(ctx, 'create', 'public') await command.run() created_world = await sync_to_async(Place.objects.first)() assert created_world.name == name assert created_world.description is None assert bool(created_world.image) is False
async def test_remove_timeout_on_selection_ko(self, ctx, registered_author, user, mocker): baker.make(Place, user=user, owner=user) ctx.author = registered_author ctx.bot = mocks.ClientMock(raise_timeout=[True]) command = self.command(ctx, 'remove') await command.run() timeout_msg = 'Sorry, you took so long to reply.' mocks.MemberMock.send.assert_called() # `Embed`, `timeout` assert mocks.MemberMock.send.call_count == 2 mocks.MemberMock.send.assert_called_with(timeout_msg)
async def test_remove_ko(self, ctx, registered_author, user, mocker): await async_create(Place, user=user, owner=user, site_type=SiteTypes.WORLD) ctx.author = registered_author # `Select world to remove`, `confirm?` ctx.bot = mocks.ClientMock(wait_for_anwsers=['0', 'no']) command = self.command(ctx, 'remove') worlds = await command.get_own_worlds_as_values(user) deleted_world = worlds[0] await command.run() await async_get(Place, pk=deleted_world['pk'])
async def test_create_image_not_sent_ko(self, ctx, registered_author, image): ctx.author = registered_author name = fake.word() description = fake.paragraph() ctx.bot = mocks.ClientMock(wait_for_anwsers=[ mocks.MessageMock(content=name), mocks.MessageMock(content=description), mocks.MessageMock(content=fake.word()) ]) command = self.command(ctx, 'create', 'public') await command.run() image_too_big_msg = 'You didn\'t send an image.' mocks.MemberMock.send.assert_called_with(image_too_big_msg)
async def test_create_image_too_big_ko(self, ctx, registered_author, image): image.size = settings.FILE_UPLOAD_MAX_MEMORY_SIZE + fake.random_int() ctx.author = registered_author name = fake.word() description = fake.paragraph() ctx.bot = mocks.ClientMock(wait_for_anwsers=[ mocks.MessageMock(content=name), mocks.MessageMock(content=description), mocks.MessageMock(files=[image]) ]) command = self.command(ctx, 'create', 'public') await command.run() image_too_big_msg = 'Image too big.' mocks.MemberMock.send.assert_called_with(image_too_big_msg)
async def test_remove_timeout_on_confimation_ko(self, ctx, registered_author, user, mocker): baker.make(Place, user=user, owner=user) ctx.author = registered_author ctx.bot = mocks.ClientMock(wait_for_anwsers=['0'], raise_timeout=[False, True]) command = self.command(ctx, 'remove') await command.run() timeout_msg = 'Sorry, you took so long to reply.' mocks.MemberMock.send.assert_called() # `Embed`, `confirmation`, `web message`, `timeout` assert mocks.MemberMock.send.call_count == 4 mocks.MemberMock.send.assert_called_with(timeout_msg)