Ejemplo n.º 1
0
 def test_invalid_character_name(self):
     user_input = '!add Moo+s tos 5'
     message = DiscordMessage(user_input)
     ctx = DiscordCtx(message)
     error = insert_keystone(ctx, self.db_manager, *message.get_args())
     self.assertEqual(
         error, f'Character names can only contain letters, '
         f'numbers, underscores, and dashes.')
Ejemplo n.º 2
0
 def test_invalid_num_args(self):
     user_input = '!add Moo Too'
     message = DiscordMessage(user_input)
     ctx = DiscordCtx(message)
     error = insert_keystone(ctx, self.db_manager, *message.get_args())
     self.assertEqual(
         error, 'I\'m sorry, I didn\'t understand that. Try '
         '`!help add` for help with formatting.')
Ejemplo n.º 3
0
 def test_db_error(self):
     self.db_manager.add_keystone = MagicMock(return_value=False)
     user_input = '!add Moo Waycrest 10'
     message = DiscordMessage(user_input)
     ctx = DiscordCtx(message)
     error = insert_keystone(ctx, self.db_manager, *message.get_args())
     self.assertEqual(
         error, 'There was a problem adding Waycrest Manor '
         '+10 for Moo.')
Ejemplo n.º 4
0
 def test_backticks_invalid_dungeon(self):
     user_input = '!add Moo `Fake Dungeon`` 10'
     message = DiscordMessage(user_input)
     ctx = DiscordCtx(message)
     error = insert_keystone(ctx, self.db_manager, *message.get_args())
     self.assertEqual(
         error, f'I\'m sorry, I didn\'t understand the dungeon '
         f'`Fake Dungeon`. Try `!dungeons` to see '
         f'dungeon names.')
Ejemplo n.º 5
0
 def test_no_character_name(self):
     user_input = '!add Temple of Sethraliss 10'
     message = DiscordMessage(user_input)
     ctx = DiscordCtx(message)
     error = insert_keystone(ctx, self.db_manager, *message.get_args())
     self.assertEqual(
         error, f'I\'m sorry, I didn\'t understand the dungeon '
         f'`of Sethraliss`. Try `!dungeons` to see '
         f'dungeon names.')
Ejemplo n.º 6
0
    def test_db_error(self):
        author = DiscordMember(1, 'Hovsep')
        channel = DiscordTextChannel([author])
        message = DiscordMessage('!keys', author, channel=channel)
        ctx = DiscordCtx(message)

        self.db_manager.get_keystones = MagicMock(return_value=None)

        result = get_keystones(ctx, self.db_manager)
        self.db_manager.get_keystones.assert_called_with({1}, 1)
        self.assertEqual(result, 'There was a problem getting the keystones.')
Ejemplo n.º 7
0
    def test_no_mentions(self):
        author = DiscordMember(1, 'Hovsep')
        channel = DiscordTextChannel([author])
        message = DiscordMessage('!keys', author, channel=channel)
        ctx = DiscordCtx(message)

        self.db_manager.get_keystones = MagicMock(return_value={1: [('toon', 245, 10)]})

        result = get_keystones(ctx, self.db_manager)
        self.db_manager.get_keystones.assert_called_with({1}, 1)
        self.assertEqual(result, 'Hovsep\'s keystones:\n   toon: Freehold 10')
Ejemplo n.º 8
0
    def test_single_mention(self):
        author = DiscordMember(1, 'Hovsep')
        mentioned_user = DiscordMember(2, 'John')
        channel = DiscordTextChannel([author, mentioned_user])
        message = DiscordMessage('!keys @John', author, channel=channel, mentions=[mentioned_user])
        ctx = DiscordCtx(message, guild=channel.guild)

        self.db_manager.get_keystones = MagicMock(return_value={2: [('toon', 245, 10)]})

        result = get_keystones(ctx, self.db_manager)
        self.db_manager.get_keystones.assert_called_with({2}, 1)
        self.assertEqual(result, 'John\'s keystones:\n   toon: Freehold 10')
