def testSendMessagesDisabled(self): # Testing that message for disabled user is not sent # But rescheduled to next day Twitter = TwitterMockup() today = datetime.date.today() self.createUser("da_zbur","disabled",10) d1 = self.createDictEntry("da_zbur",2,"lucrative",\ u"profitable, moneymaking, remunerative","[LOO-kruh-tiv]") current_time = int(time.time()) l1 = self.createLearnListItem("da_zbur",d1,today, current_time) messages_generator = sendMessagesGenerator(Twitter, logging) m_list = [] while True: try: message = messages_generator.next() except StopIteration: break m_list.append(message) # Testing that LearnListItem was rescheduled properly ll = LearnList.all().fetch(1)[0] self.assertEqual(1, ll.total_served) self.assertEqual(today + datetime.timedelta(days=1), ll.next_serve_date) self.assertEqual([None], m_list) self.assertEqual(sys.maxint, ll.next_serve_time)
def testQuestionAcknowledge(self): Twitter = TwitterMockup() today = datetime.date.today() current_time = int(time.time()) u = self.createUser("da_zbur","enabled",10) u.use_questions = "yes" u.put() d1 = self.createDictEntry("da_zbur",2,"lucrative",\ u"profitable, moneymaking, remunerative","[LOO-kruh-tiv]") d2 = self.createDictEntry("da_zbur",2,"ferociously(en)",\ u"жестоко, яростно, свирепо, дико, неистово. Ужасно, невыносимо.") l1 = self.createLearnListItem("da_zbur",d1,today,current_time) l2 = self.createLearnListItem("da_zbur",d2,today,current_time) # forcing question to be asked l1.total_served = 4 l2.total_served = 6 l2.put() l1.put() buildDailyList(today, logging) # Keep in mind building daily list means serve times will be # randomly distributed throighout the day! l1.next_serve_time = current_time l2.next_serve_time = current_time l2.put() l1.put() messages_generator = sendMessagesGenerator(Twitter, logging) m_list = [] while True: try: message = messages_generator.next() except StopIteration: break m_list.append(message) # Now imagine those question didn't get answers before next daily # list is build acknowledgeQuestions(today) unack_count = Question.all().filter("answer_received =", None).count() self.assertEqual(0, unack_count)
def testSendQuestion(self): Twitter = TwitterMockup() today = datetime.date.today() current_time = int(time.time()) u = self.createUser("da_zbur","enabled",10) u.use_questions = "yes" u.put() d1 = self.createDictEntry("da_zbur",2,"lucrative",\ u"profitable, moneymaking, remunerative","[LOO-kruh-tiv]") d2 = self.createDictEntry("da_zbur",2,"ferociously(en)",\ u"жестоко, яростно, свирепо, дико, неистово. Ужасно, невыносимо.") l1 = self.createLearnListItem("da_zbur",d1,today,current_time) l2 = self.createLearnListItem("da_zbur",d2,today,current_time) # forcing question to be asked l1.total_served = 4 l1.put() buildDailyList(today, logging) # Keep in mind building daily list means serve times will be # randomly distributed throighout the day! l1.next_serve_time = current_time l2.next_serve_time = current_time l2.put() l1.put() messages_generator = sendMessagesGenerator(Twitter, logging) m_list = [] while True: try: message = messages_generator.next() except StopIteration: break m_list.append(message) # Testing that proper Question entity was created q = Question.all().fetch(1)[0] self.assertEqual(2653, q.question_message_id) self.assertEqual(today, q.question_sent) self.assertEqual(4, l1.total_served) self.assertEqual(sys.maxint, q.lli_ref.next_serve_time) self.assertEqual("lucrative[LOO-kruh-tiv]:? [4]", m_list[0])
def testCheckForAnswer(self): # I should collapse this code into something reusable Twitter = TwitterMockup() today = datetime.date.today() current_time = int(time.time()) u = self.createUser("da_zbur","enabled",10) u.use_questions = "yes" u.put() d1 = self.createDictEntry("da_zbur",2,"lucrative",\ u"profitable, moneymaking, remunerative","[LOO-kruh-tiv]") l1 = self.createLearnListItem("da_zbur",d1,today,current_time) # forcing question to be asked l1.total_served = 4 l1.put() buildDailyList(today, logging) # Keep in mind building daily list means serve times will be # randomly distributed throighout the day! l1.next_serve_time = current_time l1.put() messages_generator = sendMessagesGenerator(Twitter, logging) m_list = [] while True: try: message = messages_generator.next() except StopIteration: break m_list.append(message) q = Question.all().fetch(1)[0] # Question for word d1 was genereated and sent # Now user prepares an answer answer = "lucrative: moneymaking, profitable" m = Twitter.api.PostUpdate(answer, in_reply_to_s_id=q.question_message_id) parsed_dict = parseMessage(m.text) q2 = checkForAnswer(parsed_dict, u.twitter) self.assertEqual(q.key(), q2.key())
def testAnswersIntegration(self): # I should collapse this code into something reusable # This is a big integration test for question/answers # Idea is that there are two answers: good and bad # Need to check if messages are being properly rescheduled and send Twitter = TwitterMockup() today = datetime.date.today() current_time = int(time.time()) u = self.createUser("da_zbur","enabled",10) u.use_questions = "yes" u.put() d1 = self.createDictEntry("da_zbur",2,"lucrative",\ u"profitable, moneymaking, remunerative","[LOO-kruh-tiv]") d2 = self.createDictEntry("da_zbur",2,"ferociously(en)",\ u"жестоко, яростно, свирепо, дико, неистово. Ужасно, невыносимо.") d3 = self.createDictEntry("da_zbur",2,"confounder",\ u"искажающий результаты фактор") l1 = self.createLearnListItem("da_zbur",d1,today,current_time) l2 = self.createLearnListItem("da_zbur",d2,today,current_time) l3 = self.createLearnListItem("da_zbur",d3,today,current_time) # forcing question to be asked l1.total_served = 4 l2.total_served = 6 l3.total_served = 8 l1.interval_days = 3.2 l1.efactor = 1.3 l2.interval_days = 7.4 l2.efactor = 0.98 l3.interval_days = 17.4 l3.efactor = 1.98 l1.put() l2.put() l3.put() buildDailyList(today, logging) # Keep in mind building daily list means serve times will be # randomly distributed throighout the day! l1.next_serve_time = current_time l2.next_serve_time = current_time l3.next_serve_time = current_time l2.put() l1.put() l3.put() messages_generator = sendMessagesGenerator(Twitter, logging) m_list = [] while True: try: message = messages_generator.next() except StopIteration: break m_list.append(message) q1 = Question.all().fetch(3)[0] q2 = Question.all().fetch(3)[1] q3 = Question.all().fetch(3)[2] # This is a good answer a1 = "lucrative: moneymaking, profitable" # This is crappy answer a2 = u"ferociously(en): ---" # This is multiword answer a3 = u"Confounder: искажающий результаты фактор" m1 = Twitter.api.PostDirectMessage("LangBotStage", a1, "da_zbur") m2 = Twitter.api.PostDirectMessage("LangBotStage", a2, "da_zbur") m3 = Twitter.api.PostDirectMessage("LangBotStage", a3, "da_zbur") processMessage(m1) processMessage(m2) processMessage(m3) q1 = Question.all().fetch(3)[0] q2 = Question.all().fetch(3)[1] q3 = Question.all().fetch(3)[2] # For good question self.assertEqual(today, q1.answer_received) self.assertEqual(6, q1.answer_rating) self.assertEqual(6, q1.lli_ref.latest_answer_rating) self.assertEqual(sys.maxint, q1.lli_ref.next_serve_time) self.assertEqual(1.6, q1.lli_ref.efactor) self.assertEqual(3.2*1.3, q1.lli_ref.interval_days) self.assertEqual("moneymaking, profitable", q1.answer_text) # For bad question self.assertEqual(today, q2.answer_received) self.assertEqual(-2, q2.answer_rating) self.assertEqual(-2, q2.lli_ref.latest_answer_rating) self.assertEqual(0, q2.lli_ref.next_serve_time) self.assertEqual(today, q2.lli_ref.next_serve_date) self.assertEqual("---", q2.answer_text) # For multiword answer self.assertEqual(today, q3.answer_received) self.assertEqual(2, q3.answer_rating) self.assertEqual(2, q3.lli_ref.latest_answer_rating) self.assertEqual(sys.maxint, q3.lli_ref.next_serve_time) self.assertEqual(u"искажающий результаты фактор", q3.answer_text) # Check total user points, assuming he had 0 self.assertEqual(6 , User.all().filter("twitter =","da_zbur").\ get().total_points)