Ejemplo n.º 1
0
class TestUpdateMetadataTask(TestUpTaskBase):
    def setUp(self):
        self.initialize_obj()
        self.new_mtime = 123412341234
        self.task = UpdateMetadataTask(self.parent_task, "/", "foo.txt", self.new_mtime)

    def test_handle(self):
        with mock.patch("onedrived.api.facets.FileSystemInfoFacet") as mock_class:
            self.task.handle()
            mock_class.assert_called_once_with(modified_time=timestamp_to_datetime(self.new_mtime))
        self.assertEqual(1, len(self.task.items_store.get_items_by_id(item_id=self.item.id)))

    def test_handle_error(self):
        self.parent_task.drive.update_item = mock.Mock(
            side_effect=OneDriveError(get_data("error_server_internal.json"))
        )
        self.task.handle()
Ejemplo n.º 2
0
class TestUpdateMetadataTask(TestUpTaskBase):
    def setUp(self):
        self.initialize_obj()
        self.new_mtime = 123412341234
        self.task = UpdateMetadataTask(self.parent_task, '/', 'foo.txt',
                                       self.new_mtime)

    def test_handle(self):
        with mock.patch(
                'onedrived.api.facets.FileSystemInfoFacet') as mock_class:
            self.task.handle()
            mock_class.assert_called_once_with(
                modified_time=timestamp_to_datetime(self.new_mtime))
        self.assertEqual(
            1,
            len(self.task.items_store.get_items_by_id(item_id=self.item.id)))

    def test_handle_error(self):
        self.parent_task.drive.update_item = mock.Mock(
            side_effect=OneDriveError(get_data('error_server_internal.json')))
        self.task.handle()
Ejemplo n.º 3
0
 def _update_attr_when_hash_equal(self, item_local_path, item):
     t = datetime_to_timestamp(item.modified_time)
     try:
         self.logger.info('Updating timestamp for file "%s" to "%s".',
                          item_local_path, str(item.modified_time))
         os.utime(item_local_path, (t, t))
         self.items_store.update_item(item, ItemRecordStatuses.OK)
     except (IOError, OSError) as e:
         self.logger.error(
             'IO error when updating timestamp for file "%s": %s',
             item_local_path, e)
         if not self.task_pool.has_pending_task(item_local_path):
             self.logger.info(
                 'Update server timestamp for file "%s" instead.',
                 item_local_path)
             self.task_pool.add_task(
                 UpdateMetadataTask(self,
                                    rel_parent_path=self.rel_path + '/',
                                    item_name=item.name,
                                    new_mtime=t))
Ejemplo n.º 4
0
 def setUp(self):
     self.initialize_obj()
     self.new_mtime = 123412341234
     self.task = UpdateMetadataTask(self.parent_task, '/', 'foo.txt',
                                    self.new_mtime)
Ejemplo n.º 5
0
 def setUp(self):
     self.initialize_obj()
     self.new_mtime = 123412341234
     self.task = UpdateMetadataTask(self.parent_task, "/", "foo.txt", self.new_mtime)