Esempio n. 1
0
    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)
Esempio n. 2
0
 def __init__(self, row):
     self.item_id, self.type, self.item_name, self.parent_id, self.parent_path, self.e_tag, self.c_tag, self.size, \
     self.created_time, self.modified_time, self.status, self.crc32_hash, self.sha1_hash = row
     self.created_time = str_to_datetime(self.created_time)
     self.modified_time = str_to_datetime(self.modified_time)
     self.local_path = self.parent_path.split(':',
                                              1)[1] + '/' + self.item_name
Esempio n. 3
0
 def created_time(self):
     """
     :rtype: int
     """
     if self._fs_info is not None:
         return self._fs_info.created_time
     return str_to_datetime(self._data['createdDateTime'])
Esempio n. 4
0
 def __init__(self, data=None, created_time=None, modified_time=None):
     """
     :param dict[str, str] | None data: A JSON dictionary of FileSystemInfoFacet.
     :param datetime.datetime | None created_time: A datetime object for creation time.
     :param datetime.datetime | None modified_time: A datetime object for last modification time.
     """
     if data is None:
         self.data = {}
         if created_time is not None:
             self.set_datetime('_created_time', 'createdDateTime', created_time)
         if modified_time is not None:
             self.set_datetime('_modified_time', 'lastModifiedDateTime', modified_time)
     else:
         self._created_time = str_to_datetime(data['createdDateTime'])
         self._modified_time = str_to_datetime(data['lastModifiedDateTime'])
         self.data = data
Esempio n. 5
0
 def modified_time(self):
     """
     :rtype: int
     """
     if self._fs_info is not None:
         return self._fs_info.modified_time
     return str_to_datetime(self._data['lastModifiedDateTime'])
Esempio n. 6
0
 def created_time(self):
     """
     :rtype: int
     """
     if self._fs_info is not None:
         return self._fs_info.created_time
     return str_to_datetime(self._data['createdDateTime'])
Esempio n. 7
0
 def modified_time(self):
     """
     :rtype: int
     """
     if self._fs_info is not None:
         return self._fs_info.modified_time
     return str_to_datetime(self._data['lastModifiedDateTime'])
Esempio n. 8
0
 def __init__(self, data=None, created_time=None, modified_time=None):
     """
     :param dict[str, str] | None data: A JSON dictionary of FileSystemInfoFacet.
     :param datetime.datetime | None created_time: A datetime object for creation time.
     :param datetime.datetime | None modified_time: A datetime object for last modification time.
     """
     if data is None:
         self.data = {}
         if created_time is not None:
             self.set_datetime('_created_time', 'createdDateTime',
                               created_time)
         if modified_time is not None:
             self.set_datetime('_modified_time', 'lastModifiedDateTime',
                               modified_time)
     else:
         self._created_time = str_to_datetime(data['createdDateTime'])
         self._modified_time = str_to_datetime(data['lastModifiedDateTime'])
         self.data = data
Esempio n. 9
0
 def test_parse(self):
     data = get_data('upload_session.json')
     session = resources.UploadSession(data)
     self.assertEqual(data['uploadUrl'], session.upload_url)
     self.assertEqual(str_to_datetime(data['expirationDateTime']), session.expires_at)
     ranges = []
     for r in session.next_ranges:
         if r[1] is None:
             ranges.append(str(r[0]) + '-')
         else:
             ranges.append('%d-%d' % r)
     self.assertListEqual(data['nextExpectedRanges'], ranges)
Esempio n. 10
0
 def test_parse(self):
     data = get_data('upload_session.json')
     session = resources.UploadSession(data)
     self.assertEqual(data['uploadUrl'], session.upload_url)
     self.assertEqual(str_to_datetime(data['expirationDateTime']),
                      session.expires_at)
     ranges = []
     for r in session.next_ranges:
         if r[1] is None:
             ranges.append(str(r[0]) + '-')
         else:
             ranges.append('%d-%d' % r)
     self.assertListEqual(data['nextExpectedRanges'], ranges)
Esempio n. 11
0
 def update(self, data):
     if "uploadUrl" in data:
         self.upload_url = data["uploadUrl"]
     if "expirationDateTime" in data:
         self.expires_at = str_to_datetime(data["expirationDateTime"])
     self.next_ranges = []
     if "nextExpectedRanges" in data:
         for s in data["nextExpectedRanges"]:
             f, t = s.split("-", 1)
             f = int(f)
             if t == "":
                 t = None
             else:
                 t = int(t)
             self.next_ranges.append((f, t))
