def setUp(self):
        # pylint: disable=C0103
        """Initialize stuff"""
        self.recid = 339705
        self.recids = [339705, 339706]
        self.rank_method_code = 'citation'

    def xtest_init_cited_by_dictionary(self):
        """bibrank citation searcher - init cited-by data"""
        # FIXME: test postponed
        #self.assert_(bibrank_citation_searcher.init_cited_by_dictionary())

    def xtest_init_reference_list_dictionary(self):
        """bibrank citation searcher - init reference data"""
        # FIXME: test postponed
        #self.assert_(bibrank_citation_searcher.init_reference_list_dictionary())

    def xtest_calculate_cited_by_list(self):
        """bibrank citation searcher - get citing relevance"""
        # FIXME: test postponed

    def xtest_calculate_co_cited_with_list(self):
        """bibrank citation searcher - get co-cited-with data"""
        # FIXME: test postponed

TEST_SUITE = make_test_suite(TestCitationSearcher,)

if __name__ == "__main__":
    run_test_suite(TEST_SUITE)

Example #2
0
            result = transform('<lang:current />', languages=[CFG_SITE_LANG])
            self.assertEqual(result[0][1], CFG_SITE_LANG)

            # ?ln=.. is returned only if not CFG_SITE_LANG
            result = transform('<lang:link />', languages=[CFG_SITE_LANG])
            self.assertEqual(result[0][1], '')

            result = transform('<lang:link />', languages=['fr'])
            self.assertEqual(result[0][1], '?ln=fr')

class WebDocCommentsFiltering(unittest.TestCase):
    """Check that comments are correctly removed from webdoc files"""

    if lang_english_configured:
        def test_comments_filtering(self):
            """webdoc - removing comments"""
            result = transform('''# -*- coding: utf-8 -*-
    ## $Id$
    ##''',
                               languages=[CFG_SITE_LANG])

            self.assertEqual(result[0][1], '')

TEST_SUITE = make_test_suite(WebDocLanguageTest,
                             WebDocPartsTest,
                             WebDocVariableReplacementTest,
                             WebDocCommentsFiltering,)

if __name__ == "__main__":
    run_test_suite(TEST_SUITE)
                                  expected_text="ISBN: 2225350574"))


class BibFormatPublInfoFormattingTest(unittest.TestCase):
    """Check publication reference info formatting produced by BibFormat."""
    def test_publinfo_in_html_brief(self):
        """bibformat - publication reference info in HTML brief formats"""
        self.assertEqual(
            [],
            test_web_page_content(
                CFG_SITE_URL + '/search?p=recid%3A84',
                expected_text="Nucl. Phys. B: 656 (2003) pp. 23-36"))

    def test_publinfo_in_html_detailed(self):
        """bibformat - publication reference info in HTML detailed formats"""
        self.assertEqual(
            [],
            test_web_page_content(
                CFG_SITE_URL + '/%s/84' % CFG_SITE_RECORD,
                expected_text="Nucl. Phys. B: 656 (2003) pp. 23-36"))


TEST_SUITE = make_test_suite(
    BibFormatBibTeXTest, BibFormatDetailedHTMLTest, BibFormatBriefHTMLTest,
    BibFormatNLMTest, BibFormatMARCTest, BibFormatMARCXMLTest,
    BibFormatAPITest, BibFormatObjectAPITest, BibFormatTitleFormattingTest,
    BibFormatISBNFormattingTest, BibFormatPublInfoFormattingTest)

if __name__ == "__main__":
    run_test_suite(TEST_SUITE, warn_user=True)
from invenio.testutils import make_test_suite, run_test_suite

class TestListSetOperations(unittest.TestCase):
    """Test list set operations."""

    def test_uniq(self):
        """bibrank downloads indexer - uniq function"""
        self.assertEqual([1, 2, 3], bibrank_downloads_indexer.uniq([1, 2, 3, 3, 3, 2]))

    def test_database_tuples_to_single_list(self):
        """bibrank downloads indexer - database tuples to list"""
        self.assertEqual([1, 2, 3], bibrank_downloads_indexer.database_tuples_to_single_list(((1,), (2,), (3,))))

class TestMergeDictionnaries(unittest.TestCase):
    """Test bibrank_downloads_indexer merge 2 dictionnaries"""

    def test_merge_with_old_dictionnary(self):
        """bibrank downloads indexer - merging with old dictionary"""
        self.assertEqual({1:[(2, 3)], 2:[(3, 4)], 3:[(4, 5)]}, bibrank_downloads_indexer.merge_with_old_dictionnary(\
            {3:[(4, 5)]}, {1:[(2, 3)], 2:[(3, 4)]}))
        self.assertEqual({1:[(2, 4)], 2:[(3, 4)]}, bibrank_downloads_indexer.merge_with_old_dictionnary(\
            {1:[(2, 1)]}, {1:[(2, 3)], 2:[(3, 4)]}))
        self.assertEqual({1:[(3, 3), (2, 3)], 2:[(3, 4)]}, bibrank_downloads_indexer.merge_with_old_dictionnary(\
            {1:[(2, 3)]}, {1:[(3, 3)], 2:[(3, 4)]}))
        self.assertEqual({}, bibrank_downloads_indexer.merge_with_old_dictionnary({}, {}))

TEST_SUITE = make_test_suite(TestListSetOperations,
                             TestMergeDictionnaries,)
if __name__ == "__main__":
    run_test_suite(TEST_SUITE)
        expected = [
            '>>> Following upgrade(s) are ready to be applied:',
            '>>> All upgrades have been applied.'
        ]
        self.assertTrue(expected[0] in lines or expected[1] in lines,
                        "%s was not found in output %s" % (expected, lines))

    def test_cmd_get(self):
        """ Test --get cmd """
        # New way of calling get
        self.capture()
        main('--conf-dir', '%s/etc/' % CFG_PREFIX, '--get=CFG_PREFIX')
        self.assertEqual('%s\n' % CFG_PREFIX, self.output.getvalue())

        # Old way of calling get
        self.capture()
        main('--conf-dir=%s/etc/' % CFG_PREFIX, '--get', 'CFG_PREFIX')
        self.assertEqual("%s\n" % CFG_PREFIX, self.output.getvalue())

        # Missing option value
        self.capture()
        self.assertExitValue(2, main, '--conf-dir', "%s/etc/" % CFG_PREFIX,
                             '--get')
        self.stop_capture()


TEST_SUITE = make_test_suite(InveniocfgTest)

if __name__ == "__main__":
    run_test_suite(TEST_SUITE)
Example #6
0
        self.failIf('PID != PGID' in stdout, 'PID != PGID was found in current output: %s (%s)' % (stdout, stderr))
        self.failUnless('PID == PGID' in stdout, 'PID == PGID wasn\'t found in current output: %s (%s)' % (stdout, stderr))

    def test_run_cmd_viasudo_no_password(self):
        """shellutils - running simple command via sudo should not wait for password"""
        exitstatus, stdout, stderr = run_process_with_timeout([self.script_path, '5'], timeout=10, sudo='foo')
        self.assertNotEqual(exitstatus, 0)


class SplitIdsTest(InvenioTestCase):
    def test_one(self):
        self.assertEqual(split_cli_ids_arg("1"), set([1]))

    def test_range(self):
        self.assertEqual(split_cli_ids_arg("1-5"), set([1, 2, 3, 4, 5]))

    def test_multiple(self):
        self.assertEqual(split_cli_ids_arg("1,5,7"), set([1, 5, 7]))

    def test_complex(self):
        self.assertEqual(split_cli_ids_arg("1-1,7,10-11,4"), set([1, 4, 7, 10, 11]))


TEST_SUITE = make_test_suite(EscapeShellArgTest,
                             RunShellCommandTest,
                             RunProcessWithTimeoutTest,
                             SplitIdsTest)

if __name__ == "__main__":
    run_test_suite(TEST_SUITE)
        from invenio.dbquery import connect
        kwargs = {'host': 'foo', 'port': 999, 'db': 'baz', 'user': '******', 'passwd': '123', 'use_unicode': False, 'charset': 'utf8'}
        try:
            connect(**kwargs)
        except:
            output = get_pretty_traceback(exc_info=sys.exc_info(), force_stack=True)
        self.failIf('123' in output, output)
        self.failUnless('<*****>' in output, output)

    def test_nested_password_hiding(self):
        """errorlib - hide password nested in dictionary in frame analysis"""
        try:
            foo = {
                'bar' : 'baz',
                'qoox' : {
                    'blibpwdblob' : '1234'
                }
            }
            int(foo)
        except:
            output = get_pretty_traceback(exc_info=sys.exc_info(), force_stack=True)
        self.failIf('1234' in output, output)
        self.failUnless('<*****>' in output, output)


