Exemplo n.º 1
0
    async def test_diff_for_new_updated_and_deleted_roles(self):
        """When roles are added, updated, and removed, all of them are returned properly."""
        new = fake_role(id=41, name="new")
        updated = fake_role(id=71, name="updated")
        deleted = fake_role(id=61, name="deleted")

        self.bot.api_client.get.return_value = [
            fake_role(),
            fake_role(id=71, name="updated name"),
            deleted,
        ]
        guild = self.get_guild(fake_role(), new, updated)

        actual_diff = await self.syncer._get_diff(guild)
        expected_diff = ({_Role(**new)}, {_Role(**updated)},
                         {_Role(**deleted)})

        self.assertEqual(actual_diff, expected_diff)
Exemplo n.º 2
0
    async def test_diff_for_deleted_roles(self):
        """Only deleted roles should be added to the 'deleted' set of the diff."""
        deleted_role = fake_role(id=61, name="deleted")

        self.bot.api_client.get.return_value = [fake_role(), deleted_role]
        guild = self.get_guild(fake_role())

        actual_diff = await self.syncer._get_diff(guild)
        expected_diff = (set(), set(), {_Role(**deleted_role)})

        self.assertEqual(actual_diff, expected_diff)
Exemplo n.º 3
0
    async def test_diff_for_new_roles(self):
        """Only new roles should be added to the 'created' set of the diff."""
        new_role = fake_role(id=41, name="new")

        self.bot.api_client.get.return_value = [fake_role()]
        guild = self.get_guild(fake_role(), new_role)

        actual_diff = await self.syncer._get_diff(guild)
        expected_diff = ({_Role(**new_role)}, set(), set())

        self.assertEqual(actual_diff, expected_diff)
Exemplo n.º 4
0
    async def test_diff_for_updated_roles(self):
        """Only updated roles should be added to the 'updated' set of the diff."""
        updated_role = fake_role(id=41, name="new")

        self.bot.api_client.get.return_value = [
            fake_role(id=41, name="old"),
            fake_role()
        ]
        guild = self.get_guild(updated_role, fake_role())

        actual_diff = await self.syncer._get_diff(guild)
        expected_diff = (set(), {_Role(**updated_role)}, set())

        self.assertEqual(actual_diff, expected_diff)
Exemplo n.º 5
0
    async def test_sync_deleted_roles(self):
        """Only DELETE requests should be made with the correct payload."""
        roles = [fake_role(id=111), fake_role(id=222)]

        role_tuples = {_Role(**role) for role in roles}
        diff = _Diff(set(), set(), role_tuples)
        await self.syncer._sync(diff)

        calls = [mock.call(f"bot/roles/{role['id']}") for role in roles]
        self.bot.api_client.delete.assert_has_calls(calls, any_order=True)
        self.assertEqual(self.bot.api_client.delete.call_count, len(roles))

        self.bot.api_client.post.assert_not_called()
        self.bot.api_client.put.assert_not_called()