def setUp(self): """Setup tests.""" from invenio_knowledge.api import add_kb from inspire.modules.workflows.receivers import precache_holdingpen_row from invenio_workflows.receivers import index_holdingpen_record from invenio_workflows.signals import ( workflow_halted, workflow_object_saved ) # Disable the holdingpen caching receiver. workflow_halted.disconnect(precache_holdingpen_row) workflow_object_saved.disconnect(index_holdingpen_record) self.create_registries() self.record_oai_arxiv_plots = pkg_resources.resource_string( 'inspire.testsuite', os.path.join( 'workflows', 'fixtures', 'oai_arxiv_record_with_plots.xml' ) ) self.some_record = pkg_resources.resource_string( 'inspire.testsuite', os.path.join( 'workflows', 'fixtures', 'some_record.xml' ) ) self.arxiv_tarball = pkg_resources.resource_stream( 'inspire.testsuite', os.path.join( 'workflows', 'fixtures', '1407.7587v1' ) ) self.arxiv_pdf = pkg_resources.resource_stream( 'inspire.testsuite', os.path.join( 'workflows', 'fixtures', '1407.7587v1.pdf' ) ) # Add temp KB add_kb('harvesting_fixture_kb')
def test_taxonomy(self): """bibknowledge - test a taxonomy (must run as bibsched user)""" import mechanize from os import remove from invenio_knowledge.api import get_kbt_items_for_bibedit, add_kb, \ get_kb_name, delete_kb, kb_exists username = "******" password = "******" #create a new taxonomy kb new_kb_id = add_kb("testtaxonomy", "taxonomy") #what was the name? new_kb_name = get_kb_name(new_kb_id) #get the taxonomy file response = mechanize.urlopen( "http://invenio-software.org/download/invenio-demo-site-files/HEP.rdf" ) content = response.read() f = open(cfg['CFG_TMPDIR'] + "/HEP.rdf", "w") f.write(content) f.close() #upload it to the right destination, but log in first browser = mechanize.Browser() browser.open(cfg['CFG_SITE_SECURE_URL'] + "/youraccount/login") browser.select_form(nr=0) browser['nickname'] = username browser['password'] = password browser.submit() #go to upload page uploadpage = browser.open(cfg['CFG_SITE_URL'] + "/kb?kb=" + str(new_kb_id)) #check that we are there content = uploadpage.read() namethere = content.count("testtaxonomy") assert namethere > 0 #upload browser.open(cfg['CFG_SITE_URL'] + "/kb?kb=" + str(new_kb_id)) browser.select_form(name="upload") browser.form["kb"] = str(new_kb_id) #force the id browser.form.add_file(open(cfg['CFG_TMPDIR'] + "/HEP.rdf"), content_type='text/plain', filename="HEP.rdf", name="file") browser.submit() #check that we can get an item from the kb items = get_kbt_items_for_bibedit(new_kb_name, "prefLabel", "Altarelli") #item should contain 1 string: 'Altarelli-Parisi equation' self.assertEqual(1, len(items)) #delete the temp file remove(cfg['CFG_TMPDIR'] + "/HEP.rdf") #delete the test odf the DB delete_kb(new_kb_name) still_there = kb_exists(new_kb_name) self.assertEqual(False, still_there)
def test_add_get_remove(self): """bibknowledge - test creating a kb, adding a mapping, removing it, removing kb""" from invenio_knowledge.api import add_kb, get_kb_name, \ kb_mapping_exists, remove_kb_mapping, delete_kb, kb_exists, \ add_kb_mapping new_kb_id = add_kb() new_name = get_kb_name(new_kb_id) add_kb_mapping(new_name, "foobar", "barfoo") fbexists = kb_mapping_exists(new_name, "foobar") self.assertEqual(True, fbexists) remove_kb_mapping(new_name, "foobar") fbexists = kb_mapping_exists(new_name, "foobar") self.assertEqual(False, fbexists) delete_kb(new_name) still_there = kb_exists(new_name) self.assertEqual(False, still_there)
def test_taxonomy(self): """bibknowledge - test a taxonomy (must run as bibsched user)""" import mechanize from os import remove from invenio_knowledge.api import get_kbt_items_for_bibedit, add_kb, \ get_kb_name, delete_kb, kb_exists username = "******" password = "******" #create a new taxonomy kb new_kb_id = add_kb("testtaxonomy","taxonomy") #what was the name? new_kb_name = get_kb_name(new_kb_id) #get the taxonomy file response = mechanize.urlopen("http://inveniosoftware.org/download/invenio-demo-site-files/HEP.rdf") content = response.read() f = open(cfg['CFG_TMPDIR']+"/HEP.rdf","w") f.write(content) f.close() #upload it to the right destination, but log in first browser = mechanize.Browser() browser.open(cfg['CFG_SITE_SECURE_URL'] + "/youraccount/login") browser.select_form(nr=0) browser['nickname'] = username browser['password'] = password browser.submit() #go to upload page uploadpage = browser.open(cfg['CFG_SITE_URL']+"/kb?kb="+str(new_kb_id)) #check that we are there content = uploadpage.read() namethere = content.count("testtaxonomy") assert namethere > 0 #upload browser.open(cfg['CFG_SITE_URL']+"/kb?kb="+str(new_kb_id)) browser.select_form(name="upload") browser.form["kb"] = str(new_kb_id) #force the id browser.form.add_file(open(cfg['CFG_TMPDIR']+"/HEP.rdf"), content_type='text/plain', filename="HEP.rdf", name="file") browser.submit() #check that we can get an item from the kb items = get_kbt_items_for_bibedit(new_kb_name, "prefLabel", "Altarelli") #item should contain 1 string: 'Altarelli-Parisi equation' self.assertEqual(1, len(items)) #delete the temp file remove(cfg['CFG_TMPDIR']+"/HEP.rdf") #delete the test odf the DB delete_kb(new_kb_name) still_there = kb_exists(new_kb_name) self.assertEqual(False, still_there)