Ejemplo n.º 1
0
        def test_with_mention(self):
            discord_user = DiscordUserFactory(discord_id="1234")

            assert_that(Command.discord_user_from_username("<@1234>"),
                        equal_to(discord_user))
            assert_that(Command.discord_user_from_username("<@1235>"),
                        equal_to(None))
Ejemplo n.º 2
0
        def test_with_username_and_discriminator(self):
            joe = DiscordUserFactory(discord_id="1234")
            jane = DiscordUserFactory(discord_id="1235")
            jack = DiscordUserFactory(discord_id="1236")

            guild = MockDiscordGuild(members=[
                MockDiscordAPIUserFactory(name="Joe",
                                          discriminator="0001",
                                          display_name="Joe Shmoe",
                                          id=joe.discord_id),
                MockDiscordAPIUserFactory(name="Joe",
                                          discriminator="0002",
                                          display_name="Jumping Jack",
                                          id=jack.discord_id),
                MockDiscordAPIUserFactory(name="Jane",
                                          display_name="Plain Jane",
                                          id=jane.discord_id),
            ])

            assert_that(Command.discord_user_from_username("Joe#0001", guild),
                        equal_to(joe))
            assert_that(Command.discord_user_from_username("Joe#0002", guild),
                        equal_to(jack))
            assert_that(
                calling(Command.discord_user_from_username).with_args(
                    "Joe#0003", guild), raises(CommandException))
            assert_that(
                Command.discord_user_from_username("Joe#0003",
                                                   guild,
                                                   raise_invalid=False),
                equal_to(None))
        def test_discord_user_from_username_with_mention(self):
            discord_user = DiscordUserFactory(discord_id="1234")

            expect(Command.discord_user_from_username("<@1234>")).to(
                equal(discord_user))
            expect(Command.discord_user_from_username("<@1235>")).to(
                equal(None))
        def test_discord_user_from_username_with_username_and_discriminator(
                self):
            joe = DiscordUserFactory(discord_id="1234")
            jane = DiscordUserFactory(discord_id="1235")
            jack = DiscordUserFactory(discord_id="1236")

            guild = MockDiscordGuild(members=[
                MockDiscordAPIUserFactory(name="Joe",
                                          discriminator="0001",
                                          display_name="Joe Shmoe",
                                          id=joe.discord_id),
                MockDiscordAPIUserFactory(name="Joe",
                                          discriminator="0002",
                                          display_name="Jumping Jack",
                                          id=jack.discord_id),
                MockDiscordAPIUserFactory(name="Jane",
                                          display_name="Plain Jane",
                                          id=jane.discord_id),
            ])

            expect(Command.discord_user_from_username("Joe#0001",
                                                      guild)).to(equal(joe))
            expect(Command.discord_user_from_username("Joe#0002",
                                                      guild)).to(equal(jack))
            expect(lambda: Command.discord_user_from_username(
                "Joe#0003", guild)).to(raise_error(CommandException))
            expect(
                Command.discord_user_from_username("Joe#0003",
                                                   guild,
                                                   raise_invalid=False)).to(
                                                       equal(None))
Ejemplo n.º 5
0
        def test_without_existing(self):
            twitch_user = TwitchUserFactory(username="******")

            assert_that(Command.twitch_user_from_username("dexfore"),
                        equal_to(None))
            assert_that(TwitchUser.objects.count(), equal_to(1))
            new_twitch_user = Command.twitch_user_from_username(
                "dexfore", existing_only=False)
            assert_that(new_twitch_user.username, equal_to("dexfore"))
            assert_that(TwitchUser.objects.count(), equal_to(2))
Ejemplo n.º 6
0
        def test_with_existing(self):
            twitch_user = TwitchUserFactory(username="******")

            assert_that(Command.twitch_user_from_username("dexfore"),
                        equal_to(twitch_user))
            assert_that(Command.twitch_user_from_username("@dexfore"),
                        equal_to(twitch_user))
            assert_that(
                Command.twitch_user_from_username("dexfore",
                                                  existing_only=False),
                equal_to(twitch_user))
            assert_that(TwitchUser.objects.count(), equal_to(1))
