Ejemplo n.º 1
0
 def test_get_tasks_in_tasklist(self):
     tasklist = TaskList()
     tasklist.entity_id = "abclistid"
     
     list_result_str_dict = {coggrinder.utilities.GoogleKeywords.ITEMS:[]}
     expected_tasks = dict()
     
     for count in range(1, 4):
         task = Task(entity_id=str(count),
             title="Test Task " + str(count),
             updated_date=datetime(2012, 3, 10, 3, 30, 6),
             parent_id=tasklist.entity_id) 
         
         expected_tasks[task.entity_id] = task
         list_result_str_dict.get(coggrinder.utilities.GoogleKeywords.ITEMS).append(task.to_str_dict())
                  
     # Mock service and request objects.
     mock_service_proxy = mock()
     mock_list_request = mock()        
                 
     when(mock_service_proxy).list(tasklist=tasklist.entity_id).thenReturn(mock_list_request) 
     when(mock_list_request).execute().thenReturn(list_result_str_dict) 
     
     # Establish the TaskService and execute the list request.
     task_service = TaskService(mock_service_proxy)
     actual_tasks = task_service.get_tasks_in_tasklist(tasklist)
     
     self.assertEqual(expected_tasks, actual_tasks) 
Ejemplo n.º 2
0
 def test_get_task_minimal(self):
     tasklist = TaskList()
     tasklist.entity_id = "tasklistid"
     
     expected_task_id = "abcid"
     expected_task_title = "Task title"
     expected_task_updated_date = datetime(2012, 3, 26, 22, 59, 24)
     expected_task_position = 10456
     expected_task_status = TaskStatus.NEEDS_ACTION
     
     result_str_dict = {
         GoogleKeywords.ID: StrConverter().to_str(expected_task_id),
         GoogleKeywords.TITLE: StrConverter().to_str(expected_task_title),
         GoogleKeywords.UPDATED: RFC3339Converter().to_str(expected_task_updated_date),
         GoogleKeywords.POSITION: IntConverter().to_str(expected_task_position),
         GoogleKeywords.STATUS: TaskStatusConverter().to_str(expected_task_status)
     }
     
     mock_service_proxy = mock()
     mock_get_request = mock()
     when(mock_service_proxy).get(tasklist=tasklist.entity_id, task=expected_task_id).thenReturn(mock_get_request)
     when(mock_get_request).execute().thenReturn(result_str_dict)
     
     task_service = TaskService(mock_service_proxy)
     actual_task = task_service.get_task(tasklist.entity_id, expected_task_id)
     
     self.assertIsNotNone(actual_task)
     self.assertEqual(expected_task_id, actual_task.entity_id)
     self.assertEqual(expected_task_title, actual_task.title)
     self.assertEqual(expected_task_updated_date, actual_task.updated_date)
     self.assertEqual(expected_task_position, actual_task.position)
     self.assertEqual(expected_task_status, actual_task.task_status)
Ejemplo n.º 3
0
 def test_get_entity_tasklist_only(self):
     expected_tasklists = dict()
     tasklist_count = 3
     for i in range(tasklist_count):
         tasklist = TaskList()
         tasklist.entity_id = "tl-{0}".format(i)
         tasklist.title = "TaskList {0}".format(i)
         
         expected_tasklists[tasklist.entity_id] = tasklist
         
     task_treestore = TaskTreeStore(expected_tasklists, {})
     
     actual_tasklists = dict()
     for i in range(tasklist_count):
         actual_tasklist = task_treestore.get_entity(str(i))
         self.assertIsNotNone(actual_tasklist)
         
         actual_tasklists[actual_tasklist.entity_id] = actual_tasklist
         
     self.assertEqual(expected_tasklists, actual_tasklists)