TEST_SUITE = make_test_suite(ErrorlibWebPagesAvailabilityTest,
                             ErrorlibRegisterExceptionTest)

if __name__ == "__main__":
    run_test_suite(TEST_SUITE, warn_user=True)
                  <subfield code="l">00</subfield>
                  <subfield code="m">2002-04-12</subfield>
                  <subfield code="o">BATCH</subfield>
                </datafield>
                <datafield tag="909" ind1="C" ind2="S">
                  <subfield code="s">m</subfield>
                  <subfield code="w">198604</subfield>
                </datafield>
                <datafield tag="980" ind1=" " ind2=" ">
                  <subfield code="a">BOOK</subfield>
                </datafield>
              </record>
              """
        reader = MarcReader(blob=xml, schema="xml")
        r = Record(reader.translate())

        r.check_record(reset = True)
        self.assertTrue('title' in r)
        self.assertEquals(len(r['title']), 2)
        self.assertEquals(len(r.fatal_errors), 1)

        r['title'] = r['title'][0]
        r.check_record(reset = True)
        self.assertEquals(len(r.fatal_errors), 0)

TEST_SUITE = make_test_suite(BibFieldMarcReaderMarcXML,
                             BibFieldCheckRecord)

if __name__ == "__main__":
    run_test_suite(TEST_SUITE)
Example #9
0
import os

from invenio.config import CFG_TMPDIR, CFG_SITE_URL
from invenio.testutils import make_test_suite, run_test_suite, InvenioTestCase


class GetDefaultsTest(InvenioTestCase):
    """Test function to get default values."""
    def setUp(self):
        self.arXiv_id = "arXiv:astro-ph_0104076"
        self.tarball = "%s/2001/04/arXiv:astro-ph_0104076/arXiv:astro-ph_0104076" % (CFG_TMPDIR,)

    def test_get_defaults(self):
        """plotextractor - get defaults"""
        from invenio.shellutils import run_shell_command
        from invenio.plotextractor import get_defaults
        sdir_should_be = os.path.join(CFG_TMPDIR, self.arXiv_id + '_plots')
        refno_should_be = "15" # Note: For ATLANTIS DEMO site
        sdir, refno = get_defaults(tarball=self.tarball, sdir=None, refno_url=CFG_SITE_URL)
        if sdir != None:
            run_shell_command("rm -rf %s" % (sdir,))
        self.assertTrue(sdir == sdir_should_be, \
                         "didn\'t get correct default scratch dir")
        self.assertTrue(refno == refno_should_be, \
                         'didn\'t get correct default reference number')

TEST_SUITE = make_test_suite(GetDefaultsTest)

if __name__ == "__main__":
    run_test_suite(TEST_SUITE, warn_user=True)
Example #10
0
    def test_5_digits_version_new(self):
        ref_line = u"""{any prefix}1310.12345v9{any postfix}"""
        r = tag_arxiv(ref_line)
        self.assertEqual(
            r.strip(': '),
            u"{any prefix}<cds.REPORTNUMBER>arXiv:1310.12345</cds.REPORTNUMBER>{any postfix}"
        )

    def test_5_digits_suffix_version_new(self):
        ref_line = u"""{any prefix}1310.12345v9 [physics.ins-det]{any postfix}"""
        r = tag_arxiv(ref_line)
        self.assertEqual(
            r.strip(': '),
            u"{any prefix}<cds.REPORTNUMBER>arXiv:1310.12345 [physics.ins-det]</cds.REPORTNUMBER>{any postfix}"
        )

    def test_5_digits_suffix_version_new_2012(self):
        ref_line = u"""{any prefix}1210.12345v9 [physics.ins-det]{any postfix}"""
        r = tag_arxiv(ref_line)
        self.assertEqual(
            r.strip(': '),
            u"{any prefix}1210.12345v9 [physics.ins-det]{any postfix}")


TEST_SUITE = make_test_suite(ReTest, IbidTest, FindNumerationTest,
                             FindSectionTest, SearchTest,
                             RebuildReferencesTest)

if __name__ == '__main__':
    run_test_suite(TEST_SUITE)
        self.assertRaises(InvenioConnectorAuthError, server.search,
                          **search_params)

        server = InvenioConnector(CFG_SITE_SECURE_URL,
                                  user='******',
                                  password='',
                                  insecure_login=True)
        result = server.search(p='LBL-28106', c=['Theses'], of='id')
        self.assertTrue(len(result) > 0, \
                        'did not get restricted collection search results.')

    def test_search_remote_restricted_collections(self):
        """InvenioConnector - remote restricted collection search"""
        server = InvenioConnector("http://invenio-demo.cern.ch")
        search_params = dict(p='LBL-28106', c=['Theses'], of='id')
        self.assertRaises(InvenioConnectorAuthError, server.search,
                          **search_params)

        server = InvenioConnector("https://invenio-demo.cern.ch",
                                  user='******',
                                  password='******')
        result = server.search(p='LBL-28106', c=['Theses'], of='id')
        self.assertTrue(len(result) > 0, \
                        'did not get restricted collection search results.')


TEST_SUITE = make_test_suite(InvenioConnectorTest)

if __name__ == "__main__":
    run_test_suite(TEST_SUITE, warn_user=True)
        self.assertEqual(wrap_text_in_a_box(text), result)

class DecodeToUnicodeTest(unittest.TestCase):
    """Test functions related to decode_to_unicode function."""

    if CHARDET_AVAILABLE:
        def test_decode_to_unicode(self):
            """textutils - decode_to_unicode."""
            self.assertEqual(decode_to_unicode('\202\203\204\205', failover_encoding='latin1'), u'\x82\x83\x84\x85')
            self.assertEqual(decode_to_unicode('àèéìòù'), u'\xe0\xe8\xe9\xec\xf2\xf9')
            self.assertEqual(decode_to_unicode('Ιθάκη'), u'\u0399\u03b8\u03ac\u03ba\u03b7')

class Latex2UnicodeTest(unittest.TestCase):
    """Test functions related to translating LaTeX symbols to Unicode."""

    if CHARDET_AVAILABLE:
        def test_latex_to_unicode(self):
            """textutils - latex_to_unicode"""
            self.assertEqual(translate_latex2unicode("\\'a \\'i \\'U").encode('utf-8'), "á í Ú")
            self.assertEqual(translate_latex2unicode("\\'N \\k{i}"), u'\u0143 \u012f')
            self.assertEqual(translate_latex2unicode("\\AAkeson"), u'\u212bkeson')
            self.assertEqual(translate_latex2unicode("$\\mathsl{\\Zeta}$"), u'\U0001d6e7')

TEST_SUITE = make_test_suite(WrapTextInABoxTest, GuessMinimumEncodingTest,
                             WashForXMLTest, WashForUTF8Test, DecodeToUnicodeTest,
                             Latex2UnicodeTest)

if __name__ == "__main__":
    run_test_suite(TEST_SUITE)

It requires a fully functional invenio installation.
"""

from invenio.testutils import InvenioTestCase

from invenio.testutils import make_test_suite, run_test_suite
from invenio.refextract_api import update_references, RecordHasReferences, FullTextNotAvailable


class RefextractApiTest(InvenioTestCase):
    def test_no_fulltext(self):
        try:
            update_references(2000000)
            self.fail()
        except FullTextNotAvailable:
            # As expected
            pass

    def test_no_overwrite(self):
        try:
            update_references(92, overwrite=False)
            self.fail()
        except RecordHasReferences:
            # As expected
            pass


TEST_SUITE = make_test_suite(RefextractApiTest)
if __name__ == "__main__":
    run_test_suite(TEST_SUITE)
    """Tests for getting family name words from author names."""

    def test_authornames_john_doe(self):
        """bibindex engine - get author family name words for John Doe"""
        tokenizer = _TOKENIZERS["BibIndexAuthorTokenizer"]()
        self.assertEqual(['doe',],
                         tokenizer.get_author_family_name_words_from_phrase('John Doe'))

    def test_authornames_doe_john(self):
        """bibindex engine - get author family name words for Doe, John"""
        tokenizer = _TOKENIZERS["BibIndexAuthorTokenizer"]()
        self.assertEqual(['doe',],
                         tokenizer.get_author_family_name_words_from_phrase('Doe, John'))

    def test_authornames_campbell_wilson(self):
        """bibindex engine - get author family name words for Campbell-Wilson, D"""
        tokenizer = _TOKENIZERS["BibIndexAuthorTokenizer"]()
        self.assertEqual(['campbell', 'wilson', 'campbell-wilson'],
                         tokenizer.get_author_family_name_words_from_phrase('Campbell-Wilson, D'))


