Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setUp(self):
Community.query.delete()
self.login('admin', '')
uid = current_user.get_id()
data = {'id': self.test_name,
'title': self.test_name}
self.c = Community(id_user=uid, **data)
db.session.add(self.c)
db.session.commit()
self.c.save_collections()
def insert_submission_dump(dump):
"""Helper function to insert submisson dump via run_sql()"""
for sql_statement in dump.replace(r'\"', '"').splitlines():
if sql_statement:
run_sql(sql_statement)
def make_url(path, **kargs):
""" Helper to generate an absolute invenio URL with query
arguments"""
url = CFG_SITE_URL + path
if kargs:
url += '?' + urlencode(kargs, doseq=True)
return url
def test_get_all_linkbacks1(self):
"""weblinkback - get all linkbacks for lnkENTRY and with a certain status"""
self.assertEqual(0, len(get_all_linkbacks(recid=5, status=CFG_WEBLINKBACK_STATUS['PENDING'])))
self.assertEqual(4, len(get_all_linkbacks(recid=41, status=CFG_WEBLINKBACK_STATUS['PENDING'])))
self.assertEqual(0, len(get_all_linkbacks(recid=41, status=CFG_WEBLINKBACK_STATUS['INSERTED'])))
self.assertEqual(5, len(get_all_linkbacks(recid=42, status=CFG_WEBLINKBACK_STATUS['PENDING'])))
self.assertEqual(0, len(get_all_linkbacks(recid=42, status=CFG_WEBLINKBACK_STATUS['APPROVED'])))
url = CFG_SITE_URL + '/%s/41/linkbacks/' % CFG_SITE_RECORD
expected_texts = ('Linkbacks to review: 4', 'Linkbacks: 0', 'URL1', 'URL2', 'URL3', 'URL4')
for text in expected_texts:
self.assertEqual([], test_web_page_content(url,
username='admin',
expected_text=text))
url = CFG_SITE_URL + '/%s/42/linkbacks/' % CFG_SITE_RECORD
expected_texts = ('Linkbacks to review: 5', 'Linkbacks: 0', 'URL5', 'URL6', 'URL7', 'URL8', 'URL1')
for text in expected_texts:
self.assertEqual([], test_web_page_content(url,
username='admin',
expected_text=text))
def test_websearch_admin_interface_pages_availability(self):
"""websearchadmin - availability of WebSearch Admin interface pages"""
baseurl = CFG_SITE_URL + '/admin/websearch/websearchadmin.py'
_exports = ['',
'?mtype=perform_showall',
'?mtype=perform_addcollection',
'?mtype=perform_addcollectiontotree',
'?mtype=perform_modifycollectiontree',
'?mtype=perform_checkwebcollstatus',
'?mtype=perform_checkcollectionstatus',]
error_messages = []
for url in [baseurl + page for page in _exports]:
# first try as guest:
error_messages.extend(test_web_page_content(url,
username='guest',
expected_text=
'Authorization failure'))
def setUp(self):
setup_loggers(verbosity=1)
def test_identify_ibids_empty(self):
from invenio.legacy.refextract.tag import identify_ibids
r = identify_ibids("")
self.assertEqual(r, ({}, ''))
def test_identify_ibids_simple(self):
from invenio.legacy.refextract.tag import identify_ibids
ref_line = u"""[46] E. Schrodinger, Sitzungsber. Preuss. Akad. Wiss. Phys. Math. Kl. 24, 418(1930); ibid, 3, 1(1931)"""
r = identify_ibids(ref_line.upper())
self.assertEqual(r, ({85: u'IBID'}, u'[46] E. SCHRODINGER, SITZUNGSBER. PREUSS. AKAD. WISS. PHYS. MATH. KL. 24, 418(1930); ____, 3, 1(1931)'))
class FindNumerationTest(InvenioTestCase):
def setUp(self):
setup_loggers(verbosity=1)
def test_vol_page_year(self):
", ()"
from invenio.legacy.refextract.tag import find_numeration
ref_line = u"""24, 418 (1930)"""
r = find_numeration(ref_line)
self.assertEqual(r['volume'], u"24")
self.assertEqual(r['year'], u"1930")
self.assertEqual(r['page'], u"418")
def test_vol_year_page(self):
", () "
from invenio.legacy.refextract.tag import find_numeration
ref_line = u"""24, (1930) 418"""
TestUpgrade('5', ['3', '4'], 'invenio'),
TestUpgrade('6', ['5', ], 'invenio'),
])
history = dictify(['1', '2', '4'], value=1)
m = InvenioUpgrader()
self.assertEqual(upgrades_str(m.order_upgrades(upgrades, history)),
"[3, 5, 6]")
history = dictify(['3', '5'], value=1)
m = InvenioUpgrader()
self.assertEqual(
upgrades_str(m.order_upgrades(upgrades, history)), "[6]")
class TestInvenioUpgraderRecipe(InvenioTestCase):
def setUp(self):
"""
Setup a test python package, to test upgrade recipe creation.
"""
self.tmpdir = tempfile.mkdtemp()
self.pkg_path = os.path.join(self.tmpdir, 'invenio_upgrader_test')
os.makedirs(self.pkg_path)
open(os.path.join(self.pkg_path, '__init__.py'), 'a').close()
self.pkg_path_mymod = os.path.join(
self.tmpdir, 'invenio_upgrader_test/mymod'
)
os.makedirs(self.pkg_path_mymod)
open(os.path.join(self.pkg_path, '__init__.py'), 'a').close()
open(os.path.join(self.pkg_path_mymod, '__init__.py'), 'a').close()
def test_search_results_ranked_by_citations_verbose(self):
"""bibrank - search results ranked by number of citations, verbose output"""
#FIXME verbose is not supported in jinja2 templates
self.assertEqual([],
test_web_page_content(CFG_SITE_URL + '/search?cc=Articles+%26+Preprints&p=Klebanov&rm=citation&verbose=2',
username="admin",
expected_text="find_citations retlist [[85, 0], [77, 2], [84, 3]]"))
def test_detailed_record_citations_tab(self):
"""bibrank - detailed record, citations tab"""
self.assertEqual([],
test_web_page_content(CFG_SITE_URL + '/'+ CFG_SITE_RECORD +'/79/citations',
expected_text=["Cited by: 1 records",
"Co-cited with: 2 records"]))
class BibRankExtCitesTest(InvenioTestCase):
"""Check BibRank citation ranking tools with respect to the external cites."""
def _detect_extcite_info(self, extcitepubinfo):
"""
Helper function to return list of recIDs citing given
extcitepubinfo. Could be move to the business logic, if
interesting for other callers.
"""
res = run_sql("""SELECT id_bibrec FROM rnkCITATIONDATAEXT
WHERE extcitepubinfo=%s""",
(extcitepubinfo,))
return [int(x[0]) for x in res]
def test_extcite_via_report_number(self):
"""bibrank - external cites, via report number"""
# The external paper hep-th/0112258 is cited by 9 demo
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Invenio; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
""" Test unit for the miscutil/errorlib module. """
__revision__ = "$Id$"
import datetime
from invenio.testsuite import make_test_suite, run_test_suite, InvenioTestCase
class TestGetEmergencyRecipients(InvenioTestCase):
def test_get_emergency_recipients(self):
"""errorlib - test return of proper set of recipients"""
from invenio.legacy.bibsched.cli import get_emergency_recipients
now = datetime.datetime(year=2000, month=1, day=20,
hour=14, minute=0)
tomorrow = now + datetime.timedelta(days=1)
diff_day = now + datetime.timedelta(days=4)
later = now.replace(hour=(now.hour + 1) % 24)
earlier = now.replace(hour=(now.hour - 1) % 24)
constraint_now = "%s %s-%s" % (
now.strftime("%a"),
earlier.strftime("%H:00"),
later.strftime("%H:00"),
)
from invenio.legacy.bibsword.client_http import RemoteSwordServer
from invenio.legacy.bibsword.client_dblayer import get_remote_server_auth, \
insert_into_swr_clientdata, \
update_submission_status, \
select_submitted_record_infos, \
delete_from_swr_clientdata
from invenio.legacy.dbquery import run_sql
from invenio.legacy.bibsword.config import CFG_SUBMISSION_STATUS_SUBMITTED, \
CFG_SUBMISSION_STATUS_PUBLISHED, \
CFG_SUBMISSION_STATUS_REMOVED
from xml.dom import minidom
TEST_DATA = pkg_resources.resource_filename('invenio.legacy.bibsword', 'data')
class Test_format_marcxml_file(InvenioTestCase):
""" bibsword_format - test the parsing and extracting of marcxml nodes"""
def test_extract_marcxml_1(self):
"""Test_format_marcxml_file - extract marcxml without id, report_nos and comment"""
# Test with marcxml file 1
marcxml = open("%s%sTest_marcxml_file_1.xml" % (TEST_DATA, os.sep)).read()
metadata = format_marcxml_file(marcxml)
self.assertEqual(metadata['id'], '')
self.assertEqual(metadata['title'], "Calorimetry triggering in ATLAS")
self.assertEqual(metadata['contributors'][0]['name'], "Igonkina, O")
self.assertEqual(metadata['contributors'][0]['affiliation'][0], "NIKHEF, Amsterdam")
self.assertEqual(metadata['summary'], "The ATLAS experiment is preparing for data taking at 14 TeV collision energy. A rich discovery physics program is being prepared in addition to the detailed study of Standard Model processes which will be produced in abundance. The ATLAS multi-level trigger system is designed to accept one event in 2 105 to enable the selection of rare and unusual physics events. The ATLAS calorimeter system is a precise instrument, which includes liquid Argon electro-magnetic and hadronic components as well as a scintillator-tile hadronic calorimeter. All these components are used in the various levels of the trigger system. A wide physics coverage is ensured by inclusively selecting events with candidate electrons, photons, taus, jets or those with large missing transverse energy. The commissioning of the trigger system is being performed with cosmic ray events and by replaying simulated Monte Carlo events through the trigger and data acquisition system.")
self.assertEqual(metadata['contributors'][1]['name'], "Achenbach, R")
self.assertEqual(metadata['contributors'][1]['affiliation'][0], "Kirchhoff Inst. Phys.")
self.assertEqual(metadata['contributors'][2]['name'], "Adragna, P")
self.assertEqual(metadata['contributors'][2]['affiliation'][0], "Queen Mary, U. of London")