def test_update_item(self): new_params = { 'item_id': '123', 'new_name': 'whatever.doc', 'new_description': 'This is a dummy description.', 'new_parent_reference': resources.ItemReference.build(drive_id='aaa', id='012'), 'new_file_system_info': facets.FileSystemInfoFacet( created_time=str_to_datetime('1971-01-01T02:03:04Z'), modified_time=str_to_datetime('2008-01-02T03:04:05.06Z')) } with requests_mock.Mocker() as mock: def callback(request, context): json = request.json() self.assertEqual(json['name'], new_params['new_name']) self.assertEqual(json['description'], new_params['new_description']) self.assertDictEqual(json['parentReference'], new_params['new_parent_reference'].data) self.assertDictEqual(json['fileSystemInfo'], new_params['new_file_system_info'].data) return get_data('image_item.json') mock.patch(self.drive.get_item_uri(new_params['item_id'], None), json=callback) self.drive.update_item(**new_params)
def handle(self): try: fs_info = facets.FileSystemInfoFacet(modified_time=self.new_mtime) new_item = self.drive.update_item(item_path=self.parent_path + '/' + self.name, new_file_system_info=fs_info) self.items_store.update_item(new_item, ItemRecordStatuses.OK) except errors.OneDriveError as e: self.logger.error('Error occurred when polling copy to "%s": %s.', self.local_parent_path + '/' + self.name, e)
def __init__(self, drive, data): """ :param onedrive_d.api.drives.DriveObject drive: The parent drive object. :param dict[str, str | int | dict[str, str | int | dict]] data: JSON response for an Item resource. """ self.drive = drive self._data = data if 'fileSystemInfo' in data: self._fs_info = facets.FileSystemInfoFacet(data['fileSystemInfo']) else: self._fs_info = None
def handle(self): local_item_path = self.local_parent_path + '/' + self.name try: size = os.path.getsize(local_item_path) with open(local_item_path, 'rb') as f: item = self.drive.upload_file( filename=self.name, data=f, size=size, parent_path=self.parent_path, conflict_behavior=self.conflict_behavior) modified_time = timestamp_to_datetime(os.path.getmtime(local_item_path)) fs_info = facets.FileSystemInfoFacet(modified_time=modified_time) item = self.drive.update_item(item_id=item.id, new_file_system_info=fs_info) self.items_store.update_item(item, ItemRecordStatuses.OK) except Exception as e: self.logger.error('Error occurred when uploading "%s": %s.', local_item_path, e)
def assert_timestamp(self, attr_name, dict_key, time_str): obj = facets.FileSystemInfoFacet( **{attr_name: str_to_datetime(time_str)}) self.assertEqual(str_to_datetime(time_str), getattr(obj, attr_name, None)) self.assertEqual(time_str, obj.data[dict_key])
def setUp(self): self.data = get_data('facets/filesysteminfo_facet.json') self.facet = facets.FileSystemInfoFacet(self.data)