TEST_SUITE = make_test_suite(TestListSetOperations,
                             TestWashIndexTerm,
                             TestGetWordsFromPhrase,
                             TestGetPairsFromPhrase,
                             TestGetWordsFromDateTag,
                             TestGetAuthorFamilyNameWords,)

if __name__ == "__main__":
    run_test_suite(TEST_SUITE)
            1 has a self-citation
            see document graph up in this file
            """
            from invenio.bibrank_selfcites_indexer import compute_self_citations

            tags = get_author_tags_mock()
            self_citations = compute_self_citations(1, tags, get_record_coauthors_mock)
            self.assertEqual(self_citations, set([3]))

        @patch("invenio.bibrank_selfcites_indexer.get_collaborations_from_record", get_collaborations_from_record_mock)
        @patch("invenio.bibrank_selfcites_indexer.get_authors_from_record", get_authors_from_record_mock)
        @patch("invenio.bibrank_selfcites_indexer.get_cited_by", get_cited_by_mock(1, 2, 3))
        def test_compute_self_citations_all_self_citations(self):
            """
            Check self citations count matches when all citations
            are self citations

            see document graph up in this file
            """
            from invenio.bibrank_selfcites_indexer import compute_self_citations

            tags = get_author_tags_mock()
            total_citations = compute_self_citations(1, tags, get_record_coauthors_mock)
            self.assertEqual(total_citations, set([1, 2, 3]))


TEST_SUITE = make_test_suite(SelfCitesOtherTests)

if __name__ == "__main__":
    run_test_suite(TEST_SUITE)
Example #16
0
        self.assertEqual(websubmit_functions['Is_Referee'].__doc__,
                         "test_reloading")

        websubmit_functions.reload_plugins(reload=True)
        self.assertNotEqual(websubmit_functions['Is_Referee'].__doc__,
                            "test_reloading")

    def test_plugin_container_module_caching(self):
        """pluginutils - plugin caching"""
        websubmit_functions = PluginContainer(
            os.path.join(CFG_PYLIBDIR, 'invenio', 'websubmit_functions',
                         '*.py'))
        self.assertNotEqual(websubmit_functions['Is_Referee'].__doc__,
                            "test_caching")
        websubmit_functions['Is_Referee'].__doc__ = "test_caching"
        self.assertEqual(websubmit_functions['Is_Referee'].__doc__,
                         "test_caching")

        websubmit_functions.reload_plugins()
        websubmit_functions_new = PluginContainer(
            os.path.join(CFG_PYLIBDIR, 'invenio', 'websubmit_functions',
                         '*.py'))
        self.assertEqual(websubmit_functions_new['Is_Referee'].__doc__,
                         "test_caching")


TEST_SUITE = make_test_suite(TestPluginContainer, )

if __name__ == "__main__":
    run_test_suite(TEST_SUITE)
                                                              password="******", \
                                                              verbose=0)
        self.assertEqual(1, len(matchedrecs))

    def test_restricted_collections_remote(self):
        """bibmatch - check restricted collections remote search"""
        records = create_records(self.recxml5)
        # Jekyll should have access
        [dummy1, matchedrecs, dummy2, dummy3] = match_records(records, \
                                                              qrystrs=[("", "[088__a]")], \
                                                              collections=["Theses"], \
                                                              server_url="https://invenio-demo.cern.ch", \
                                                              user  ="******", \
                                                              password="******",
                                                              verbose=0)
        self.assertEqual(1, len(matchedrecs))
        # Hyde should not have access
        [nomatchrecs, dummy1, dummy2, dummy3] = match_records(records, \
                                                              qrystrs=[("", "[088__a]")], \
                                                              collections=["Theses"], \
                                                              server_url="https://invenio-demo.cern.ch", \
                                                              user="******", \
                                                              password="******",
                                                              verbose=0)
        self.assertEqual(1, len(nomatchrecs))

TEST_SUITE = make_test_suite(BibMatchTest)

if __name__ == "__main__":
    run_test_suite(TEST_SUITE, warn_user=True)
Example #18
0
        user_info = {'uid': '', 'remote_ip': '127.0.0.1', 'uri': 'testuri'}

        settings = ObelixSearchEngineSettings(redis=self.redis)

        self.assertEqual(
            self.hitset[0:10],
            rank_records_obelix(user_info,
                                self.hitset,
                                rg=10,
                                jrec=0,
                                settings=settings)[0])

    def test_result_no_changes_when_user_is_zero_jrec_set(self):
        user_info = {'uid': '', 'remote_ip': '127.0.0.1', 'uri': 'testuri'}

        settings = ObelixSearchEngineSettings(redis=self.redis)

        self.assertEqual(
            self.hitset[4:14],
            rank_records_obelix(user_info,
                                self.hitset,
                                rg=10,
                                jrec=5,
                                settings=settings)[0])


TEST_SUITE = make_test_suite(TestRedisMock, TestObelixRecommendations)

if __name__ == "__main__":
    run_test_suite(TEST_SUITE)
    def test_wash_dashed_language(self):
        """messages - washing dashed language code (fr-ca)"""
        if 'fr' not in CFG_SITE_LANGS:
            self.assertEqual(messages.wash_language('fr-ca'), CFG_SITE_LANG)
        else:
            self.assertEqual(messages.wash_language('fr-ca'), 'fr')

    def test_wash_languages(self):
        """messages - washing multiple languages"""
        if 'de' not in CFG_SITE_LANGS:
            self.assertEqual(messages.wash_languages(['00', '11', '22', 'de']),
                             CFG_SITE_LANG)
        else:
            self.assertEqual(messages.wash_languages(['00', '11', '22', 'de']),
                             'de')
        self.assertEqual(messages.wash_languages(['00', '11', '22']),
                         CFG_SITE_LANG)

    def test_rtl_direction(self):
        """messages - right-to-left language detection"""
        # Arabic is right-to-left:
        self.assertEqual(messages.is_language_rtl('ar'), True)
        # English is not right-to-left:
        self.assertEqual(messages.is_language_rtl('en'), False)


TEST_SUITE = make_test_suite(MessagesLanguageTest, )

if __name__ == "__main__":
    run_test_suite(TEST_SUITE)
                         test_case_pubinfo_cited_by)

    def test_intcite_via_report_number(self):
        """bibrank - external cites, no internal papers via report number"""
        # The internal paper hep-th/9809057 is cited by 2 demo
        # records, but it also exists as a demo record, so it should
        # not be found in the extcite table.
        test_case_repno = "hep-th/9809057"
        test_case_repno_cited_by = []
        self.assertEqual(self._detect_extcite_info(test_case_repno),
                         test_case_repno_cited_by)

    def test_intcite_via_publication_reference(self):
        """bibrank - external cites, no internal papers via publication reference"""
        # The internal paper #18 has only pubinfo, no repno, and is
        # cited by internal paper #96 via its pubinfo, so should not
        # be present in the extcite list:
        test_case_repno = "Phys. Lett., B 151 (1985) 357"
        test_case_repno_cited_by = []
        self.assertEqual(self._detect_extcite_info(test_case_repno),
                         test_case_repno_cited_by)

TEST_SUITE = make_test_suite(BibRankWebPagesAvailabilityTest,
                             BibRankIntlMethodNames,
                             BibRankWordSimilarityRankingTest,
                             BibRankCitationRankingTest,
                             BibRankExtCitesTest)

if __name__ == "__main__":
    run_test_suite(TEST_SUITE, warn_user=True)
            'user': '******',
            'passwd': '123',
            'use_unicode': False,
            'charset': 'utf8'
        }
        try:
            connect(**kwargs)
        except:
            output = get_pretty_traceback(exc_info=sys.exc_info(),
                                          force_stack=True)
        self.failIf('123' in output, output)
        self.failUnless('<*****>' in output, output)

    def test_nested_password_hiding(self):
        """errorlib - hide password nested in dictionary in frame analysis"""
        try:
            foo = {'bar': 'baz', 'qoox': {'blibpwdblob': '1234'}}
            int(foo)
        except:
            output = get_pretty_traceback(exc_info=sys.exc_info(),
                                          force_stack=True)
        self.failIf('1234' in output, output)
        self.failUnless('<*****>' in output, output)


TEST_SUITE = make_test_suite(ErrorlibWebPagesAvailabilityTest,
                             ErrorlibRegisterExceptionTest)

if __name__ == "__main__":
    run_test_suite(TEST_SUITE, warn_user=True)
                                                   linebreak_output="\n")
        self.assertEqual(res, expected_text)

    def test_indenting_rule_message(self):
        """webmessage - return email-like indenting rule"""
        text = """>>Brave Sir Robin ran away...
