def test_root_dir_node_repr(self): """Utility method to test Rest conversion of a root directory node.""" f1 = MockNode() f1.kind = StorageObject.DIRECTORY f1.name = "" f1.path = '/' f1.full_path = "/" info = self.mapper.node_repr(f1) self.assertEqual(info['key'], f1.nodekey) self.assertEqual(info['kind'], f1.kind.lower()) self.assertEqual(info['path'], f1.full_path) self.assertEqual(info['when_created'], date_formatter(f1.when_created)) self.assertEqual(info['when_changed'], date_formatter(f1.when_last_modified)) self.assertEqual(info['generation'], f1.generation) self.assertEqual(info['generation_created'], f1.generation_created) self.assertEqual(info['parent_path'], None) self.assertEqual(info['volume_path'], "/volumes/%s" % settings.ROOT_USERVOLUME_PATH) self.assertEqual(info['content_path'], '/content/%s' % settings.ROOT_USERVOLUME_PATH) # make sure directory specific rules apply self.assertTrue('hash' not in info) self.assertTrue('is_public' not in info) self.assertTrue('public_url' not in info) self.assertTrue('has_children' in info) self.assertEqual(info['is_live'], True)
def test_root_dir_node_repr(self): """Utility method to test Rest conversion of a root directory node.""" f1 = MockNode() f1.kind = StorageObject.DIRECTORY f1.name = "" f1.path = '/' f1.full_path = "/" info = self.mapper.node_repr(f1) self.assertEqual(info['key'], f1.nodekey) self.assertEqual(info['kind'], f1.kind.lower()) self.assertEqual(info['path'], f1.full_path) self.assertEqual(info['when_created'], date_formatter(f1.when_created)) self.assertEqual( info['when_changed'], date_formatter(f1.when_last_modified)) self.assertEqual(info['generation'], f1.generation) self.assertEqual(info['generation_created'], f1.generation_created) self.assertEqual(info['parent_path'], None) self.assertEqual( info['volume_path'], "/volumes/%s" % settings.ROOT_USERVOLUME_PATH) self.assertEqual( info['content_path'], '/content/%s' % settings.ROOT_USERVOLUME_PATH) # make sure directory specific rules apply self.assertTrue('hash' not in info) self.assertTrue('is_public' not in info) self.assertTrue('public_url' not in info) self.assertTrue('has_children' in info) self.assertEqual(info['is_live'], True)
def test_file_node_repr(self): """Test Rest conversion of a file node.""" f1 = MockNode() info = self.mapper.node_repr(f1) self.assertEqual(info['key'], f1.nodekey) self.assertEqual(info['kind'], f1.kind.lower()) self.assertEqual(info['path'], f1.full_path) self.assertEqual(info['hash'], f1.content_hash) self.assertEqual(info['when_created'], date_formatter(f1.when_created)) self.assertEqual(info['when_changed'], date_formatter(f1.when_last_modified)) self.assertEqual(info['generation'], f1.generation) self.assertEqual(info['generation_created'], f1.generation_created) self.assertEqual(info['public_url'], f1.public_url) self.assertEqual(info['is_public'], f1.is_public) self.assertEqual(info['parent_path'], "/%s/a/b/c/d" % settings.ROOT_USERVOLUME_PATH) self.assertEqual(info['volume_path'], "/volumes/%s" % settings.ROOT_USERVOLUME_PATH) self.assertEqual( info['content_path'], '/content/%s/a/b/c/d/file.txt' % settings.ROOT_USERVOLUME_PATH) # make sure file specific rules apply self.assertTrue('has_children' not in info) self.assertEqual(info['is_live'], True)
def test_file_node_repr(self): """Test Rest conversion of a file node.""" f1 = MockNode() info = self.mapper.node_repr(f1) self.assertEqual(info['key'], f1.nodekey) self.assertEqual(info['kind'], f1.kind.lower()) self.assertEqual(info['path'], f1.full_path) self.assertEqual(info['hash'], f1.content_hash) self.assertEqual( info['when_created'], date_formatter(f1.when_created)) self.assertEqual( info['when_changed'], date_formatter(f1.when_last_modified)) self.assertEqual(info['generation'], f1.generation) self.assertEqual(info['generation_created'], f1.generation_created) self.assertEqual(info['public_url'], f1.public_url) self.assertEqual(info['is_public'], f1.is_public) self.assertEqual( info['parent_path'], "/%s/a/b/c/d" % settings.ROOT_USERVOLUME_PATH) self.assertEqual( info['volume_path'], "/volumes/%s" % settings.ROOT_USERVOLUME_PATH) self.assertEqual( info['content_path'], '/content/%s/a/b/c/d/file.txt' % settings.ROOT_USERVOLUME_PATH) # make sure file specific rules apply self.assertTrue('has_children' not in info) self.assertEqual(info['is_live'], True)
def test_volume_repr(self): """Test Rest conversion of a volume.""" udf = MockVolume() info = self.mapper.volume_repr(udf) self.assertEqual(info['resource_path'], '/volumes/~/Documents') self.assertEqual(info['type'], 'root' if udf.is_root else 'udf') self.assertEqual(info['path'], udf.path) self.assertEqual(info['generation'], udf.generation) self.assertEqual(info['node_path'], self.mapper.node(udf.path)) self.assertEqual(info['when_created'], date_formatter(udf.when_created))
def test_volume_repr(self): """Test Rest conversion of a volume.""" udf = MockVolume() info = self.mapper.volume_repr(udf) self.assertEqual(info['resource_path'], '/volumes/~/Documents') self.assertEqual(info['type'], 'root' if udf.is_root else 'udf') self.assertEqual(info['path'], udf.path) self.assertEqual(info['generation'], udf.generation) self.assertEqual(info['node_path'], self.mapper.node(udf.path)) self.assertEqual( info['when_created'], date_formatter(udf.when_created))
def test_volume_with_delta_repr0(self): """Test Rest conversion of a vol with delta information, no nodes.""" udf = MockVolume() nodes = [] info = self.mapper.volume_repr( volume=udf, from_generation=0, nodes=nodes) self.assertEqual(info['resource_path'], '/volumes/~/Documents') self.assertEqual(info['type'], 'root' if udf.is_root else 'udf') self.assertEqual(info['path'], udf.path) self.assertEqual(info['generation'], udf.generation) self.assertEqual(info['node_path'], self.mapper.node(udf.path)) self.assertEqual( info['when_created'], date_formatter(udf.when_created)) self.assertEqual(info['delta']['from_generation'], 0) self.assertEqual(info['delta']['nodes'], nodes)
def test_volume_with_delta_repr0(self): """Test Rest conversion of a vol with delta information, no nodes.""" udf = MockVolume() nodes = [] info = self.mapper.volume_repr(volume=udf, from_generation=0, nodes=nodes) self.assertEqual(info['resource_path'], '/volumes/~/Documents') self.assertEqual(info['type'], 'root' if udf.is_root else 'udf') self.assertEqual(info['path'], udf.path) self.assertEqual(info['generation'], udf.generation) self.assertEqual(info['node_path'], self.mapper.node(udf.path)) self.assertEqual(info['when_created'], date_formatter(udf.when_created)) self.assertEqual(info['delta']['from_generation'], 0) self.assertEqual(info['delta']['nodes'], nodes)