def test_file__init__(self): ac = mock.Mock(spec=Agave) af = AgaveFile(wrap=self.afile_json, agave_client=ac) self.assertEqual(af.agave_client, ac) self.assertDictEqual(af._wrap, self.afile_json) self.assertFalse(af._permissions)
def test_folder__init__(self): ac = mock.Mock(spec=Agave) af = AgaveFile(wrap=self.afile_json, agave_client=ac) self.assertEqual(af.agave_client, ac) self.assertDictEqual(af._wrap, self.afile_json) self.assertEqual(af.name, af.path.split('/')[-1]) self.assertFalse(af._permissions)
def test_folder__init__with_pems(self): ac = mock.Mock(spec=Agave) self.afile_json['permissions'] = self.apems_json af = AgaveFile(wrap=self.afile_json, agave_client=ac) self.assertEqual(af.agave_client, ac) self.assertDictEqual(af._wrap, self.afile_json) self.assertEqual(af.name, af.path.split('/')[-1]) for i, pem in enumerate(af.permissions): self.assertDictEqual(pem, self.apems_json[i])
def to_file_dict(self): """Returns a dictionary correctly formatted as a data api response. This method first constructs a dictionary that looks like a response from an agave call to `files.listing`. After this it instantiates a :class:`~designsafe.apps.api.agave.files.AgaveFile` object and returns the result of :meth:`~designsafe.apps.api.agave.files.AgaveFile.to_dict`. We hand off the dict construction to the :class:`~designsafe.apps.api.agave.files.AgaveFile` class so we don't have to implement it twice. :param string pems_user: User to filter permissions for :returns: dict object representation of a file :rtype: dict .. note:: in future releases the ES documents in the index should look like the response of an agave call to `files.listing`. We would need to keep this method to hand of the dict construction to the :class:`~designsafe.apps.api.agave.files.AgaveFile` class """ try: lm = dateutil.parser.parse(self.lastModified) except AttributeError: lm = datetime.datetime.now() pems = self.to_dict()['permissions'] wrap = { 'format': getattr(self, 'format', 'folder'), 'lastModified': lm, 'length': self.length, 'mimeType': self.mimeType, 'name': self.name, 'path': os.path.join(self.path, self.name).strip('/'), 'permissions': pems, 'system': self.systemId, 'type': self.type, '_pems': pems } f = AgaveFile(wrap=wrap) extra = { 'meta': { 'keywords': self.to_dict().get('keywords', list([])), 'systemTags': self.to_dict().get('systemTags', list([])) } } return f.to_dict(extra=extra)
def get_mock_file(self): ac = mock.Mock() af = AgaveFile(wrap=self.afile_json.copy(), agave_client=ac) return af
def get_mock_agave_file(self): ac = mock.Mock() wrap = self.afile_json.copy() wrap['lastModified'] = dateutil.parser.parse(wrap['lastModified']) af = AgaveFile(wrap = wrap, agave_client = ac) return af