コード例 #1
0
    async def test_track_cycle(self):
        member = mocks.MockMember()
        scs = mocks.MockGuild(roles=mocks.tracks)
        with self.subTest('No track'):
            res = await track_cycle(member, scs)
            self.assertEqual(0, res)
            self.assertIn(mocks.track1, member.roles)

        with self.subTest('Track 1->2'):
            member.roles = [mocks.track1]
            res = await track_cycle(member, scs)
            self.assertEqual(1, res)
            self.assertIn(mocks.track2, member.roles)
            self.assertNotIn(mocks.track1, member.roles)

        with self.subTest('Track 2->3'):
            member.roles = [mocks.track2]
            res = await track_cycle(member, scs)
            self.assertEqual(2, res)
            self.assertIn(mocks.track3, member.roles)
            self.assertNotIn(mocks.track2, member.roles)

        with self.subTest('Track 3'):
            member.roles = [mocks.track3]
            res = await track_cycle(member, scs)
            self.assertEqual(3, res)

        with self.subTest('full'):
            member.roles = [mocks.true_locked]
            res = await track_cycle(member, scs)
            self.assertEqual(3, res)
コード例 #2
0
    def test_mock_guild_accepts_dynamic_arguments(self):
        """Test if MockGuild accepts and sets abitrary keyword arguments."""
        guild = mocks.MockGuild(
            emojis=(":hyperjoseph:", ":pensive_ela:"),
            premium_subscription_count=15,
        )

        self.assertTupleEqual(guild.emojis, (":hyperjoseph:", ":pensive_ela:"))
        self.assertEqual(guild.premium_subscription_count, 15)
コード例 #3
0
    def test_mock_guild_default_initialization(self):
        """Test if the default initialization of Mockguild results in the correct object."""
        guild = mocks.MockGuild()

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

        self.assertListEqual(
            guild.roles, [mocks.MockRole(name="@everyone", position=1, id=0)])
        self.assertListEqual(guild.members, [])
コード例 #4
0
    def test_mock_guild_alternative_arguments(self):
        """Test if MockGuild initializes with the arguments provided."""
        core_developer = mocks.MockRole(name="Core Developer", position=2)
        guild = mocks.MockGuild(
            roles=[core_developer],
            members=[mocks.MockMember(id=54321)],
        )

        self.assertListEqual(guild.roles, [
            mocks.MockRole(name="@everyone", position=1, id=0), core_developer
        ])
        self.assertListEqual(guild.members, [mocks.MockMember(id=54321)])
コード例 #5
0
    def test_mocks_rejects_access_to_attributes_not_part_of_spec(self):
        """Accessing attributes that are invalid for the objects they mock should fail."""
        mock_tuple = (
            mocks.MockGuild(),
            mocks.MockRole(),
            mocks.MockMember(),
            mocks.MockBot(),
            mocks.MockContext(),
            mocks.MockTextChannel(),
            mocks.MockMessage(),
        )

        for mock in mock_tuple:
            with self.subTest(mock=mock):
                with self.assertRaises(AttributeError):
                    mock.the_cake_is_a_lie
コード例 #6
0
    def test_mocks_allows_access_to_attributes_part_of_spec(self):
        """Accessing attributes that are valid for the objects they mock should succeed."""
        mock_tuple = (
            (mocks.MockGuild(), 'name'),
            (mocks.MockRole(), 'hoist'),
            (mocks.MockMember(), 'display_name'),
            (mocks.MockBot(), 'user'),
            (mocks.MockContext(), 'invoked_with'),
            (mocks.MockTextChannel(), 'last_message'),
            (mocks.MockMessage(), 'mention_everyone'),
        )

        for mock, valid_attribute in mock_tuple:
            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)