Beispiel #1
0
 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)
Beispiel #2
0
 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)
Beispiel #4
0
 def test_EJOURNALS_exists(self):
     """bibknowledge - test that EJOURNALS kb is there"""
     from invenio_knowledge.api import kb_exists
     isthere = kb_exists("EJOURNALS")
     self.assertEqual(True, isthere)