Exemplo n.º 1
0
 def test_09_detect_provider(self):
     record = {"identifier" : {"id" : "12345"}}
     workflow.detect_provider(record)
     
     # the record should not have changed
     assert not record.has_key('provider')
     
     record['identifier']['type'] = "unknown"
     workflow.detect_provider(record)
     
     # the record should not have changed
     assert not "provider" in record
     
     # check that a plugin is applied
     pdir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "plugins", "test_workflow", "test_09_1")
     plugin.PluginFactory.load_from_directory(plugin_dir=pdir)
     
     record['identifier']['type'] = "doi"
     workflow.detect_provider(record)
     assert "provider" in record, record
     assert "url" in record['provider']
     assert record["provider"]["url"][0] == "http://provider"
     
     # now check that the chain continues all the way to the end
     pdir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "plugins", "test_workflow", "test_09_2")
     plugin.PluginFactory.load_from_directory(plugin_dir=pdir)
     
     del record['provider']
     workflow.detect_provider(record)
     assert "provider" in record
     assert "url" in record['provider']
     assert "http://provider" in record["provider"]["url"]
 def test_08_detect_provider(self):
     record = {"identifier" : {"id" : "12345"}}
     workflow.detect_provider(record)
     
     # the record should not have changed
     assert not record.has_key('provider')
     
     record['identifier']['type'] = "unknown"
     workflow.detect_provider(record)
     
     # the record should not have changed
     assert not "provider" in record
     
     # check that a plugin is applied
     config.provider_detection = {"doi" : ["mock_detect_provider"]}
     record['identifier']['type'] = "doi"
     workflow.detect_provider(record)
     assert "provider" in record, record
     assert "url" in record['provider']
     assert record["provider"]["url"][0] == "http://provider"
     
     # now check that the chain continues all the way to the end
     config.provider_detection = {"doi" : ["mock_no_provider", "mock_other_detect", "mock_detect_provider"]}
     del record['provider']
     workflow.detect_provider(record)
     assert "provider" in record
     assert "url" in record['provider']
     assert record["provider"]["url"][0] == "http://provider"
Exemplo n.º 3
0
 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_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]
Exemplo n.º 5
0
 def test_10_detect_provider_errors(self):
     # Identifier type is none
     record = {"identifier" : {"id" : "12345"}}
     workflow.detect_provider(record)
     assert "error" in record
     
     # detect provider fails
     pdir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "plugins", "test_workflow", "test_10")
     plugin.PluginFactory.load_from_directory(plugin_dir=pdir)
     
     del record["error"]
     record['identifier']['type'] = "doi"
     workflow.detect_provider(record)
     assert "error" in record
     
     # detect provider fails and message object corrupt
     ret = workflow.detect_provider("whatever")
     assert "error" in ret
Exemplo n.º 6
0
 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