<img src="malicious_script"/>*No!*
>>bravely ran away away...
I didn't!*<script>malicious code</script>
>>When danger reared its ugly head, he bravely turned his tail and fled.
<form onload="malicious"></form>*I never did!*
"""
        expected_text = """>>Brave Sir Robin ran away...
&lt;img src="malicious_script" /&gt;*No!*
>>bravely ran away away...
I didn't!*&lt;script&gt;malicious code&lt;/script&gt;
>>When danger reared its ugly head, he bravely turned his tail and fled.
&lt;form onload="malicious"&gt;&lt;/form&gt;*I never did!*
"""

        res = webmessage_mailutils.escape_email_quoted_text(text,
                                                            indent_txt='>>',
                                                            linebreak_txt='\n')
        self.assertEqual(res, expected_text)


TEST_SUITE = make_test_suite(TestQuotingMessage)

if __name__ == "__main__":
    run_test_suite(TEST_SUITE)
Example #23
0
# -*- coding: utf-8 -*-
##
## This file is part of Invenio.
## Copyright (C) 2012 CERN.
##
## Invenio is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## Invenio is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## 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.
"""Unit tests for jsonutils library."""

from invenio.testutils import InvenioTestCase

from invenio.testutils import make_test_suite, run_test_suite

TEST_SUITE = make_test_suite()

if __name__ == "__main__":
    run_test_suite(TEST_SUITE)
__revision__ = "$Id$"

from invenio.testutils import InvenioTestCase
import sys
from invenio.testutils import make_test_suite, run_test_suite

if sys.hexversion < 0x2040000:
    # pylint: disable=W0622
    from sets import Set as set
    # pylint: enable=W0622

class WebGroupTests(InvenioTestCase):
    """Test functions related to the WebGroup usage."""

    def test_set(self):
        """webgroup - test fancy usage of set (differences among Python versions)"""
        # These should succeed:
        self.failUnless(set([1,2,3]))
        self.assertEqual(set([1,2,3]) - set([3,4,5]), set([1,2]))
        self.assertEqual(set([1,2,3,3]), set([1,2,3]))
        self.assertEqual(set([1,2,3]), set([3,2,1]))
        self.assertEqual(set([1,2,3]) & set([2,3,4]), set([2,3]))
        self.assertEqual(set([1,2,3]) | set([2,3,4]), set([1,2,3,4]))
        self.assertEqual(set([1,2,3]), set([3,2,1]))

TEST_SUITE = make_test_suite(WebGroupTests,)

if __name__ == "__main__":
    run_test_suite(TEST_SUITE)
        user_info = {}
        user_info['nickname'] = 'test_user'
        user_info['email'] = '*****@*****.**'
        user_info['id'] = 1

        result = perform_submission_process(
            4, 'https://arxiv.org/sword-app/test-collection', 97, user_info,
            metadata)

        self.assertEqual(open('/tmp/media.xml', 'r').read() != '', True)
        self.assertEqual(open('/tmp/metadata.xml', 'r').read() != '', True)
        self.assertEqual(open('/tmp/submit.xml', 'r').read() != '', True)

        if result['row_id'] != '':
            delete_from_swr_clientdata(result['row_id'])


TEST_SUITE = make_test_suite(
    Test_format_marcxml_file,
    Test_format_metadata,
    #Test_get_submission_status,
    #Test_format_submission_status,
    Test_swrCLIENTDATA_table)
#Test_format_metadata_atom)
#Test_list_submitted_resources)
#Test_submission_process)

if __name__ == "__main__":
    run_test_suite(TEST_SUITE)
            'url': 'http://rjfreijoiregjreoijgoirg.fr'
        }, {
            'url': 'http://1.2.3.4/'
        }]

        def finished(pagegetter, check, current_time):
            """Function called when a page is received."""
            is_ok = pagegetter.status is not None

            if check.has_key('content') and is_ok:
                is_ok = pagegetter.data.find(check['content']) > 0

            check['result'] = is_ok == check.has_key('content')

        pagegetters = [HTTPAsyncPageGetter(check['url']) for check in checks]
        finished_list = async_download(pagegetters, finished, checks, 20)

        for (finished, check) in zip(finished_list, checks):
            if not finished:
                check['result'] = not check.has_key('content')

        errors = [check for check in checks if not check['result']]

        self.assertEqual(errors, [])


TEST_SUITE = make_test_suite(AsyncDownloadTest, )

if __name__ == "__main__":
    run_test_suite(TEST_SUITE)
            }, rec_termcount, hitset, 50, 0)
        self.assertEqual(([(1, 71), (3, 100)], list(hitset2)),
                         (res1, list(res2)))

    def test_calculate_record_relevance(self):
        """bibrank record sorter - calculating relevances"""
        hitset = intbitset()
        hitset += (1, 2, 5)
        self.assertEqual(({
            1: 7,
            2: 7,
            5: 5
        }, {
            1: 1,
            2: 1,
            5: 1
        }),
                         bibrank_word_searcher.calculate_record_relevance(
                             ("testterm", 2.0), {
                                 "Gi": (0, 50.0),
                                 1: (3, 4.0),
                                 2: (4, 5.0),
                                 5: (1, 3.5)
                             }, hitset, {}, {}, 0, None))


TEST_SUITE = make_test_suite(TestListSetOperations, )

if __name__ == "__main__":
    run_test_suite(TEST_SUITE)
        self.browser.get(CFG_SITE_SECURE_URL + '/admin/webjournal/webjournaladmin.py/feature_record?journal_name=AtlantisTimes&action=askremove&recid=7&ln=en')
        self.page_source_test(expected_text='Authorization failure')
        self.browser.get(CFG_SITE_SECURE_URL + '/admin/webjournal/webjournaladmin.py/feature_record?ln=en')
        self.page_source_test(expected_text='Authorization failure')
        self.logout()
        # Access WebJournal URLs as fully authorized editor
        self.browser.get(CFG_SITE_SECURE_URL + '/admin/webjournal/webjournaladmin.py?ln=en')
        # login as balthasar
        self.login(username="******", password="******")
        self.page_source_test(expected_text='delete')
        self.find_element_by_link_text_with_timeout("AtlantisTimes")
        self.browser.find_element_by_link_text("AtlantisTimes").click()
        self.page_source_test(expected_text=['Feature a Record', 'Edit Configuration',
                                             'regenerate', 'release now', 'announce now'])
        self.browser.get(CFG_SITE_SECURE_URL + '/admin/webjournal/webjournaladmin.py/configure?action=add&ln=en')
        self.page_source_test(unexpected_text='Authorization failure')
        self.browser.get(CFG_SITE_SECURE_URL + '/admin/webjournal/webjournaladmin.py/index?journal_name=AtlantisTimes&action=askDelete&ln=en')
        self.page_source_test(unexpected_text='Authorization failure')
        self.browser.get(CFG_SITE_SECURE_URL + '/admin/webjournal/webjournaladmin.py/configure?action=edit&journal_name=AtlantisTimes&ln=en')
        self.page_source_test(unexpected_text='Authorization failure')
        self.browser.get(CFG_SITE_SECURE_URL + '/admin/webjournal/webjournaladmin.py/feature_record?journal_name=AtlantisTimes&ln=en')
        self.page_source_test(unexpected_text='Authorization failure')
        self.browser.get(CFG_SITE_SECURE_URL + '/admin/webjournal/webjournaladmin.py/feature_record?ln=en')
        self.page_source_test(unexpected_text='Authorization failure')
        self.logout()

TEST_SUITE = make_test_suite(InvenioWebJournalWebTest, )

if __name__ == '__main__':
    run_test_suite(TEST_SUITE, warn_user=True)
        dicts['cites'][95].remove(77)
        dicts['refs'][77].remove(95)
        process_chunk([95], CONFIG, dicts)
        compare_dicts(self, dicts)

    def test_removed_refs(self):
        "test the cascading of removed refs"
        from invenio.bibrank_citation_indexer import process_chunk
        dicts = EXPECTED_DICTS.copy()
        dicts['cites'].setdefault(1, []).append(3)
        dicts['cites'].setdefault(2, []).append(3)
        dicts['refs'].setdefault(3, []).extend([1, 2])
        process_chunk([3], CONFIG, dicts)
        compare_dicts(self, dicts)

    def test_removed_cites(self):
        "test the cascading of removed cites"
        from invenio.bibrank_citation_indexer import process_chunk
        dicts = EXPECTED_DICTS.copy()
        dicts['cites'].setdefault(1, []).append(3)
        dicts['cites'].setdefault(2, []).append(3)
        dicts['refs'].setdefault(3, []).extend([1, 2])
        process_chunk([1, 2], CONFIG, dicts)
        compare_dicts(self, dicts)


TEST_SUITE = make_test_suite(TestCitationIndexer,)

if __name__ == "__main__":
    run_test_suite(TEST_SUITE, warn_user=True)
Example #30
0
class TestBibSortWasherWashers(InvenioTestCase):
    """Test BibSortWasher Washers."""
    def test_sort_alphanumerically_remove_leading_articles(self):
        """Test the sort_alphanumerically_remove_leading_articles method"""
        method = "sort_alphanumerically_remove_leading_articles"
        bsm = BibSortWasher(method)
        self.assertEqual('title of a record',
                         bsm.get_transformed_value('The title of a record'))
        self.assertEqual('title of a record',
                         bsm.get_transformed_value('a title of a record'))
        self.assertEqual('the', bsm.get_transformed_value('The'))

    def test_sort_dates(self):
        """Test the sort_dates method"""
        method = "sort_dates"
        bsm = BibSortWasher(method)
        self.assertEqual('2010-01-10', bsm.get_transformed_value('2010-01-10'))
        self.assertEqual('2010-11-10',
                         bsm.get_transformed_value('10 nov 2010'))
        self.assertEqual('2010-11-01', bsm.get_transformed_value('nov 2010'))
        self.assertEqual('2010-01-01', bsm.get_transformed_value('2010'))
        self.assertEqual('2010-11-08', bsm.get_transformed_value('8 nov 2010'))


TEST_SUITE = make_test_suite(TestBibSortWasherWashers,
                             TestBibSortWasherCreation)

if __name__ == "__main__":
    run_test_suite(TEST_SUITE)
Example #31
0
        pass

    def test_strip_accents(self):
        """textutils - transliterate to ascii (basic)"""
        self.assertEqual("memememe", strip_accents('mémêmëmè'))
        self.assertEqual("MEMEMEME", strip_accents('MÉMÊMËMÈ'))
        self.assertEqual("oe", strip_accents('Å“'))
        self.assertEqual("OE", strip_accents('Å’'))


class TestALALC(unittest.TestCase):
    """Test for handling ALA-LC transliteration."""

    if UNIDECODE_AVAILABLE:

        def test_alalc(self):
            msg = "眾鳥高飛盡"
            encoded_text, encoding = guess_minimum_encoding(msg)
            unicode_text = unicode(encoded_text.decode(encoding))
            self.assertEqual("Zhong Niao Gao Fei Jin ",
                             transliterate_ala_lc(unicode_text))


TEST_SUITE = make_test_suite(WrapTextInABoxTest, GuessMinimumEncodingTest,
                             WashForXMLTest, WashForUTF8Test,
                             DecodeToUnicodeTest, Latex2UnicodeTest,
                             TestStripping, TestALALC)

if __name__ == "__main__":
    run_test_suite(TEST_SUITE)
Example #32
0
            (
                (20, 30, 1000, 41),
                'x\x9cc`\x10p``b\x18\x18\xc0\x88`\x02\x00+9\x00T',
                'x\x9cc`\x10p`\x18(\xf0\x1f\x01\x00k\xe6\x0bF'
            ),
            (
                (20, 30, 1001, 41),
                'x\x9cc`\x10p``b\x18\x18\x80d/\x00+D\x00U',
                'x\x9cc`\x10p`\x18(\xf0\xef?\x1c\x00\x00k\xdb\x0bE'
            )
        )
        for original, dumped, dumped_trails in tests:
            intbitset1 = intbitset(original)
            intbitset2 = intbitset(original, trailing_bits=True)
            intbitset3 = intbitset(dumped)
            intbitset4 = intbitset(dumped_trails)
            self._helper_sanity_test(intbitset1)
            self._helper_sanity_test(intbitset2)
            self._helper_sanity_test(intbitset3)
            self._helper_sanity_test(intbitset4)
            self.assertEqual(intbitset1.fastdump(), dumped)
            self.assertEqual(intbitset1, intbitset3)
            self.assertEqual(intbitset2.fastdump(), dumped_trails)
            self.assertEqual(intbitset2, intbitset4)

TEST_SUITE = make_test_suite(IntBitSetTest,)

if __name__ == "__main__":
    run_test_suite(TEST_SUITE)

        my_new_bibdoc.delete()
        self.assertEqual(my_new_bibdoc.deleted_p(), True)

class CheckBibDocAuthorization(unittest.TestCase):
    """Regression tests for check_bibdoc_authorization function."""
    def test_check_bibdoc_authorization(self):
        """bibdocfile - check_bibdoc_authorization function"""
        from invenio.webuser import collect_user_info, get_uid_from_email
        jekyll = collect_user_info(get_uid_from_email('*****@*****.**'))
        self.assertEqual(check_bibdoc_authorization(jekyll, 'role:thesesviewer'), (0, CFG_WEBACCESS_WARNING_MSGS[0]))
        self.assertEqual(check_bibdoc_authorization(jekyll, 'role: thesesviewer'), (0, CFG_WEBACCESS_WARNING_MSGS[0]))
        self.assertEqual(check_bibdoc_authorization(jekyll, 'role:  thesesviewer'), (0, CFG_WEBACCESS_WARNING_MSGS[0]))
        self.assertNotEqual(check_bibdoc_authorization(jekyll, 'Role:  thesesviewer')[0], 0)
        self.assertEqual(check_bibdoc_authorization(jekyll, 'email: [email protected]'), (0, CFG_WEBACCESS_WARNING_MSGS[0]))
        self.assertEqual(check_bibdoc_authorization(jekyll, 'email: [email protected]'), (0, CFG_WEBACCESS_WARNING_MSGS[0]))

        juliet = collect_user_info(get_uid_from_email('*****@*****.**'))
        self.assertEqual(check_bibdoc_authorization(juliet, 'restricted_picture'), (0, CFG_WEBACCESS_WARNING_MSGS[0]))
        self.assertEqual(check_bibdoc_authorization(juliet, 'status: restricted_picture'), (0, CFG_WEBACCESS_WARNING_MSGS[0]))
        self.assertNotEqual(check_bibdoc_authorization(juliet, 'restricted_video')[0], 0)
        self.assertNotEqual(check_bibdoc_authorization(juliet, 'status: restricted_video')[0], 0)



TEST_SUITE = make_test_suite(BibRecDocsTest, \
                             BibDocsTest, \
                             BibDocFilesTest, \
                             CheckBibDocAuthorization)
if __name__ == "__main__":
    run_test_suite(TEST_SUITE, warn_user=True)
Example #34
0
        from invenio.websearch_model import Collection
        from invenio.bibformat import format_record
        from invenio.bibfield import get_record

        etree.clear_error_log()

        for recid in Collection.query.filter_by(name='zenodo').first().reclist:
            try:
                xml = None
                record = get_record(recid)
                for identifier in record.get('related_identifiers', []):
                    if identifier['scheme'] != identifier['scheme'].lower():
                        raise Exception(
                            "Record %s has problem with upper-case scheme %s" %
                            (recid, identifier['scheme']))
                if record.get('doi', None):
                    xml = StringIO(format_record(recid, 'dcite'))
                    xml_doc = etree.parse(xml)
                    self.schema.assertValid(xml_doc)
            except Exception, e:
                print recid
                if xml:
                    print xml.getvalue()
                raise e


TEST_SUITE = make_test_suite(DataCiteXMLRegressionTest)

if __name__ == "__main__":
    run_test_suite(TEST_SUITE)
            error_messages.extend(test_web_page_content(url,
                                                        username='******'))
        if error_messages:
            self.fail(merge_error_messages(error_messages))
        return

    def test_oairepositoryadmin_edit_set(self):
        """oairepositoryadmin - edit set page"""
        test_edit_url = CFG_SITE_URL + \
               "/admin/bibharvest/oairepositoryadmin.py/editset?oai_set_id=2"
        error_messages = test_web_page_content(test_edit_url,
                                               username='******')
        if error_messages:
            self.fail(merge_error_messages(error_messages))
        return

    def test_oairepositoryadmin_delete_set(self):
        """oairepositoryadmin - delete set page"""
        test_edit_url = CFG_SITE_URL + \
               "/admin/bibharvest/oairepositoryadmin.py/delset?oai_set_id=2"
        error_messages = test_web_page_content(test_edit_url,
                                               username='******')
        if error_messages:
            self.fail(merge_error_messages(error_messages))
        return

TEST_SUITE = make_test_suite(OAIRepositoryAdminWebPagesAvailabilityTest)

if __name__ == "__main__":
    run_test_suite(TEST_SUITE, warn_user=True)
        # bad argument type
        error = 'ERR_MISCUTIL_DEBUG'
        other_error = 'ERR_MISCUTIL_BAD_ARGUMENT_TYPE'
        output_list = get_msgs_for_code_list([(error, 'should be an int')])
        self.assertEqual(2, len(output_list))
        self.assertEqual(2, len(output_list[0]))
        self.assertEqual(2, len(output_list[1]))
        self.assertEqual(error, output_list[0][0])
        self.assertEqual(other_error, output_list[1][0])

    # z because this function must execute lately for more interesting
    # results:
    def test_zsubstitution(self):
        """errorlib - arguments: every argument substituted"""
        # string replacement
        testmessages = reduce(lambda x, y: str(x) + str(y), self.messages)
        self.assertEqual(0, testmessages.count('%') - testmessages.count('%%'))

    # z because this function must also execute lately for more
    # interesting results:
    def test_zinternationalization(self):
        """errorlib - internationalization"""
        # string internationalization
        testmessages = reduce(lambda x, y: str(x) + str(y), self.messages)
        self.assertEqual(0, testmessages.count('_('))

TEST_SUITE = make_test_suite(TestInternalErrorlibErrors,)

if __name__ == "__main__":
    run_test_suite(TEST_SUITE)
                         get_field_content_in_utf8(6, 'abstract', tags))

    @nottest
    def test_build_custom_field_content(self):
        """solrutils - build custom field content"""
        tags = {'abstract': ['520__%', '590__%']}

        self.assertEqual(u"""In 1962, CERN hosted the 11th International Conference on High Energy Physics. Among the distinguished visitors were eight Nobel prizewinners.Left to right: Cecil F. Powell, Isidor I. Rabi, Werner Heisenberg, Edwin M. McMillan, Emile Segre, Tsung Dao Lee, Chen Ning Yang and Robert Hofstadter. En 1962, le CERN est l'hote de la onzieme Conference Internationale de Physique des Hautes Energies. Parmi les visiteurs eminents se trouvaient huit laureats du prix Nobel.De gauche a droite: Cecil F. Powell, Isidor I. Rabi, Werner Heisenberg, Edwin M. McMillan, Emile Segre, Tsung Dao Lee, Chen Ning Yang et Robert Hofstadter.""",
                         get_field_content_in_utf8(6, 'abstract', tags))


