def test__webresource__source_path_exists(tmpdir, settings): test_base = str(tmpdir) webresource = WebResource(spec=spec_name, base_dir=test_base, uri=test_uri) webresource.create_dataset_webresource_dirs() test_image = os.path.join(os.path.dirname(__file__), 'nasa_ares_logo.png') shutil.copy(test_image, webresource.uri_to_path) assert os.path.exists(webresource.uri_to_path) assert webresource.exists_source webresource = WebResource(spec=spec_name, base_dir=test_base, uri='urn:{}/fake_image.jpg'.format(webresource.spec)) assert not os.path.exists(webresource.uri_to_path) assert not webresource.exists_source
def test__create_dataset_webresource_dir(tmpdir): test_base = str(tmpdir) webresource = WebResource(spec=spec_name, base_dir=test_base) assert webresource is not None assert webresource.base_dir == test_base assert len(os.listdir(test_base)) == 0 assert not webresource.exist_webresource_dirs webresource.create_dataset_webresource_dirs() assert len(os.listdir(test_base)) != 0 assert os.listdir(test_base) == [webresource.org_id] assert os.path.exists( os.path.join(webresource.get_spec_dir, THUMBNAIL_DIR) ) assert webresource.exist_webresource_dirs
def create_webresource_dirs(endpoint=None): if endpoint is None: endpoint = rdfstore.get_sparql_base_url() from void.views import DataSetStatistics stats = DataSetStatistics(endpoint) specs = stats.get_spec_list(include_deleted=False) created_dirs = 0 logger.info("Start syncing WebResource directories") for spec in specs.keys(): logger.info(spec) from webresource.webresource import WebResource webresource = WebResource(spec=spec) created = webresource.create_dataset_webresource_dirs() if created: created_dirs += 1 logger.info("Finished syncing WebResource directories. Created {}".format(created_dirs))