def test_mock_role_uses_position_for_less_than_greater_than(self):
        role_one = helpers.MockRole(position=1)
        role_two = helpers.MockRole(position=2)
        role_three = helpers.MockRole(position=3)

        self.assertLess(role_one, role_two)
        self.assertLess(role_one, role_three)
        self.assertLess(role_two, role_three)
        self.assertGreater(role_three, role_two)
        self.assertGreater(role_three, role_one)
        self.assertGreater(role_two, role_one)
    def test_mock_member_alternative_arguments(self):
        core_developer = helpers.MockRole(name="Core Developer", position=2)
        member = helpers.MockMember(name="Mark", id=12345, roles=[core_developer])

        self.assertEqual(member.name, "Mark")
        self.assertEqual(member.id, 12345)
        self.assertListEqual(
            member.roles,
            [helpers.MockRole(name="@everyone", position=1, id=0), core_developer],
        )
        self.assertEqual(member.mention, "@Mark")
    def test_mock_guild_alternative_arguments(self):
        core_developer = helpers.MockRole(name="Core Developer", position=2)
        guild = helpers.MockGuild(
            roles=[core_developer],
            members=[helpers.MockMember(id=54321)],
        )

        self.assertListEqual(
            guild.roles,
            [helpers.MockRole(name="@everyone", position=1, id=0), core_developer],
        )
        self.assertListEqual(guild.members, [helpers.MockMember(id=54321)])
    def test_mock_role_accepts_dynamic_arguments(self):
        role = helpers.MockRole(
            guild="Dino Man",
            hoist=True,
        )

        self.assertEqual(role.guild, "Dino Man")
        self.assertTrue(role.hoist)
    def test_mock_role_default_initialization(self):
        role = helpers.MockRole()

        # The `spec` argument makes sure `isistance` checks with `discord.Role` pass
        self.assertIsInstance(role, discord.Role)

        self.assertEqual(role.name, "role")
        self.assertEqual(role.position, 1)
        self.assertEqual(role.mention, "&role")
    def test_mock_guild_default_initialization(self):
        guild = helpers.MockGuild()

        # The `spec` argument makes sure `isistance` checks with `discord.Guild` pass
        self.assertIsInstance(guild, discord.Guild)

        self.assertListEqual(
            guild.roles, [helpers.MockRole(name="@everyone", position=1, id=0)]
        )
        self.assertListEqual(guild.members, [])
    def test_mock_member_default_initialization(self):
        member = helpers.MockMember()

        # The `spec` argument makes sure `isistance` checks with `discord.Member` pass
        self.assertIsInstance(member, discord.Member)

        self.assertEqual(member.name, "member")
        self.assertListEqual(
            member.roles, [helpers.MockRole(name="@everyone", position=1, id=0)]
        )
        self.assertEqual(member.mention, "@member")
    def test_mock_role_alternative_arguments(self):
        role = helpers.MockRole(
            name="Admins",
            id=90210,
            position=10,
        )

        self.assertEqual(role.name, "Admins")
        self.assertEqual(role.id, 90210)
        self.assertEqual(role.position, 10)
        self.assertEqual(role.mention, "&Admins")
    def test_mocks_rejects_access_to_attributes_not_part_of_spec(self):
        mocks = (
            helpers.MockGuild(),
            helpers.MockRole(),
            helpers.MockMember(),
            helpers.MockBot(),
            helpers.MockContext(),
            helpers.MockTextChannel(),
            helpers.MockMessage(),
        )

        for mock in mocks:
            with self.subTest(mock=mock), self.assertRaises(AttributeError):
                mock.the_cake_is_a_lie
Beispiel #10
0
    def test_mocks_allows_access_to_attributes_part_of_spec(self):
        mocks = (
            (helpers.MockGuild(), "name"),
            (helpers.MockRole(), "hoist"),
            (helpers.MockMember(), "display_name"),
            (helpers.MockBot(), "user"),
            (helpers.MockContext(), "invoked_with"),
            (helpers.MockTextChannel(), "last_message"),
            (helpers.MockMessage(), "mention_everyone"),
        )

        for mock, valid_attribute in mocks:
            with self.subTest(mock=mock):
                try:
                    getattr(mock, valid_attribute)
                except AttributeError:
                    msg = f"accessing valid attribute `{valid_attribute}` raised an AttributeError"
                    self.fail(msg)
Beispiel #11
0
 def test_mock_class_with_hashable_mixin_uses_id_for_hashing(self):
     for mock in self.hashable_mocks:
         with self.subTest(mock_class=mock):
             instance = helpers.MockRole(id=100)
             self.assertEqual(hash(instance), instance.id)