def test_journal_tag_parsign(self): volley = [ ("Fun #PoolParty with @KatyRoth", ["#PoolParty"], ["@KatyRoth"]), ("Stressful day at work with @BarackObama", [], ["@BarackObama"]), ("Went #Fishing with @JohnKariuki and got #Sick off #Seafood", ["#Fishing", "#Sick", "#Seafood"], ["@JohnKariuki"]), ("Went #Fishing with @BarackObama", ["#Fishing"], ["@BarackObama"]), (None, [], []), (5, [], []) ] for v in volley: txt, expected_hashes, expected_people = v jts = JournalTag.CreateFromText(self.u, txt) hashes = map(lambda jt: jt.key.id(), filter(lambda jt: not jt.person(), jts)) people = map(lambda jt: jt.key.id(), filter(lambda jt: jt.person(), jts)) self.assertEqual(expected_hashes, hashes) self.assertEqual(expected_people, people) self.assertEqual(len(JournalTag.All(self.u)), 7)
def test_stateful_journal_submission(self): # Journal submissions ask multiple questions and require # state to be kept in a conversation_state object (memcached) # Setup journal questions for account # settings = tools.getJson(self.u.settings) NARR = "Productive! #Hacked a few things with @JuliaSpiegel" RATING = 7 conversation = [ # (User message, Flow reply) ("daily report", "A few words on your day?", False), # narrative (NARR, "How was the day?", False), # day_rating ("?", JOURNAL.INVALID_REPLY + " " + JOURNAL.INVALID_SUFFIX_NUMERIC, False), ("%s" % RATING, JOURNAL.TOP_TASK_PROMPT, False), ("Finish hacking the machine", JOURNAL.TOP_TASK_PROMPT_ADDTL, False), ("done", "Report submitted!", True) ] for message, expected_reply, expected_end_of_convo in conversation: action, params = self.ca.parse_message(message) reply, message_data, end_convo = self.ca.respond_to_action( action, parameters=params) self.assertEqual(expected_end_of_convo, end_convo) self.assertEqual(reply, expected_reply) # Confirm journal saved properly jrnl = MiniJournal.Get(self.u) self.assertIsNotNone(jrnl) rating = jrnl.get_data_value('day_rating') self.assertEqual(rating, RATING) narrative = jrnl.get_data_value('narrative') self.assertEqual(narrative, NARR) # Confirm we have tags from narrative tags = JournalTag.All(self.u) self.assertEqual(len(tags), 2) for t in tags: if t.person(): self.assertEqual(t.name, "JuliaSpiegel") else: self.assertEqual(t.name, "Hacked") # Confirm we created tasks tasks = Task.Open(self.u) self.assertEqual(len(tasks), 2) # One added in journal self.assertEqual(tasks[0].title, "Finish hacking the machine") # Try to submit again action, params = self.ca.parse_message("daily journal") reply, message_data, end_convo = self.ca.respond_to_action( action, parameters=params) self.assertEqual(reply, JOURNAL.ALREADY_SUBMITTED_REPLY)
def list(self, d): tags = JournalTag.All(self.user) self.set_response({ 'tags': [tag.json() for tag in tags] }, success=True)