Esempio n. 1
0
 def test_submit_answer_success(self):
     client = QbApi(BASE_URL, USER_ID, API_KEY)
     res = client.submit_answer(0, "abcasdfasdfasdf")
     self.assertEqual(res, False)
Esempio n. 2
0
 def test_submit_answer_duplicate(self):
     client = QbApi(BASE_URL, USER_ID, API_KEY)
     client.submit_answer(0, "answer1")
     self.assertRaises(ValueError, client.submit_answer(0, "answer2"))
Esempio n. 3
0
 def test_get_question_length(self):
     client = QbApi(BASE_URL, USER_ID, API_KEY)
     q_length = client.get_question_length(0)
     self.assertIsInstance(q_length, int)
     self.assertTrue(q_length > 0)
Esempio n. 4
0
 def test_get_word(self):
     client = QbApi(BASE_URL, USER_ID, API_KEY)
     word = client.get_word(0, 0)
     self.assertIsInstance(w, str)
     self.assertTrue(w)
Esempio n. 5
0
            for ii in range(qlen):
                curr_word_info = self._server.get_word(next_q, ii)
                curr_word = curr_word_info['text']
                print(curr_word, end=' ')
                current_question += ' ' + curr_word
                if answer == "" and any(x in current_question.lower()
                                        for x in self._patterns):
                    answer = [self._patterns[x] for x in self._patterns if
                              x in current_question.lower()][0]
                    print("\nANSWERING! %i %i (%s, %f sec)" %
                          (next_q, ii, answer, time.time() - start))
                    self._server.submit_answer(next_q, answer)
                    break
                sys.stdout.flush()

            # Submit some answer if the question is unanswered by the end
            if answer == "":
                print("\nANSWERING! %i %i (%s)" %
                      (next_q, qlen, "Chinua Achebe"))
                self._server.submit_answer(next_q, "Chinua Achebe")

            answer = ""
            print("took %f seconds\n" % (time.time() - start, ))

if __name__ == "__main__":

    base_url = qb_host + '/qb-api/v1'
    server = QbApi(base_url, user_id, api_key)
    sa = StringAnswerer(server)
    sa.answer_questions()
Esempio n. 6
0
 def test_get_num_questions(self):
     client = QbApi(BASE_URL, USER_ID, API_KEY)
     num_qs = client.get_num_questions()
     self.assertIsInstance(num_qs, int)
     self.assertTrue(num_qs > 0)
Esempio n. 7
0
 def test_submit_answer_duplicate(self):
     client = QbApi(BASE_URL, USER_ID, API_KEY)
     client.submit_answer(0, 'answer1')
     self.assertRaises(ValueError, client.submit_answer(0, 'answer2'))
Esempio n. 8
0
 def test_submit_answer_success(self):
     client = QbApi(BASE_URL, USER_ID, API_KEY)
     res = client.submit_answer(0, 'abcasdfasdfasdf')
     self.assertEqual(res, False)
Esempio n. 9
0
 def test_get_word(self):
     client = QbApi(BASE_URL, USER_ID, API_KEY)
     word = client.get_word(0, 0)
     self.assertIsInstance(w, str)
     self.assertTrue(w)
Esempio n. 10
0
 def test_get_question_length(self):
     client = QbApi(BASE_URL, USER_ID, API_KEY)
     q_length = client.get_question_length(0)
     self.assertIsInstance(q_length, int)
     self.assertTrue(q_length > 0)
Esempio n. 11
0
 def test_get_num_questions(self):
     client = QbApi(BASE_URL, USER_ID, API_KEY)
     num_qs = client.get_num_questions()
     self.assertIsInstance(num_qs, int)
     self.assertTrue(num_qs > 0)