예제 #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) 
예제 #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)
예제 #3
0
 def test_get_tasklist(self):
     expected_tasklist = TaskList(entity_id="1",
         title="Test List Title", updated_date=datetime(2012, 3, 10, 3, 30, 6))
     
     mock_service_proxy = mock()
     mock_get_request = mock()
     when(mock_service_proxy).get(tasklist=expected_tasklist.entity_id).thenReturn(mock_get_request)
     when(mock_get_request).execute().thenReturn(expected_tasklist.to_str_dict())
     
     tasklist_service = TaskListService(mock_service_proxy)
     result_tasklist = tasklist_service.get_tasklist(expected_tasklist.entity_id) 
     
     self.assertEqual(expected_tasklist, result_tasklist)
예제 #4
0
 def test_add_list(self):
     mock_service_proxy = mock()
     mock_insert_request = mock()
     
     tasklist = TaskList(entity_id="abcdfakekey", title="Test List 1",
         updated_date=datetime(2012, 3, 22, 13, 50, 00))
     
     when(mock_service_proxy).insert(body=any(dict)).thenReturn(mock_insert_request)
     when(mock_insert_request).execute().thenReturn(tasklist.to_str_dict())
             
     tasklist_service = TaskListService(mock_service_proxy)        
     result_tasklist = tasklist_service.add_tasklist(tasklist)
     
     verify(mock_insert_request).execute()
     self.assertIsNotNone(result_tasklist)
     self.assertIsNotNone(result_tasklist.entity_id)
예제 #5
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)
예제 #6
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)
예제 #7
0
    def add_tasklist(self, tasklist):
        tasklist_dict = tasklist.to_str_dict()
                
        # Create a dict with only a 'title' property; it looks like everything
        # else is ignored by the GTask service insert handler.
        keywords = coggrinder.utilities.GoogleKeywords
        filtered_insert_dict = coggrinder.utilities.DictUtilities.filter_dict(tasklist_dict,
            (keywords.TITLE,))
        
        # Execute the insert operation.
        result_dict = self.service_proxy.insert(body=filtered_insert_dict).execute()

        # Convert the resulting dict (which contains assigned ID, updated values
        # from the service) back into a TaskList object.
        tasklist = TaskList.from_str_dict(result_dict)

        return tasklist
예제 #8
0
 def get_all_tasklists(self):     
     """
     Return a dictionary of all tasklists available. Dictionary keys will be
     entity IDs, values will be the corresponding tasklist instances.
     """   
     tasklist_items_dict = self.service_proxy.list().execute()
     
     assert tasklist_items_dict.has_key(coggrinder.utilities.GoogleKeywords.ITEMS)
     
     tasklist_items_list = tasklist_items_dict.get(coggrinder.utilities.GoogleKeywords.ITEMS)
     
     tasklist_result_list = dict()
     for tasklist_dict in tasklist_items_list:
         tasklist = TaskList.from_str_dict(tasklist_dict)
         
         tasklist_result_list[tasklist.entity_id] = tasklist
      
     return tasklist_result_list
예제 #9
0
 def test_get_all_tasklists(self):         
     mock_service_proxy = mock()
     mock_list_request = mock()
                      
     tasklist_items_dict = {coggrinder.utilities.GoogleKeywords.ITEMS:[]}
     expected_tasklists = dict()
     
     for count in range(1, 4):
         tasklist = TaskList(entity_id=str(count),
             title="Test List " + str(count), updated_date=datetime(2012, 3, 10, 3, 30, 6)) 
         
         expected_tasklists[tasklist.entity_id] = tasklist
         tasklist_items_dict.get(coggrinder.utilities.GoogleKeywords.ITEMS).append(tasklist.to_str_dict())
                 
     when(mock_service_proxy).list().thenReturn(mock_list_request) 
     when(mock_list_request).execute().thenReturn(tasklist_items_dict)        
     
     tasklist_service = TaskListService(mock_service_proxy)
     
     result_tasklists = tasklist_service.get_all_tasklists()
     
     self.assertEqual(expected_tasklists, result_tasklists)
예제 #10
0
    def update_tasklist(self, tasklist):
        """
        This method updates the TaskList using a patch command rather than a
        full update.
        TODO: Enhance this method to only update fields that have been locally
        modified.
        """
        tasklist_dict = tasklist.to_str_dict()
                
        # Create a dict with only the 'title' and 'id' properties.   
        keywords = coggrinder.utilities.GoogleKeywords
        filtered_update_dict = coggrinder.utilities.DictUtilities.filter_dict(tasklist_dict,
            (keywords.TITLE, keywords.ID))
        
        # Execute the update operation.
        result_dict = self.service_proxy.patch(tasklist=tasklist.entity_id,
            body=filtered_update_dict).execute()

        # Convert the resulting dict (which contains updated values  from the 
        # service) back into a TaskList object.
        tasklist = TaskList.from_str_dict(result_dict)

        return tasklist
예제 #11
0
 def get_tasklist(self, entity_id):        
     tasklist_dict = self.service_proxy.get(tasklist=entity_id).execute()
     
     tasklist = TaskList.from_str_dict(tasklist_dict)
     
     return tasklist
예제 #12
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)