Ejemplo n.º 9
0
    def test_mention_here(self):
        author = DiscordMember(1, 'Hovsep')
        users = [author, DiscordMember(2, 'John'), DiscordMember(3, 'Mike', status='offline')]
        channel = DiscordTextChannel(users)
        message = DiscordMessage('!keys @here', author, channel=channel)
        ctx = DiscordCtx(message, guild=channel.guild)

        self.db_manager.get_keystones = MagicMock(return_value={
            1: [('pally', 246, 15)],
            2: [('toon', 245, 10)],
        })

        result = get_keystones(ctx, self.db_manager)
        self.db_manager.get_keystones.assert_called_with({1, 2}, 1)
        self.assertEqual(result, 'Hovsep\'s keystones:\n   pally: Tol Dagor 15\n'
                                 'John\'s keystones:\n   toon: Freehold 10')
Ejemplo n.º 10
0
    def test_multiple_mentions(self):
        author = DiscordMember(1, 'Hovsep')
        mentioned_users = [DiscordMember(2, 'John'), DiscordMember(3, 'Mike')]
        channel = DiscordTextChannel([author] + mentioned_users)
        message = DiscordMessage('!keys @John', author, channel=channel, mentions=mentioned_users)
        ctx = DiscordCtx(message, guild=channel.guild)

        self.db_manager.get_keystones = MagicMock(return_value={
            2: [('toon', 245, 10)],
            3: [('warrior', 251, 12)],
        })

        result = get_keystones(ctx, self.db_manager)
        self.db_manager.get_keystones.assert_called_with({2, 3}, 1)
        self.assertEqual(result, 'John\'s keystones:\n   toon: Freehold 10\n'
                                 'Mike\'s keystones:\n   warrior: The Underrot 12')
Ejemplo n.º 11
0
    def test_mention_role(self):
        mention_role = DiscordRole('role')
        general_role = DiscordRole('@everyone')
        author = DiscordMember(1, 'Hovsep', roles=[general_role])
        users = [
            author,
            DiscordMember(2, 'John', roles=[mention_role, general_role]),
            DiscordMember(3, 'Mike', roles=[general_role])
        ]
        channel = DiscordTextChannel(users)
        message = DiscordMessage('!keys @role', author, channel=channel, role_mentions=[mention_role])
        ctx = DiscordCtx(message, guild=channel.guild)

        self.db_manager.get_keystones = MagicMock(return_value={
            2: [('toon', 245, 10)],
        })

        result = get_keystones(ctx, self.db_manager)
        self.db_manager.get_keystones.assert_called_with({2}, 1)
        self.assertEqual(result, 'John\'s keystones:\n   toon: Freehold 10')
Ejemplo n.º 12
0
 def test_backticks_invalid_level(self):
     user_input = '!add Moo Temple of Sethraliss `Bad`Level`'
     message = DiscordMessage(user_input)
     ctx = DiscordCtx(message)
     error = insert_keystone(ctx, self.db_manager, *message.get_args())
     self.assertEqual(error, f'`BadLevel` isn\'t a valid dungeon level.')
Ejemplo n.º 13
0
 def test_insert_less_than_2_level(self):
     user_input = '!add Moo Waycrest NaN'
     message = DiscordMessage(user_input)
     ctx = DiscordCtx(message)
     error = insert_keystone(ctx, self.db_manager, *message.get_args())
     self.assertEqual(error, f'`NaN` isn\'t a valid dungeon level.')
Ejemplo n.º 14
0
 def test_valid_insertion_plus_level(self):
     user_input = '!add Moo Waycrest Manor +10'
     message = DiscordMessage(user_input)
     ctx = DiscordCtx(message)
     error = insert_keystone(ctx, self.db_manager, *message.get_args())
     self.assertEqual(error, 'Added Waycrest Manor +10 for Moo')
Ejemplo n.º 15
0
 def test_valid_character_name_all(self):
     user_input = '!add M_5-m wm 5'
     message = DiscordMessage(user_input)
     ctx = DiscordCtx(message)
     error = insert_keystone(ctx, self.db_manager, *message.get_args())
     self.assertEqual(error, f'Added Waycrest Manor +5 for M_5-m')