Ejemplo n.º 7
0
 def test_invalid(self):
     assert_that(
         calling(Command.twitch_user_from_username).with_args(
             "invalid username"), raises(CommandException))
     assert_that(
         Command.twitch_user_from_username("invalid username",
                                           raise_invalid=False),
         equal_to(None))
        def test_discord_user_from_username_with_username(self, get_guild):
            joe = DiscordUserFactory(discord_id="1234")
            jane = DiscordUserFactory(discord_id="1235")

            guild1 = MockDiscordGuild(members=[
                MockDiscordAPIUserFactory(
                    name="Joe", display_name="Joe Shmoe", id=joe.discord_id),
                MockDiscordAPIUserFactory(name="Jack",
                                          display_name="Jumping Jack"),
            ])
            guild2 = MockDiscordGuild(members=[
                MockDiscordAPIUserFactory(name="Jane",
                                          display_name="Plain Jane",
                                          id=jane.discord_id),
                MockDiscordAPIUserFactory(name="Jack",
                                          display_name="Jumping Jack"),
            ])
            get_guild.return_value = guild1

            expect(Command.discord_user_from_username("joe shmoe",
                                                      guild1)).to(equal(joe))
            expect(lambda: Command.discord_user_from_username(
                "plain jane", guild1)).to(raise_error(CommandException))
            expect(
                Command.discord_user_from_username("plain jane",
                                                   guild1,
                                                   raise_invalid=False)).to(
                                                       equal(None))
            expect(Command.discord_user_from_username("jumping jack",
                                                      guild1)).to(equal(None))

            expect(lambda: Command.discord_user_from_username(
                "joe shmoe", guild2)).to(raise_error(CommandException))
            expect(Command.discord_user_from_username("plain jane",
                                                      guild2)).to(equal(jane))
            expect(Command.discord_user_from_username("jumping jack",
                                                      guild2)).to(equal(None))

            expect(Command.discord_user_from_username("joe shmoe")).to(
                equal(joe))
            expect(
                lambda: Command.discord_user_from_username("plain jane")).to(
                    raise_error(CommandException))
            expect(Command.discord_user_from_username("jumping jack")).to(
                equal(None))
Ejemplo n.º 9
0
        def test_with_username(self, get_guild):
            joe = DiscordUserFactory(discord_id="1234")
            jane = DiscordUserFactory(discord_id="1235")

            guild1 = MockDiscordGuild(members=[
                MockDiscordAPIUserFactory(
                    name="Joe", display_name="Joe Shmoe", id=joe.discord_id),
                MockDiscordAPIUserFactory(name="Jack",
                                          display_name="Jumping Jack"),
            ])
            guild2 = MockDiscordGuild(members=[
                MockDiscordAPIUserFactory(name="Jane",
                                          display_name="Plain Jane",
                                          id=jane.discord_id),
                MockDiscordAPIUserFactory(name="Jack",
                                          display_name="Jumping Jack"),
            ])
            get_guild.return_value = guild1

            assert_that(
                Command.discord_user_from_username("joe shmoe", guild1),
                equal_to(joe))
            assert_that(
                calling(Command.discord_user_from_username).with_args(
                    "plain jane", guild1), raises(CommandException))
            assert_that(
                Command.discord_user_from_username("plain jane",
                                                   guild1,
                                                   raise_invalid=False),
                equal_to(None))
            assert_that(
                Command.discord_user_from_username("jumping jack", guild1),
                equal_to(None))

            assert_that(
                calling(Command.discord_user_from_username).with_args(
                    "joe shmoe", guild2), raises(CommandException))
            assert_that(
                Command.discord_user_from_username("plain jane", guild2),
                equal_to(jane))
            assert_that(
                Command.discord_user_from_username("jumping jack", guild2),
                equal_to(None))

            assert_that(Command.discord_user_from_username("joe shmoe"),
                        equal_to(joe))
            assert_that(
                calling(Command.discord_user_from_username).with_args(
                    "plain jane"), raises(CommandException))
            assert_that(Command.discord_user_from_username("jumping jack"),
                        equal_to(None))