TESTS = []


if CFG_SOLR_URL:
    TESTS.extend((TestSolrSearch, TestSolrWebSearch))
    if get_external_word_similarity_ranker() == 'solr':
        TESTS.extend((TestSolrRanking,
                      TestSolrSimilarToRecid,
                      TestSolrWebRanking,
                      TestSolrWebSimilarToRecid,
                      TestSolrLoadLogicalFieldSettings,
                      TestSolrBuildFieldContent,
                      ))


TEST_SUITE = make_test_suite(*TESTS)

if __name__ == "__main__":
    run_test_suite(TEST_SUITE, warn_user=True)
        """InvenioConnector - collection search"""
        server = InvenioConnector(CFG_SITE_URL)
        result = server.search(p="", c=["Books"], of="id")
        self.assertTrue(len(result) > 0, "did not get collection search results.")

    def test_search_local_restricted_collections(self):
        """InvenioConnector - local restricted collection search"""
        server = InvenioConnector(CFG_SITE_URL)
        search_params = dict(p="LBL-28106", c=["Theses"], of="id")
        self.assertRaises(InvenioConnectorAuthError, server.search, **search_params)

        server = InvenioConnector(CFG_SITE_SECURE_URL, user="******", password="")
        result = server.search(p="LBL-28106", c=["Theses"], of="id")
        self.assertTrue(len(result) > 0, "did not get restricted collection search results.")

    def test_search_remote_restricted_collections(self):
        """InvenioConnector - remote restricted collection search"""
        server = InvenioConnector("http://invenio-demo.cern.ch")
        search_params = dict(p="LBL-28106", c=["Theses"], of="id")
        self.assertRaises(InvenioConnectorAuthError, server.search, **search_params)

        server = InvenioConnector("https://invenio-demo.cern.ch", user="******", password="******")
        result = server.search(p="LBL-28106", c=["Theses"], of="id")
        self.assertTrue(len(result) > 0, "did not get restricted collection search results.")


