示例#1
0
 def test_control_stop(self):
     """
     Stop the quizz
     """
     self.client.quizz.add_question('q1?', ['a1'])
     self.client.control_quizz(Message(), self._parse_cmd('quizz start'))
     self.assertTrue(self.client.running)
     self.client.control_quizz(Message(), self._parse_cmd('quizz stop'))
     self.assertFalse(self.client.running)
示例#2
0
 def test_question_add_duplicate(self):
     """
     Add a question. Twice.
     """
     self.client.question(
         Message(), self._parse_cmd('question -a {}'.format(self.que)))
     self.assertReplyEqual(
         "Question added: q?\nAnswers: ['a1', 'a2', 'a3']")
     self.client.question(
         Message(), self._parse_cmd('question -a {}'.format(self.que)))
     self.assertReplyEqual('error: Duplicate question')
示例#3
0
 def test_control_start_bis(self):
     """
     Start the quizz. Twice.
     """
     self.client.quizz.add_question('q1?', ['a1'])
     self.client.control_quizz(Message(), self._parse_cmd('quizz start'))
     self.assertTrue(self.client.running)
     self.assertSayGroupEqual('q1?')
     self.client.control_quizz(Message(), self._parse_cmd('quizz start'))
     self.assertTrue(self.client.running)
     self.assertReplyEqual('The quizz is already running ^_^')
示例#4
0
 def set_reactions(message: Message, to_id: str, reactions: Iterable[str]):
     """
     Add reactions to a Message object.
     """
     reactions_stanza = stanza.Reactions()
     reactions_stanza['to'] = to_id
     for reaction in reactions:
         reaction_stanza = stanza.Reaction()
         reaction_stanza['value'] = reaction
         reactions_stanza.append(reaction_stanza)
     message.append(reactions_stanza)
示例#5
0
 def test_set_taunt_aggro_no_number(self):
     """
     Evolutionary void: set the aggro level of nothing
     """
     self.client.tauntionary.add_taunt('blaaargh?', 'Grishka', 3)
     self.client.taunt(Message(), self._parse_cmd('taunt -g 2'))
     self.assertReplyEqual('no taunt specified')
示例#6
0
 def test_quit(self):
     """
     Disconnect with a custom message
     """
     self.client.quit(Message(sfrom='*****@*****.**'),
                      self._parse_cmd('quit'))
     self.assertSayGroupEqual('I quit!')
示例#7
0
 def test_set_taunt_aggro(self):
     """
     Set the aggro level of a taunt
     """
     self.client.tauntionary.add_taunt('blaaargh?', 'Grishka', 3)
     self.client.taunt(Message(), self._parse_cmd('taunt -g 2 -n 1'))
     self.assertEqual(self.client.tauntionary.taunts[0].aggro, 2)
示例#8
0
 def test_question_list(self):
     """
     List questions
     """
     self.client.quizz.add_question('q1?', ['a1'])
     self.client.quizz.add_question('q2?', ['a2'])
     self.client.question(Message(), self._parse_cmd('question -l'))
     self.assertReplyEqual('\n1 - q1?\n2 - q2?')
示例#9
0
    def test_question_add_error(self):
        """
        Add a question with no answers
        """
        args = self._parse_cmd('question -a q?#')

        self.client.question(Message(), args)
        self.assertReplyEqual('error: No answers specified')
示例#10
0
 def test_question_add(self):
     """
     Add a question
     """
     self.client.question(
         Message(), self._parse_cmd('question -a {}'.format(self.que)))
     self.assertReplyEqual(
         "Question added: q?\nAnswers: ['a1', 'a2', 'a3']")
示例#11
0
 def test_check_wrong_answer(self):
     """
     Someone has given the wrong answer
     """
     self.client.quizz.add_question('q1?', ['a1'])
     self.client.control_quizz(Message(), self._parse_cmd('quizz start'))
     self.assertEqual(self._check_answer('1a', 'Hans'),
                      'Sorry Hans, 1a is not the answer to my question.')
示例#12
0
 def test_control_start(self):
     """
     Start the quizz
     """
     self.client.quizz.add_question('q1?', ['a1'])
     self.client.control_quizz(Message(), self._parse_cmd('quizz start'))
     self.assertTrue(self.client.running)
     self.assertSayGroupEqual('q1?')