Esempio n. 12
0
 def update(self, data):
     if 'uploadUrl' in data:
         self.upload_url = data['uploadUrl']
     if 'expirationDateTime' in data:
         self.expires_at = str_to_datetime(data['expirationDateTime'])
     self.next_ranges = []
     if 'nextExpectedRanges' in data:
         for s in data['nextExpectedRanges']:
             f, t = s.split('-', 1)
             f = int(f)
             if t == '':
                 t = None
             else:
                 t = int(t)
             self.next_ranges.append((f, t))
Esempio n. 13
0
def assert_properties(test, data, obj):
    """
    Assuming data uses camelCase and obj properties uses underscored lowercase, test if the property in obj matches the
    value in data.
    :param unittest.TestCase test:
    :param dict[str, T] data:
    :param T obj:
    """
    for k, v in data.items():
        if 'DateTime' in k:
            k = k.replace('DateTime', 'Time')
            v = str_to_datetime(v)
        if 'lastModified' in k:
            k = k.replace('lastModified', 'modified')
        test.assertEqual(v, getattr(obj, to_underscore_name(k)), 'The property %s does not match data.' % k)
Esempio n. 14
0
def assert_properties(test, data, obj):
    """
    Assuming data uses camelCase and obj properties uses underscored lowercase, test if the property in obj matches the
    value in data.
    :param unittest.TestCase test:
    :param dict[str, T] data:
    :param T obj:
    """
    for k, v in data.items():
        if 'DateTime' in k:
            k = k.replace('DateTime', 'Time')
            v = str_to_datetime(v)
        if 'lastModified' in k:
            k = k.replace('lastModified', 'modified')
        test.assertEqual(v, getattr(obj, to_underscore_name(k)),
                         'The property %s does not match data.' % k)
Esempio n. 15
0
 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])
Esempio n. 16
0
 def assert_timestamps(self, d, o):
     self.assertEqual(str_to_datetime(d['createdDateTime']), o.created_time)
     self.assertEqual(str_to_datetime(d['lastModifiedDateTime']), o.modified_time)
Esempio n. 17
0
 def test_parse(self):
     self.assertEqual(str_to_datetime(self.data['createdDateTime']),
                      self.facet.created_time)
     self.assertEqual(str_to_datetime(self.data['lastModifiedDateTime']),
                      self.facet.modified_time)
Esempio n. 18
0
 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])
Esempio n. 19
0
 def test_convert(self):
     self.assertEqual(self.d, onedrive_d.str_to_datetime(self.s))
     self.assertEqual(self.s, onedrive_d.datetime_to_str(self.d))
     self.assertEqual(self.t, onedrive_d.datetime_to_timestamp(self.d))
Esempio n. 20
0
 def test_parse_modified_time(self):
     self.assertEqual(
         str_to_datetime(
             self.data['fileSystemInfo']['lastModifiedDateTime']),
         self.item.modified_time)
Esempio n. 21
0
 def assert_timestamps(self, d, o):
     self.assertEqual(str_to_datetime(d['createdDateTime']), o.created_time)
     self.assertEqual(str_to_datetime(d['lastModifiedDateTime']),
                      o.modified_time)
Esempio n. 22
0
 def test_parse_modified_time(self):
     self.assertEqual(str_to_datetime(self.data['fileSystemInfo']['lastModifiedDateTime']), self.item.modified_time)
Esempio n. 23
0
 def test_convert(self):
     self.assertEqual(self.d, onedrive_d.str_to_datetime(self.s))
     self.assertEqual(self.s, onedrive_d.datetime_to_str(self.d))
     self.assertEqual(self.t, onedrive_d.datetime_to_timestamp(self.d))
Esempio n. 24
0
 def __init__(self, row):
     self.item_id, self.type, self.item_name, self.parent_id, self.parent_path, self.e_tag, self.c_tag, self.size, \
     self.created_time, self.modified_time, self.status, self.crc32_hash, self.sha1_hash = row
     self.created_time = str_to_datetime(self.created_time)
     self.modified_time = str_to_datetime(self.modified_time)
     self.local_path = self.parent_path.split(':', 1)[1] + '/' + self.item_name
Esempio n. 25
0
 def taken_time(self):
     """
     Represents the date and time the photo was taken.
     :rtype: int
     """
     return str_to_datetime(self._data['takenDateTime'])
Esempio n. 26
0
 def test_parse(self):
     self.assertEqual(str_to_datetime(self.data['createdDateTime']), self.facet.created_time)
     self.assertEqual(str_to_datetime(self.data['lastModifiedDateTime']), self.facet.modified_time)
Esempio n. 27
0
 def taken_time(self):
     """
     Represents the date and time the photo was taken.
     :rtype: int
     """
     return str_to_datetime(self._data['takenDateTime'])