TEST_SUITE = make_test_suite(InvenioConnectorTest)

if __name__ == "__main__":
    run_test_suite(TEST_SUITE, warn_user=True)
Example #39
0
    def xtest_ouput_modes(self):
        pass

    def xtest_get_single_keywords(self):
        """test the function returns {<keyword>: [ [spans...] ] }"""

    def xtest_get_composite_keywords(self):
        """test the function returns {<keyword>: [ [spans...], [correct component counts] ] }"""


def suite(cls=BibClassifyTest):
    import unittest
    tests = []
    for x in sys.argv[1:]:
        if x[0:4] == 'test':
            tests.append(x)
    if len(tests) < 1:
        raise Exception('You must specify tests to run')

    return unittest.TestSuite(map(cls, tests))


if 'custom' in sys.argv:
    TEST_SUITE = suite(BibClassifyTest)
else:
    TEST_SUITE = make_test_suite(BibClassifyTest)

if __name__ == '__main__':
    run_test_suite(TEST_SUITE)
        self.bmcs0.store()
        self.bm.duplicate_existing('testname2','testnameduplicate')
        self.assertTrue(self.bmcs0.load())
        self.assertTrue(self.bm.load())
        bmcs0 = self.bmcs0
        bm = self.bm
        for i in range(100):
            for  j in range(100):
                self.assertTrue(bmcs0[i,j] == bm[i,j])

    def test_special_items(self):
        self.bmcs0[0,0] = '+'
        self.bmcs0[0,1] = '-'
        self.bmcs0[0,2] = None
        self.assertTrue(self.bmcs0[0,0] == '+')
        self.assertTrue(self.bmcs0[0,1] == '-')
        self.assertTrue(self.bmcs0[0,2] is None)

    def test_getitem_numeric(self):
        self.bmcs0[0,0] = '+'
        self.bmcs0[0,1] = '-'
        self.bmcs0[0,2] = None
        self.assertTrue(self.bmcs0.getitem_numeric([0,0])[0] == -2)
        self.assertTrue(self.bmcs0.getitem_numeric([0,1])[0] == -1)
        self.assertTrue(self.bmcs0.getitem_numeric([0,2])[0] == -3)

TEST_SUITE = make_test_suite(TestBibMatrix)

if __name__ == "__main__":
    run_test_suite(TEST_SUITE, warn_user=True)
Example #41
0
            self.assertEqual(result[0][1], '?ln=%s' % CFG_SITE_LANG)

            result = transform('<lang:link />', languages=['fr'])
            self.assertEqual(result[0][1], '?ln=fr')


class WebDocCommentsFiltering(InvenioTestCase):
    """Check that comments are correctly removed from webdoc files"""

    if lang_english_configured:

        def test_comments_filtering(self):
            """webdoc - removing comments"""
            result = transform('''# -*- coding: utf-8 -*-
    ## $Id$
    ##''',
                               languages=[CFG_SITE_LANG])

            self.assertEqual(result[0][1], '')


TEST_SUITE = make_test_suite(
    WebDocLanguageTest,
    WebDocPartsTest,
    WebDocVariableReplacementTest,
    WebDocCommentsFiltering,
)

if __name__ == "__main__":
    run_test_suite(TEST_SUITE)
from invenio.testutils import InvenioTestCase

from invenio.importutils import autodiscover_modules
from invenio.testutils import make_test_suite, run_test_suite


class TestImportUtils(InvenioTestCase):
    """
    importutils TestSuite.
    """

    def test_autodiscover_modules(self):
        modules = autodiscover_modules(['invenio.bibformat_elements'], related_name_re='bfe_.+\.py')
        assert(len(modules) > 10)
        modules = autodiscover_modules(['invenio'], related_name_re='(.+)_config\.py')
        assert(len(modules) > 10)
        assert(None not in modules)
        modules = autodiscover_modules(['invenio.not_an_existing_folder'], related_name_re='foo_.+\.py')
        assert(len(modules) == 0)
        assert(None not in modules)
        modules = autodiscover_modules(['invenio.bibformat_elements'], related_name_re='not_an_existing_file_name_.+\.yp')
        assert(len(modules) == 0)
        assert(None not in modules)


TEST_SUITE = make_test_suite(TestImportUtils,)

if __name__ == "__main__":
    run_test_suite(TEST_SUITE)
