def test_update_json(self, configuration, static_json): galleryitem_data = copy.deepcopy(TestGalleryItem.galleryitem_data) galleryitem = GalleryItem(configuration, galleryitem_data) assert galleryitem['title'] == 'MyGalleryItem1' assert galleryitem['type'] == 'visualization' galleryitem.update_from_json(static_json) assert galleryitem['title'] == 'MyGalleryItem1' assert galleryitem['type'] == 'other'
def test_read_from_hdx(self, configuration, read): galleryitem = GalleryItem.read_from_hdx(configuration, 'TEST1') assert galleryitem['id'] == '2f90d964-f980-4513-ad1b-5df6b2d044ff' assert galleryitem['title'] == 'MyGalleryItem1' galleryitem = GalleryItem.read_from_hdx(configuration, 'TEST2') assert galleryitem is None galleryitem = GalleryItem.read_from_hdx(configuration, 'TEST3') assert galleryitem is None
def test_update_json(self, configuration, static_json): galleryitem_data = copy.deepcopy(TestGalleryItem.galleryitem_data) galleryitem = GalleryItem(configuration, galleryitem_data) assert galleryitem['title'] == 'MyGalleryItem1' assert galleryitem['type'] == 'visualization' galleryitem.update_json(static_json) assert galleryitem['title'] == 'MyGalleryItem1' assert galleryitem['type'] == 'other'
def test_update_yaml(self, configuration, static_yaml): galleryitem_data = copy.deepcopy(TestGalleryItem.galleryitem_data) galleryitem = GalleryItem(galleryitem_data) assert galleryitem['title'] == 'MyGalleryItem1' assert galleryitem['type'] == 'visualization' galleryitem.update_from_yaml(static_yaml) assert galleryitem['title'] == 'MyGalleryItem1' assert galleryitem['type'] == 'paper'
def datasets(self): # noqa if self._datasets: return self._datasets self._datasets = {} for theme in self._feature_selection.themes: dataset = Dataset() name = '{}_{}'.format(self._dataset_prefix, theme) title = '{} {} (OpenStreetMap Export)'.format(self._name, theme) tags = [] caveats = '' if 'hdx' in self._feature_selection.doc[theme]: hdx = self._feature_selection.doc[theme]['hdx'] title = hdx.get('name') or title caveats = hdx.get('caveats', caveats) if 'tags' in hdx: tags = map(lambda tag: tag.strip(), hdx['tags'].split(',')) dataset['name'] = name dataset['title'] = title dataset['caveats'] = caveats dataset['private'] = self.is_private dataset['notes'] = self.hdx_note(theme) dataset['dataset_source'] = 'OpenStreetMap contributors' dataset.set_dataset_date_from_datetime(self._dataset_date) dataset['owner_org'] = '225b9f7d-e7cb-4156-96a6-44c9c58d31e3' dataset['license_id'] = self._license dataset['methodology'] = 'Other' dataset['methodology_other'] = 'Volunteered geographic information' dataset['data_update_frequency'] = str(self._data_update_frequency) dataset['subnational'] = str(int(self.subnational)) dataset['groups'] = [] # warning: this makes a network call [dataset.add_other_location(x) for x in self._locations] dataset.add_tags(tags) ga = GalleryItem({ 'title': 'OSM Analytics', 'description': 'View detailed information about OpenStreetMap edit history in this area.', 'url': self.osm_analytics_url, 'image_url': 'http://{}/static/ui/images/osm_analytics.png'.format( self.hostname), 'type': 'Visualization', }) dataset.add_update_galleryitem(ga) self._datasets[theme] = dataset return self._datasets
def _dataset_create_resources_gallery(self) -> None: """Creates resource and gallery item objects in dataset """ if 'resources' in self.data: self.old_data['resources'] = self._copy_hdxobjects( self.resources, Resource) self.separate_resources() if self.include_gallery: success, result = self._read_from_hdx( 'gallery', self.data['id'], 'id', GalleryItem.actions()['list']) if success: self.data['gallery'] = result self.old_data['gallery'] = self._copy_hdxobjects( self.gallery, GalleryItem) self.separate_gallery()
def add_update_galleryitem(self, galleryitem) -> None: """Add new or update existing gallery item in dataset with new metadata Args: galleryitem (Any): Gallery item metadata either from a GalleryItem object or a dictionary Returns: None """ if isinstance(galleryitem, dict): galleryitem = GalleryItem(galleryitem) if isinstance(galleryitem, GalleryItem): if 'dataset_id' in galleryitem: raise HDXError( "Gallery item %s being added already has a dataset id!" % (galleryitem['name'])) self._addupdate_hdxobject(self.gallery, 'title', galleryitem) return raise HDXError("Type %s cannot be added as a gallery item!" % type(galleryitem).__name__)
def test_delete_from_hdx(self, configuration, post_delete): galleryitem = GalleryItem.read_from_hdx(configuration, 'TEST1') galleryitem.delete_from_hdx() del galleryitem['id'] with pytest.raises(HDXError): galleryitem.delete_from_hdx()
def test_update_in_hdx(self, configuration, post_update): galleryitem = GalleryItem(configuration) galleryitem['id'] = 'NOTEXIST' with pytest.raises(HDXError): galleryitem.update_in_hdx() galleryitem['title'] = 'LALA' with pytest.raises(HDXError): galleryitem.update_in_hdx() galleryitem = GalleryItem.read_from_hdx(configuration, 'TEST1') assert galleryitem['id'] == '2f90d964-f980-4513-ad1b-5df6b2d044ff' assert galleryitem['type'] == 'visualization' galleryitem['type'] = 'paper' galleryitem['id'] = 'TEST1' galleryitem['title'] = 'MyGalleryItem1' galleryitem.update_in_hdx() assert galleryitem['id'] == 'TEST1' assert galleryitem['type'] == 'paper' galleryitem['id'] = 'NOTEXIST' with pytest.raises(HDXError): galleryitem.update_in_hdx() del galleryitem['id'] with pytest.raises(HDXError): galleryitem.update_in_hdx() galleryitem_data = copy.deepcopy(TestGalleryItem.galleryitem_data) galleryitem_data['title'] = 'MyGalleryItem1' galleryitem_data['id'] = 'TEST1' galleryitem = GalleryItem(configuration, galleryitem_data) galleryitem.create_in_hdx() assert galleryitem['id'] == 'TEST1' assert galleryitem['type'] == 'visualization'
def test_create_in_hdx(self, configuration, post_create): galleryitem = GalleryItem(configuration) with pytest.raises(HDXError): galleryitem.create_in_hdx() galleryitem['id'] = 'TEST1' galleryitem['title'] = 'LALA' with pytest.raises(HDXError): galleryitem.create_in_hdx() galleryitem_data = copy.deepcopy(TestGalleryItem.galleryitem_data) galleryitem = GalleryItem(configuration, galleryitem_data) galleryitem.create_in_hdx() assert galleryitem['id'] == '2f90d964-f980-4513-ad1b-5df6b2d044ff' galleryitem_data['title'] = 'MyGalleryItem2' galleryitem = GalleryItem(configuration, galleryitem_data) with pytest.raises(HDXError): galleryitem.create_in_hdx() galleryitem_data['title'] = 'MyGalleryItem3' galleryitem = GalleryItem(configuration, galleryitem_data) with pytest.raises(HDXError): galleryitem.create_in_hdx()