def test_13_provider_licence_error(self): pdir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "plugins", "test_workflow", "test_13_1") plugin.PluginFactory.load_from_directory(plugin_dir=pdir) # no provider record = {} ret = workflow.provider_licence(record) print ret assert "error" in ret # no plugin to handle provider pdir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "plugins", "test_workflow", "test_13_2") plugin.PluginFactory.load_from_directory(plugin_dir=pdir) if "error" in record: del record["error"] record['provider'] = {"url" : ["testprovider"]} ret = workflow.provider_licence(record) assert "error" in ret # some error in license detect pdir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "plugins", "test_workflow", "test_13_3") plugin.PluginFactory.load_from_directory(plugin_dir=pdir) if "error" in record: del record["error"] ret = workflow.provider_licence(record) assert "error" in ret # some error in licence detect and record corrupt ret = workflow.detect_provider("whatever") assert "error" in ret
def test_11_provider_licence(self): pdir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "plugins", "test_workflow", "test_11_1") plugin.PluginFactory.load_from_directory(plugin_dir=pdir) # first check that no provider results in no change record = {} workflow.provider_licence(record) assert not record.has_key("bibjson") # now check there's no change if there's no plugin pdir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "plugins", "test_workflow", "test_11_2") plugin.PluginFactory.load_from_directory(plugin_dir=pdir) record = models.MessageObject(record=record) record = record.record assert not record.has_key("bibjson") # check that it works when it's right pdir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "plugins", "test_workflow", "test_11_1") plugin.PluginFactory.load_from_directory(plugin_dir=pdir) record['provider'] = {"url" : ["testprovider"]} workflow.provider_licence(record) assert record.has_key("bibjson") assert record['bibjson'].has_key("license") # american spelling assert len(record['bibjson']['license']) == 1
def test_14_chain(self): global CACHE global ARCHIVE record = {'identifier' : {"id" : "10.1", "type" : "doi", "canonical" : "doi:10.1"}, "queued" : True} config.provider_detection = {"doi" : ["mock_detect_provider"]} config.license_detection = ["mock_licence_plugin"] cache.cache = mock_cache models.Record.store = mock_store # run the chain synchronously record = workflow.detect_provider(record) record = workflow.provider_licence(record) record = workflow.store_results(record) assert "provider" in record assert record["provider"]["url"][0] == "http://provider" assert record.has_key("bibjson") assert record['bibjson'].has_key("license") assert CACHE.has_key("doi:10.1") assert not CACHE["doi:10.1"].has_key("queued") assert len(ARCHIVE) == 1 assert ARCHIVE[0]["title"] == "mytitle" del CACHE['doi:10.1'] del ARCHIVE[0]
def test_11_provider_unknown_licence(self): config.license_detection = ["mock_unknown_licence_plugin"] # check that it works when it's right record = {} record['provider'] = {"url" : ["testprovider"]} workflow.provider_licence(record) # mock_unknown_plugin runs but does not provide us with a licence, # but nonetheless, we expect an unknown licence to exist assert record.has_key("bibjson") assert record['bibjson'].has_key("license") # american spelling assert len(record['bibjson']['license']) == 1 licence = record['bibjson']['license'][0] assert licence['url'] == config.unknown_url, (licence['url'], config.unknown_url) assert licence["type"] == "failed-to-obtain-license" assert licence['provenance']['handler'] == "test_workflow", licence['provenance']['handler'] assert licence['provenance']['handler_version'] == "1.0", licence['provenance']['handler_version']
def test_12_provider_unknown_licence(self): pdir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "plugins", "test_workflow", "test_12") plugin.PluginFactory.load_from_directory(plugin_dir=pdir) # check that it works when it's right record = {} record['provider'] = {"url" : ["testprovider"]} workflow.provider_licence(record) # mock_unknown_plugin runs but does not provide us with a licence, # but nonetheless, we expect an unknown licence to exist assert record.has_key("bibjson") assert record['bibjson'].has_key("license") # american spelling assert len(record['bibjson']['license']) == 1 licence = record['bibjson']['license'][0] assert licence['url'] == config.unknown_url, (licence['url'], config.unknown_url) assert licence["type"] == "failed-to-obtain-license" assert licence['provenance']['handler'] == "test_workflow", licence['provenance']['handler'] assert licence['provenance']['handler_version'] == "1.0", licence['provenance']['handler_version']
def test_18_provider_licence_was_licences(self): pdir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "plugins", "test_workflow", "test_18") plugin.PluginFactory.load_from_directory(plugin_dir=pdir) record = { 'provider' : {"url" : ["testprovider"]}, "bibjson" : { "license" : [ {"title" : "l1"} ] } } record = models.MessageObject(record=record) record = record.prep_for_backend() # check that it works when it's right workflow.provider_licence(record) # mock_unknown_plugin runs but does not provide us with a licence, # but because there was a licence initially, we expect there not to have been one added assert not record.has_key("bibjson")
def test_17_chain(self): global CACHE global ARCHIVE record = { 'identifier' : {"id" : "10.1", "type" : "doi", "canonical" : "doi:10.1"}, "queued" : True, "bibjson" : { "license" : [ {"title" : "l1"} ] } } record = models.MessageObject(record=record) record = record.prep_for_backend() # check that this sets up the chainable object correctly assert record.get("licensed", False) assert "bibjson" not in record pdir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "plugins", "test_workflow", "test_17") plugin.PluginFactory.load_from_directory(plugin_dir=pdir) cache.cache = mock_cache models.Record.store = mock_store old_check_archive = workflow._check_archive workflow._check_archive = lambda x: {"license" : [{"title" : "l1"}]} # run the chain synchronously record = workflow.detect_provider(record) record = workflow.provider_licence(record) record = workflow.store_results(record) assert "provider" in record assert record["provider"]["url"][0] == "http://provider" assert record.has_key("bibjson") assert record['bibjson'].has_key("license") assert len(record["bibjson"]["license"]) == 2, ARCHIVE # should have picked up the archive copy assert CACHE.has_key("doi:10.1") assert not CACHE["doi:10.1"].get("queued", False) assert len(ARCHIVE) == 1, len(ARCHIVE) assert ARCHIVE[0]["license"][0]["title"] == "mytitle" assert ARCHIVE[0]["license"][1]["title"] == "l1" del CACHE['doi:10.1'] del ARCHIVE[:] workflow._check_archive = old_check_archive
def test_10_provider_licence(self): config.license_detection = ["mock_licence_plugin"] # first check that no provider results in no change record = {} workflow.provider_licence(record) assert not record.has_key("bibjson") # now check there's no change if there's no plugin mock_licence_plugin.sup = False record['provider'] = {"url" : ["provider"]} workflow.provider_licence(record) assert not record.has_key("bibjson") # check that it works when it's right mock_licence_plugin.sup = True record['provider'] = {"url" : ["testprovider"]} workflow.provider_licence(record) assert record.has_key("bibjson") assert record['bibjson'].has_key("license") # american spelling assert len(record['bibjson']['license']) == 1