Example #43
0
                                                   linebreak_output="\n")
        self.assertEqual(res, expected_text)

    def test_indenting_rule_message(self):
        """webmessage - return email-like indenting rule"""
        text = """>>Brave Sir Robin ran away...
<img src="malicious_script"/>*No!*
>>bravely ran away away...
I didn't!*<script>malicious code</script>
>>When danger reared its ugly head, he bravely turned his tail and fled.
<form onload="malicious"></form>*I never did!*
"""
        expected_text = """>>Brave Sir Robin ran away...
&lt;img src="malicious_script" /&gt;*No!*
>>bravely ran away away...
I didn't!*&lt;script&gt;malicious code&lt;/script&gt;
>>When danger reared its ugly head, he bravely turned his tail and fled.
&lt;form onload="malicious"&gt;&lt;/form&gt;*I never did!*
"""

        res = webmessage_mailutils.escape_email_quoted_text(text,
                                                            indent_txt='>>',
                                                            linebreak_txt='\n')
        self.assertEqual(res, expected_text)


TEST_SUITE = make_test_suite(TestQuotingMessage)

if __name__ == "__main__":
    run_test_suite(TEST_SUITE)
Example #44
0
            <subfield code="a">http://scd-theses.u-strasbg.fr/1818/01/RICAUD_Helene_2008.pdf</subfield>
            <subfield code="d">Fulltext</subfield>
        </datafield>
        </record>"""

        self.assertEqual(re.sub("\s+", " ", output['resultXML'].strip()),
                         re.sub("\s+", " ", xml_expected_output.strip()))


class TestPerformDoiSearch(InvenioTestCase):
    """Test the perform_doi_search function, which resolves the doi using
    dx.doi.org page and returns the url of the resource
    """
    def test_normal(self):
        """Checks if some standard doi is working"""
        doi = "10.1007/BF02724522"
        wrong_output = {}
        self.assertNotEqual(perform_doi_search(doi), wrong_output)

    def test_no_headers(self):
        """Checks if the doi that requires 'User-Agent' header is working"""
        doi = "10.1016/0550-3213(89)90423-9"
        wrong_output = {}
        self.assertNotEqual(perform_doi_search(doi), wrong_output)


TEST_SUITE = make_test_suite(TextmarcToXMLTests, TestPerformDoiSearch)

if __name__ == "__main__":
    run_test_suite(TEST_SUITE)
Example #45
0
## Invenio is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## 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.
"""Unit tests for BibKnowledge."""

from invenio.testutils import make_test_suite, run_test_suite, InvenioTestCase


class BibknowledgeTests(InvenioTestCase):
    """Unit test functions for bibknowledge."""
    pass

    def setUp(self):
        """bibknowledge unit test setup"""
        pass

    def tearDown(self):
        """bbibknowledge unit test cleanup"""
        pass


TEST_SUITE = make_test_suite(BibknowledgeTests)

if __name__ == "__main__":
    run_test_suite(TEST_SUITE)
        self.failUnless(websubmit_functions['CaseEDS'])
        self.failUnless(callable(websubmit_functions['CaseEDS']))
        self.failUnless(len(websubmit_functions) >= 62)
        ## Retrieve_Data and Shared_Functions are not real plugins
        self.failUnless(len(websubmit_functions.get_broken_plugins()) >= 2)
        self.failIf(websubmit_functions.get('Shared_Functions'))
        self.failUnless('Shared_Functions' in websubmit_functions.get_broken_plugins())

    def test_plugin_container_wrapping_external_authentications(self):
        """pluginutils - wrapping external authentications"""
        def plugin_builder(plugin_name, plugin_code):
            for name in dir(plugin_code):
                candidate = getattr(plugin_code, name)
                try:
                    if issubclass(candidate, ExternalAuth):
                        return candidate
                except TypeError:
                    pass
            raise ValueError('%s is not a valid external authentication plugin' % plugin_name)

        external_authentications = PluginContainer(os.path.join(CFG_PYLIBDIR, 'invenio', 'external_authentication_*.py'), plugin_signature=ExternalAuth, plugin_builder=plugin_builder)
        self.failUnless(issubclass(external_authentications['external_authentication_sso'], ExternalAuth))
        self.failIf(external_authentications.get('external_authentication_cern_wrapper'))
        self.failUnless(len(external_authentications) >= 1)
        self.failUnless(len(external_authentications.get_broken_plugins()) >= 2)

TEST_SUITE = make_test_suite(TestPluginContainer,)

if __name__ == "__main__":
    run_test_suite(TEST_SUITE)
        """webjournal - check washing of ln parameter in /record handler"""
        error_messages = test_web_page_content(
            CFG_SITE_URL + '/record/103?verbose=9&ln=hello',
            expected_text=[
                "we rode to another estate",
                "The forest abounded with beautiful objects"
            ],
            unexpected_text=[
                "Error when evaluating format element WEBJOURNAL_"
            ])
        if error_messages:
            self.fail(merge_error_messages(error_messages))

    def test_language_handling_in_whatsnew_widget(self):
        """webjournal - check handling of ln parameter in "what's new" widget"""
        error_messages = test_web_page_content(
            CFG_SITE_URL + '/journal/AtlantisTimes/2009/03/News?ln=fr',
            expected_link_label="Scissor-beak",
            expected_link_target=CFG_SITE_URL +
            "/journal/AtlantisTimes/2009/03/Science/111?ln=fr")
        if error_messages:
            self.fail(merge_error_messages(error_messages))


TEST_SUITE = make_test_suite(ArticlesRelated, CategoriesRelated,
                             JournalConfigVars, TimeIssueFunctions,
                             JournalRelated, HtmlCachingFunction,
                             FormattingElements)
if __name__ == "__main__":
    run_test_suite(TEST_SUITE, warn_user=True)
    for line in output.splitlines():
        line = line.strip()
        if line:
            if line not in result:
                msg = "\nGot: %s\nMissing: \"%s\"" % (result, line)
                break
    if msg and output_bad_pdftotext:
        warn(
            "Standard test failed; let's try a test amended for older pdftotext versions now. If this succeeds, please consider upgrading to the latest version of pdftotext."
        )
        msg = ""
        for line in output_bad_pdftotext.splitlines():
            line = line.strip()
            if line:
                if line not in result:
                    msg = "\nGot: %s\nMissing: \"%s\"" % (result, line)
                    break
    if msg:
        return (False, msg)
    else:
        return (True, True)


if 'custom' in sys.argv:
    TEST_SUITE = suite(BibClassifyRegressionTest)
else:
    TEST_SUITE = make_test_suite(BibClassifyRegressionTest)

if __name__ == "__main__":
    run_test_suite(TEST_SUITE, warn_user=True)
Example #49
0
        ]

        error_messages = []
        for url in [baseurl + page for page in _exports]:
            # first try as guest:
            error_messages.extend(
                test_web_page_content(url,
                                      username='******',
                                      expected_text='Authorization failure'))
            # then try as admin:
            error_messages.extend(test_web_page_content(url, username='******'))
        if error_messages:
            self.fail(merge_error_messages(error_messages))
        return

    def test_websearch_admin_guide_availability(self):
        """websearchadmin - availability of WebSearch Admin guide pages"""

        url = CFG_SITE_URL + '/help/admin/websearch-admin-guide'
        error_messages = test_web_page_content(
            url, expected_text="WebSearch Admin Guide")
        if error_messages:
            self.fail(merge_error_messages(error_messages))
        return


TEST_SUITE = make_test_suite(WebSearchAdminWebPagesAvailabilityTest)

if __name__ == "__main__":
    run_test_suite(TEST_SUITE, warn_user=True)
    def test_send_message_later(self):
        """webmessage - web test send a message later"""

        self.browser.get(CFG_SITE_SECURE_URL)
        # login as romeo
        self.login(username="******", password="******")
        # let's go to "Your Messages"
        self.find_element_by_link_text_with_timeout("Personalize")
        self.browser.find_element_by_link_text("Personalize").click()
        self.find_element_by_link_text_with_timeout("Your Messages")
        self.browser.find_element_by_link_text("Your Messages").click()
        self.find_element_by_name_with_timeout("del_all")
        self.browser.find_element_by_name("del_all").click()
        self.handle_popup_dialog()
        self._compose_message(users="juliet", subject="dear juliet", body= "i love you")
        self.choose_selectbox_option_by_label(selectbox_name="msg_send_day",label= "4")
        self.choose_selectbox_option_by_label(selectbox_name="msg_send_month", label="July")
        self.find_element_by_name_with_timeout("send_button")
        self.browser.find_element_by_name("send_button").click()
        self.page_source_test(expected_text='The chosen date (0/7/4) is invalid')
        self.choose_selectbox_option_by_label(selectbox_name="msg_send_year", label="2019")
        self.find_element_by_name_with_timeout("send_button")
        self.browser.find_element_by_name("send_button").click()
        self.page_source_test(expected_text='Your message has been sent')
        self.logout()

TEST_SUITE = make_test_suite(InvenioWebMessageWebTest, )

if __name__ == '__main__':
    run_test_suite(TEST_SUITE, warn_user=True)
Example #51
0
        issue2 = '07/2009'
        self.assertEqual(compare_issues(issue1, issue2), -1)

    def test_issue1_is_later_than(self):
        """webjournal - tests comparing issue1 is later than issue2 """
        issue1 = '07/2009'
        issue2 = '07/2008'
        self.assertEqual(issue_is_later_than(issue1, issue2), True)

        issue1 = '07/2008'
        issue2 = '07/2009'
        self.assertEqual(issue_is_later_than(issue1, issue2), False)

        issue1 = '07/2009'
        issue2 = '06/2009'
        self.assertEqual(issue_is_later_than(issue1, issue2), True)

        issue1 = '06/2009'
        issue2 = '07/2009'
        self.assertEqual(issue_is_later_than(issue1, issue2), False)

        issue1 = '07/2009'
        issue2 = '07/2009'
        self.assertEqual(issue_is_later_than(issue1, issue2), False)


TEST_SUITE = make_test_suite(TestCompareIssues)

if __name__ == "__main__":
    run_test_suite(TEST_SUITE)
                                          automatic_link_transformation=True),
                         body_expected)

    def test_not_transform_link(self):
        """htmlutils - not transforming a link"""
        body_input = '<a href="https://cds.cern.ch/collection/Multimedia%20%26%20Outreach?ln=es">Multimedia</a>'
        body_expected = '<a href="https://cds.cern.ch/collection/Multimedia%20%26%20Outreach?ln=es">Multimedia</a>'
        self.assertEqual(self.washer.wash(html_buffer=body_input,
                                          automatic_link_transformation=True),
                         body_expected)

class HTMLCreation(unittest.TestCase):
    """Test functions related to creation of HTML markup."""

    def test_create_html_select(self):
        """htmlutils - create HTML <select> list """
        self.assertEqual(create_html_select(["foo", "bar"], selected="bar", name="baz"),
                         '<select name="baz"><option value="foo">foo</option>\n<option selected="selected" value="bar">bar</option></select>')


TEST_SUITE = make_test_suite(XSSEscapingTest,
                             CharactersEscapingTest,
                             HTMLWashingTest,
                             HTMLMarkupRemovalTest,
                             HTMLTidyingTest,
                             HTMLAutomaticLinksTransformation,
                             HTMLCreation)

if __name__ == "__main__":
    run_test_suite(TEST_SUITE)
        original_restriction = run_sql("SELECT restriction FROM cmtRECORDCOMMENT WHERE id=%s",
                                       (self.restr_comid_2,))[0][0]
        restriction_to_inherit = 'juliet_only'
        run_sql("UPDATE cmtRECORDCOMMENT SET restriction=%s WHERE id=%s",
                (restriction_to_inherit, self.restr_comid_2))

        # Reply to a restricted comment
        self.msg4 = "A test comment 4"
        prepare_attachments()
        self.restr_comid_3 = \
                           query_add_comment_or_remark(reviews=0, recID=self.public_record_restr_comment,
                                                       uid=self.jekyll_uid, msg=self.msg4,
                                                       editor_type='textarea',
                                                       attached_files=self.attached_files,
                                                       reply_to=self.restr_comid_2)

        inherited_restriction = run_sql("SELECT restriction FROM cmtRECORDCOMMENT WHERE id=%s",
                                        (self.restr_comid_3,))[0][0]

        self.assertEqual(restriction_to_inherit, inherited_restriction)

        # Restore original restriction
        run_sql("UPDATE cmtRECORDCOMMENT SET restriction=%s WHERE id=%s",
                (original_restriction, self.restr_comid_2))

TEST_SUITE = make_test_suite(WebCommentWebPagesAvailabilityTest,
                             WebCommentRestrictionsTest)

if __name__ == "__main__":
    run_test_suite(TEST_SUITE, warn_user=True)
Example #54
0
__revision__ = "$Id$"

import unittest
import sys
from invenio.testutils import make_test_suite, run_test_suite

if sys.hexversion < 0x2040000:
    # pylint: disable=W0622
    from sets import Set as set
    # pylint: enable=W0622


class WebGroupTests(unittest.TestCase):
    """Test functions related to the WebGroup usage."""
    def test_set(self):
        """webgroup - test fancy usage of set (differences among Python versions)"""
        # These should succeed:
        self.failUnless(set([1, 2, 3]))
        self.assertEqual(set([1, 2, 3]) - set([3, 4, 5]), set([1, 2]))
        self.assertEqual(set([1, 2, 3, 3]), set([1, 2, 3]))
        self.assertEqual(set([1, 2, 3]), set([3, 2, 1]))
        self.assertEqual(set([1, 2, 3]) & set([2, 3, 4]), set([2, 3]))
        self.assertEqual(set([1, 2, 3]) | set([2, 3, 4]), set([1, 2, 3, 4]))
        self.assertEqual(set([1, 2, 3]), set([3, 2, 1]))


TEST_SUITE = make_test_suite(WebGroupTests, )

if __name__ == "__main__":
    run_test_suite(TEST_SUITE)
        """bibconvert - error codes"""

        # FIXME: put proper tests here
        self.assertEqual(1, 1)

class TestEncodings(InvenioTestCase):
    """Test bibconvert encodings"""

    def xtest_enc(self):
        """bibconvert - encodings"""

        # FIXME: put proper tests here
        self.assertEqual(1, 1)


TEST_SUITE = make_test_suite(TestFormattingFunctions,
                             TestGlobalFormattingFunctions,
                             TestGenerateValues,
                             TestParseData,
                             TestRegExp,
                             TestLim,
                             TestLimw,
                             TestWords,
                             TestBCCL,
                             TestKnowledgeBase,
                             TestErrorCodes,
                             TestEncodings,)

if __name__ == "__main__":
    run_test_suite(TEST_SUITE)
Example #56
0
                  <subfield code="l">00</subfield>
                  <subfield code="m">2002-04-12</subfield>
                  <subfield code="o">BATCH</subfield>
                </datafield>
                <datafield tag="909" ind1="C" ind2="S">
                  <subfield code="s">m</subfield>
                  <subfield code="w">198604</subfield>
                </datafield>
                <datafield tag="980" ind1=" " ind2=" ">
                  <subfield code="a">BOOK</subfield>
                </datafield>
              </record>
              """
        reader = MarcReader(blob=xml, schema="xml")
        r = Record(reader.translate())

        r.check_record(reset=True)
        self.assertTrue('title' in r)
        self.assertEquals(len(r['title']), 2)
        self.assertEquals(len(r.fatal_errors), 1)

        r['title'] = r['title'][0]
        r.check_record(reset=True)
        self.assertEquals(len(r.fatal_errors), 0)


