def find_list(self, list_name): list_result, error_text, error_code = cow_rest.get_list() if error_text: self.speak_dialog('RestResponseError', {ERROR_TEXT_PARAMETER: error_text, ERROR_CODE_PARAMETER: error_code}) return LIST_TUPLE(None, None, None, error_text, error_code) # Workaround the intent parser remove the word list: First, try to # match to a "list_name list" list_name_best_match, significance = ( process.extractOne(list_name + " list", map(lambda x: x['name'].lower(), list_result))) # Then try to match to "list_name" if significance < 100: list_name_best_match, significance = ( process.extractOne(list_name, map(lambda x: x['name'].lower(), list_result))) list_id = [x for x in list_result if x['name'].lower() == list_name_best_match][0]['id'] self.set_context(LIST_CONTEXT, json.dumps({'id': list_id, 'name': list_name_best_match, 'significance': significance})) return LIST_TUPLE(list_name_best_match, list_id, significance, None, 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
def test_get_list(self): list_id, error_text, error_code = cow_rest.get_list() self.assertEqual(error_text, TEXT_LOGIN_FAILED) self.assertEqual(error_code, CODE_LOGIN_FAILED)