示例#13
0
    def test_control_next(self):
        """
        Skip the question
        """
        # add and ask a first question
        self.client.quizz.add_question('q1?', ['a1'])
        self.client.control_quizz(Message(), self._parse_cmd('quizz start'))
        self.assertTrue(self.client.running)
        self.assertSayGroupEqual('q1?')

        # remove it
        self.client.quizz.delete_question(1)

        # add and ask a second question
        self.client.quizz.add_question('q2?', ['a2'])
        self.client.control_quizz(Message(), self._parse_cmd('quizz next'))
        self.assertSayGroupEqual('q2?')
示例#14
0
 def test_add_invalid_taunt(self):
     """
     Add an invalid taunt
     """
     self.client.taunt(Message(),
                       self._parse_cmd('taunt -a blorgh!'))
     self.assertEqual(self.client.reply,
                      'error: Taunt: empty user nickname')
示例#15
0
 def test_question_del(self):
     """
     Delete a question
     """
     self.client.quizz.add_question('q1?', ['a1'])
     self.client.quizz.add_question('q2?', ['a2'])
     self.client.question(Message(), self._parse_cmd('question -d 2'))
     self.assertEqual(str(self.client.quizz), '1 - q1?')
     self.assertReplyEqual('The question #2 has been deleted')
示例#16
0
    def Message(self, *args, **kwargs):
        """
        Create a Message stanza.

        Uses same arguments as StanzaBase.__init__

        Arguments:
            xml -- An XML object to use for the Message's values.
        """
        return Message(self.xmpp, *args, **kwargs)
示例#17
0
 def test_check_good_answer(self):
     """
     Someone has given the right answer
     """
     self.client.quizz.add_question('q1?', ['a1'])
     self.client.control_quizz(Message(), self._parse_cmd('quizz start'))
     self.assertEqual(
         self._check_answer('a1', 'Hans'),
         'Good answer Hans!\nYou now have 1 points\n'
         'Next question: q1?')
示例#18
0
    def test_add_too_long_taunt(self):
        """
        Attempt to add a taunt that exceeds the max authorized length
        """
        tnt = ''.join(['a'] * TAUNT_LEN_MAX)

        self.client.taunt(Message(),
                          self._parse_cmd('taunt -a long{}'.format(tnt)))
        self.assertEqual(self.client.reply,
                         'too long a taunt, sir!')
示例#19
0
 def test_list_taunt_by_aggro(self):
     """
     Returns the list of taunts, sorted by aggro level
     """
     self.client.tauntionary.add_taunt('blaaargh?', 'Grishka', 3)
     self.client.tauntionary.add_taunt('blorgh!', 'Igor', 5)
     self.client.taunt(Message(), self._parse_cmd('taunt --lg'))
     self.assertEqual(
         self.client.reply,
         '\n{}'.format(self.client.tauntionary.list_by_aggro())
     )
示例#20
0
    def test_say_infinite(self):
        """
        Attempt to use the bot's name
        """
        msg = Message()
        cmd = 'say {}'.format(self.client.nick)

        args = self._parse_cmd(cmd)
        args.func(msg, args)
        self.assertEqual(self.client.reply,
                         'Do not try to unleash the infinite fury, ')

        args = self._parse_muc_cmd(cmd)
        args.func(msg, args)
        self.assertEqual(self.client.reply,
                         'Do not try to unleash the infinite fury, ')
示例#21
0
 def test_control_score(self):
     """
     Display current scores
     """
     self.client.control_quizz(Message(), self._parse_cmd('quizz score'))
     self.assertReplyEqual('\nScores:\n')
示例#22
0
 def test_quit_user(self):
     """
     A non-admin user attempts to stop the bot
     """
     with self.assertRaises(PrivilegeError):
         self.client.quit(Message(), None)
示例#23
0
 def test_control_reset(self):
     """
     Reset the scores
     """
     self.client.control_quizz(Message(), self._parse_cmd('quizz reset'))
     self.assertSayGroupEqual('All scores have been reset!')
示例#24
0
 def test_list_empty_taunt(self):
     """
     Ask for the (empty) list of taunts
     """
     self.client.taunt(Message(), self._parse_cmd('taunt -l'))
     self.assertEqual(self.client.reply, '\n')
示例#25
0
 def Message(self, *args, **kwargs):
     """Create a Message stanza associated with this stream."""
     msg = Message(self, *args, **kwargs)
     msg['lang'] = self.default_lang
     return msg