Пример #1
0
 def test_taxonomy(self):
     """bibknowledge - test a taxonomy (must run as bibsched user)"""
     import mechanize
     from os import remove
     from invenio.bibknowledge 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_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_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_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_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_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_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)
Пример #2
0
def kb_delete(req, kb, ln=CFG_SITE_LANG, chosen_option=""):
    """
    Deletes an existing kb

    @param kb the kb id to delete
    """
    ln = wash_language(ln)
    _ = gettext_set_language(ln)
    navtrail_previous_links = ''' &gt; <a class="navtrail" href="%s/kb?ln=%s">%s</a> &gt; %s''' % (
        CFG_SITE_SECURE_URL, ln, _("Manage Knowledge Bases"),
        _("Delete Knowledge Base"))

    try:
        dummy = getUid(req)
    except MySQLdb.Error:
        return error_page(req)

    (auth_code, auth_msg) = check_user(req, 'cfgbibknowledge')
    if not auth_code:
        kb_id = wash_url_argument(kb, 'int')
        kb_name = bibknowledge.get_kb_name(kb_id)
        if kb_name is None:
            return page(title=_("Unknown Knowledge Base"),
                        body="",
                        language=ln,
                        navtrail=navtrail_previous_links,
                        errors=[("ERR_KB_ID_UNKNOWN", kb)],
                        lastupdated=__lastupdated__,
                        req=req)

        #Ask confirmation to user if not already done
        chosen_option = wash_url_argument(chosen_option, 'str')
        if chosen_option == "":
            return dialog_box(req=req,
                              ln=ln,
                              title="Delete %s" % kb_name,
                              message="""Are you sure you want to
                              delete knowledge base <i>%s</i>?""" % kb_name,
                              navtrail=navtrail_previous_links,
                              options=[_("Cancel"), _("Delete")])

        elif chosen_option == _("Delete"):
            bibknowledge.delete_kb(kb_name)

        redirect_to_url(req, "kb?ln=%(ln)s" % {'ln': ln})
    else:
        navtrail_previous_links = ''' &gt; <a class="navtrail" href="%s/kb">%s</a>''' % (
            CFG_SITE_SECURE_URL, _("Manage Knowledge Bases"))

        return page_not_authorized(req=req,
                                   text=auth_msg,
                                   navtrail=navtrail_previous_links)
 def test_add_get_remove(self):
     """bibknowledge - test creating a kb, adding a mapping, removing it, removing kb"""
     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_add_get_remove(self):
     """bibknowledge - test creating a kb, adding a mapping, removing it, removing kb"""
     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)
Пример #5
0
def kb_delete(req, kb, ln=CFG_SITE_LANG, chosen_option=""):
    """
    Deletes an existing kb

    @param kb the kb id to delete
    """
    ln = wash_language(ln)
    _ = gettext_set_language(ln)
    navtrail_previous_links = ''' &gt; <a class="navtrail" href="%s/kb?ln=%s">%s</a> &gt; %s''' % (CFG_SITE_SECURE_URL, ln, _("Manage Knowledge Bases"), _("Delete Knowledge Base"))

    try:
        dummy = getUid(req)
    except:
        return error_page('Error', req)

    (auth_code, auth_msg) = check_user(req, 'cfgbibknowledge')
    if not auth_code:
        kb_id = wash_url_argument(kb, 'int')
        kb_name = bibknowledge.get_kb_name(kb_id)
        if kb_name is None:
            return page(title=_("Unknown Knowledge Base"),
                        body = "",
                        language=ln,
                        navtrail = navtrail_previous_links,
                        errors = [("ERR_KB_ID_UNKNOWN", kb)],
                        lastupdated=__lastupdated__,
                        req=req)

        #Ask confirmation to user if not already done
        chosen_option = wash_url_argument(chosen_option, 'str')
        if chosen_option == "":
            return dialog_box(req=req,
                              ln=ln,
                              title="Delete %s" % kb_name,
                              message="""Are you sure you want to
                              delete knowledge base <i>%s</i>?""" % kb_name,
                              navtrail=navtrail_previous_links,
                              options=[_("Cancel"), _("Delete")])

        elif chosen_option==_("Delete"):
            bibknowledge.delete_kb(kb_name)

        redirect_to_url(req, "kb?ln=%(ln)s" % {'ln':ln})
    else:
        navtrail_previous_links = ''' &gt; <a class="navtrail" href="%s/kb">%s</a>''' % (CFG_SITE_SECURE_URL, _("Manage Knowledge Bases"))

        return page_not_authorized(req=req, text=auth_msg,
                                   navtrail=navtrail_previous_links)
 def test_taxonomy(self):
     """bibknowledge - test a taxonomy (must run as bibsched user)"""
     import mechanize
     from os import remove
     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_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_SITE_SECURE_URL + "/youraccount/login")
     browser.select_form(nr=0)
     browser['p_un'] = username
     browser['p_pw'] = password
     browser.submit()
     #go to upload page
     uploadpage = browser.open(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_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_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_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 tearDown(self):
     """bbibknowledge test cleanup"""
     delete_kb(self.dyn_kbname)
 def tearDown(self):
     """bbibknowledge test cleanup"""
     delete_kb(self.dyn_kbname)
Пример #9
0
 def tearDown(self):
     """bbibknowledge test cleanup"""
     from invenio.bibknowledge import delete_kb
     delete_kb(self.dyn_kbname)