TEST_SUITE = make_test_suite(BibFieldMarcReaderMarcXML, BibFieldCheckRecord)

if __name__ == "__main__":
    run_test_suite(TEST_SUITE)
            url = CFG_SITE_URL + '/textmining/api/extract-references-pdf'

            pdf = open("%s/docextract/example.pdf" % CFG_ETCDIR, 'rb')
            response = requests.post(url, files={'pdf': pdf})
            # Remove stats tag
            lines = response.content.split('\n')
            lines[-6:-1] = []
            compare_references(self, '\n'.join(lines), EXPECTED_RESPONSE)

        def test_url(self):
            url = CFG_SITE_URL + '/textmining/api/extract-references-pdf-url'

            pdf = CFG_SITE_URL + '/textmining/example.pdf'
            response = requests.post(url, data={'url': pdf})
            compare_references(self, response.content, EXPECTED_RESPONSE)

        def test_txt(self):
            url = CFG_SITE_URL + '/textmining/api/extract-references-txt'

            pdf = open("%s/docextract/example.txt" % CFG_ETCDIR, 'rb')
            response = requests.post(url, files={'txt': pdf})
            # Remove stats tag
            lines = response.content.split('\n')
            lines[-6:-1] = []
            compare_references(self, '\n'.join(lines), EXPECTED_RESPONSE)

TEST_SUITE = make_test_suite(DocExtractTest)

if __name__ == '__main__':
    run_test_suite(TEST_SUITE)