def undo_intent(self, message): try: c = json.loads(message.data.get(UNDO_CONTEXT)) if c['dialog'] == "AddTaskToListUndo": transaction_id, error_text, error_code = cow_rest.delete_task( c['task']['task_id'], c['task']["taskseries_id"], c['task']["list_id"]) if error_text: self.speak_dialog('RestResponseError', {ERROR_TEXT_PARAMETER: error_text, ERROR_CODE_PARAMETER: error_code}) return self.speak_dialog(c['dialog'], c['dialogParam']) if c['dialog'] in ["CompleteTaskOnListUndo", "CompleteListOneTaskUndo", "CompleteListUndo"]: for t in c['transaction_id']: error_text, error_code = cow_rest.roll_back(str(t)) if error_text: self.speak_dialog('RestResponseError', {ERROR_TEXT_PARAMETER: error_text, ERROR_CODE_PARAMETER: error_code}) return self.speak_dialog(c['dialog'], c['dialogParam']) except Exception: self.speak_exception(traceback.format_exc(), message, "undo intent")
def test_delete_task(self): cow_rest.timeline = "0" transaction_id, error_text, error_code = cow_rest.delete_task( "0", "0", "0") self.assertEqual(error_text, TEXT_LOGIN_FAILED) self.assertEqual(error_code, CODE_LOGIN_FAILED) self.assertEqual(transaction_id, None)
def test_add_remove_item_to_list(self): task_name = "Cows Lists test item: " + str(uuid.uuid1()) print "Working on item:" + task_name cow_rest.get_token(cow_rest) self.assertNotEqual(cow_rest.auth_token, None) error_text, error_code = cow_rest.verify_token_validity() self.assertEqual(error_text, None) error_text, error_code = cow_rest.get_timeline(cow_rest) self.assertEqual(error_text, None) self.assertNotEqual(cow_rest.timeline, None) # Get all lists list_result, error_text, error_code = cow_rest.get_list() self.assertEqual(error_text, None) list_id = filter(lambda x: str(x['name']).lower() == "inbox", list_result)[0]['id'] # add an item taskseries_id, task_id, error_text, error_code = cow_rest.add_task( task_name, list_id) self.assertEqual(error_text, None) self.assertNotEqual(task_id, None) # check item was added task_list, error_code, error_text = cow_rest.list_task( "status:incomplete", list_id) self.assertEqual(error_text, None) task_match = cow_rest.find_task_id(task_list, taskseries_id, task_id) self.assertNotEqual(task_match, None) # assuming RTM make unique tasks # check flat list flat_task_list = cow_rest.flat_task_list(task_list) self.assertTrue( len( filter( lambda x: x['task_name'] == task_name and x[ 'taskseries_id'] == taskseries_id and x['task_id'] == task_id, flat_task_list)) > 0) # mark task as complete transaction_id, error_text, error_code = cow_rest.complete_task( task_id, taskseries_id, list_id) self.assertEqual(error_text, None) self.assertNotEqual(transaction_id, None) # check item is completed task_list, error_code, error_text = cow_rest.list_task( "status:completed", list_id) self.assertEqual(error_text, None) task_match = cow_rest.find_task_id(task_list, taskseries_id, task_id) self.assertNotEqual(task_match, None) # assuming RTM make unique tasks # roll back error_text, error_code = cow_rest.roll_back(str(transaction_id)) self.assertEqual(error_text, None) # check item was set back to incomplete task_list, error_code, error_text = cow_rest.list_task( "status:incomplete", list_id) self.assertEqual(error_text, None) task_match = cow_rest.find_task_id(task_list, taskseries_id, task_id) self.assertNotEqual(task_match, None) # assuming RTM make unique tasks # delete the item transaction_id, error_text, error_code = cow_rest.delete_task( task_id, taskseries_id, list_id) self.assertEqual(error_text, None) self.assertNotEqual(transaction_id, None) # check item was deleted task_list, error_code, error_text = cow_rest.list_task( "status:incomplete", list_id) self.assertEqual(error_text, None) task_match = cow_rest.find_task_id(task_list, taskseries_id, task_id) self.assertEqual(task_match, None) # assuming RTM make unique tasks