Ejemplo n.º 4
0
 def test_add_task(self):
     tasklist = TaskList()
     tasklist.entity_id = "tasklistid"        
     
     expected_task = Task()
     expected_task.entity_id = "abcid"
     expected_task.tasklist_id = tasklist.entity_id
     expected_task.title = "Task title"
     
     now = datetime.now()
     expected_task_updated_date = datetime(now.year, now.month, now.day,
         now.hour, now.minute, now.second)
     expected_task_position = 10456 
     expected_task_status = TaskStatus.NEEDS_ACTION
     
     result_str_dict = {
         GoogleKeywords.ID: StrConverter().to_str(expected_task.entity_id),
         GoogleKeywords.TITLE: StrConverter().to_str(expected_task.title),
         GoogleKeywords.UPDATED: RFC3339Converter().to_str(expected_task_updated_date),
         GoogleKeywords.POSITION: IntConverter().to_str(expected_task_position),
         GoogleKeywords.STATUS: TaskStatusConverter().to_str(expected_task_status)
     }
     
     mock_service_proxy = mock()
     mock_insert_request = mock()
     when(mock_service_proxy).insert(tasklist=tasklist.entity_id, body=any(dict)).thenReturn(mock_insert_request)
     when(mock_insert_request).execute().thenReturn(result_str_dict)
     
     task_service = TaskService(mock_service_proxy)
     actual_task = task_service.add_task(expected_task)
     
     self.assertIsNotNone(actual_task)
     self.assertEqual(expected_task.entity_id, actual_task.entity_id)
     self.assertEqual(expected_task.tasklist_id, actual_task.tasklist_id)
     self.assertEqual(expected_task.title, actual_task.title)
     self.assertEqual(expected_task_updated_date, actual_task.updated_date)
     self.assertEqual(expected_task_position, actual_task.position)
     self.assertEqual(expected_task_status, actual_task.task_status)
Ejemplo n.º 5
0
 def test_delete_task(self):
     # IDs used to specify which task to delete and get.
     tasklist = TaskList()
     tasklist.entity_id = "tasklistid"
     
     # Fake an updated update date by capturing a date, adding five minutes,
     # and using that new date as the date source for a str dict that is
     # returned by the fake service proxy?
     existing_updated_date = datetime(2012, 3, 21, 13, 52, 06)
     expected_updated_date = datetime(2012, 3, 21, 13, 57, 06)
     
     input_task = Task()
     input_task.entity_id = "abcid"
     input_task.tasklist_id = tasklist.entity_id
     input_task.title = "Task title"
     input_task.position = 10456 
     input_task.task_status = TaskStatus.COMPLETED
     input_task.updated_date = existing_updated_date
     
     expected_task = Task()
     expected_task.entity_id = input_task.entity_id
     expected_task.title = input_task.entity_id
     expected_task.position = input_task.position
     expected_task.task_status = input_task.task_status
     expected_task.updated_date = expected_updated_date
     
     # Mock service and request objects.
     mock_service_proxy = mock()
     mock_delete_request = mock()
     mock_get_request = mock()
     
     # Note that this str dict serves as the result of a subsequent get 
     # called on the same task after that task has been deleted. It includes
     # the expected (mock updated) update date.
     get_result_str_dict = {
         GoogleKeywords.ID: StrConverter().to_str(expected_task.entity_id),
         GoogleKeywords.TITLE: StrConverter().to_str(expected_task.title),
         GoogleKeywords.UPDATED: RFC3339Converter().to_str(expected_updated_date),
         GoogleKeywords.POSITION: IntConverter().to_str(expected_task.position),
         GoogleKeywords.STATUS: TaskStatusConverter().to_str(expected_task.task_status),
         GoogleKeywords.DELETED: BooleanConverter().to_str(True)
     }
     
     # Set up service proxy mock behavior in order to provide the delete
     # method with the necessary backend.
     when(mock_service_proxy).delete(tasklist=tasklist.entity_id, task=input_task.entity_id).thenReturn(mock_delete_request)
     when(mock_delete_request).execute().thenReturn("")
     when(mock_service_proxy).get(tasklist=tasklist.entity_id, task=input_task.entity_id).thenReturn(mock_get_request)
     when(mock_get_request).execute().thenReturn(get_result_str_dict)
     
     # Create a new TaskService.
     task_service = TaskService(mock_service_proxy)
     
     # Delete the task, and store the updated results.
     actual_task = task_service.delete_task(input_task)
     
     # Task should be present and have these updated properties:
     # * update date
     # * deleted
     self.assertIsNotNone(actual_task)
     self.assertEqual(expected_updated_date, actual_task.updated_date)
     self.assertTrue(actual_task.is_deleted, True)