Esempio n. 1
0
 def test_get_record_using_field_filter(self):
     """bibfield - get record filtering fields"""
     authors = get_record(12, fields=('authors',))
     self.assertEquals(len(authors['authors']), 19)
     mainauthor_title = get_record(12, fields=('authors[0]', 'title'))
     self.assertTrue('authors[0].full_name' in mainauthor_title)
     self.assertTrue('title' in mainauthor_title)
Esempio n. 2
0
 def test_get_using_formating_function(self):
     """bibfield - format values using formating function"""
     def dummy(s):
         return s.upper()
     record = get_record(1)
     self.assertEqual('ALEPH EXPERIMENT: CANDIDATE OF HIGGS BOSON PRODUCTION',
                      record.get('title.title', formatfunction=dummy))
Esempio n. 3
0
    def test_produce_json_for_dublin_core(self):
        """bibfield - produce json dublin core"""
        record = get_record(1)
        date = record.get('version_id').strftime('%Y-%m-%dT%H:%M:%SZ')
        produced_dc = record.produce_json_for_dc()

        self.assertTrue({'dc:date': date} in produced_dc)
Esempio n. 4
0
 def test_compare_field_values_with_bibrecord_values(self):
     """bibfield - same value as in bibrecord"""
     from invenio.legacy.bibrecord import record_get_field_values
     from invenio.legacy.search_engine import get_record as search_engine_get_record
     record = get_record(1)
     bibrecord_value = record_get_field_values(search_engine_get_record(1), '245', ' ', ' ', 'a')[0]
     self.assertEqual(bibrecord_value, record['title.title'])
Esempio n. 5
0
 def test_calculated_fields_availability_and_values(self):
     """bibfield - values of calculated fields"""
     record = get_record(31)
     self.assertEqual(2, record['_number_of_copies'])
     run_sql("insert into crcITEM(barcode, id_bibrec) VALUES('test',31)")
     self.assertEqual(2, record['_number_of_copies'])
     self.assertEqual(3, record.get('_number_of_copies', reset_cache=True))
     run_sql("delete from crcITEM WHERE barcode='test'")
     record.update_field_cache('_number_of_copies')
     self.assertEqual(2, record['_number_of_copies'])
     self.assertEqual(2, record['number_of_copies'])
Esempio n. 6
0
    def test_get_legacy_recstruct(self):
        """bibfield - legacy functions"""
        from invenio.legacy.search_engine import get_record as search_engine_get_record
        from invenio.legacy.bibrecord import record_get_field_value

        bibfield_recstruct = get_record(8).get_legacy_recstruct()
        bibrecord = search_engine_get_record(8)

        self.assertEqual(record_get_field_value(bibfield_recstruct, '100', code='a'),
                         record_get_field_value(bibrecord, '100', code='a'))
        self.assertEqual(len(bibfield_recstruct['999']), len(bibrecord['999']))
Esempio n. 7
0
    def test_bibdoc_integration(self):
        """bibfield - bibdoc integration"""
        rec = get_record(7)

        self.assertTrue('_files' in rec)
        self.assertEquals(len(rec['files']), 2)
        image = rec['files'][1]
        self.assertEquals(image['eformat'], '.jpeg')
        self.assertEquals(image['name'], '9806033')

        bibdoc = rec['bibdocs'].list_latest_files()[1]
        self.assertEquals(image['name'], bibdoc.name)
Esempio n. 8
0
 def test_normal_fields_availability_and_values(self):
     """bibfield - access to normal fields"""
     record = get_record(12)
     self.assertTrue(record.get('asdas') is None)
     self.assertEqual('12', record['recid'])
     self.assertTrue('recid' in record.get_persistent_identifiers())
     self.assertEqual(record['recid'], record.get('recid'))
     self.assertEqual('Physics at the front-end of a neutrino factory : a quantitative appraisal', record['title.title'])
     self.assertEqual('Physics at the front-end of a neutrino factory : a quantitative appraisal', record['title']['title'])
     self.assertFalse('title.subtitle' in record)
     self.assertEqual('Physics at the front-end of a neutrino factory : a quantitative appraisal', record.get('title.title'))
     self.assertEqual('Mangano', record['authors[0].last_name'])
     self.assertEqual('M L', record['authors[0].first_name'])
     self.assertEqual(19, len(record['authors']))
     self.assertEqual(19, len(record['authors.last_name']))
Esempio n. 9
0
 def test_derived_fields_availability_and_values(self):
     """bibfield - values of derived fields"""
     record = get_record(12)
     self.assertEqual(19, record['number_of_authors'])
Esempio n. 10
0
    def test_produce_json_for_marc(self):
        """bibfield - produce json marc"""
        record = get_record(1)
        produced_marc = record.produce_json_for_marc()

        self.assertTrue({'001': '1'} in produced_marc)
Esempio n. 11
0
    def test_record_creation(self):
        import os
        from wtforms import TextAreaField
        from datetime import datetime

        from invenio.legacy.search_engine import record_exists
        from invenio.cache import cache
        from invenio.config import CFG_PREFIX
        from invenio.modules.workflows.models import Workflow
        from invenio.modules.workflows.config import CFG_WORKFLOW_STATUS
        from invenio.modules.scheduler.models import SchTASK

        from invenio.webdeposit_utils import get_form, create_workflow, \
            set_form_status, CFG_DRAFT_STATUS
        from invenio.modules.deposit.loader import \
            deposition_metadata
        from invenio.webdeposit_workflow_utils import \
            create_record_from_marc
        from invenio.legacy.bibfield import get_record

        user_id = self.login_user()
        for deposition_type in deposition_metadata.keys():

            deposition = create_workflow(deposition_type, user_id)
            assert deposition is not None

            # Check if deposition creates a record
            create_rec = create_record_from_marc()
            function_exists = False
            for workflow_function in deposition.workflow:
                if create_rec.func_code == workflow_function .func_code:
                    function_exists = True
            if not function_exists:
                # if a record is not created,
                #continue with the next deposition
                continue

            uuid = deposition.get_uuid()

            cache.delete_many("1:current_deposition_type", "1:current_uuid")
            cache.add("1:current_deposition_type", deposition_type)
            cache.add("1:current_uuid", uuid)

            # Run the workflow
            deposition.run()

            # Create form's json based on the field name
            form = get_form(user_id, uuid=uuid)
            webdeposit_json = {}

            # Fill the json with dummy data
            for field in form:
                if isinstance(field, TextAreaField):
                    # If the field is associated with a marc field
                    if field.has_recjson_key() or field.has_cook_function():
                        webdeposit_json[field.name] = "test " + field.name

            draft = dict(form_type=form.__class__.__name__,
                         form_values=webdeposit_json,
                         step=0,  # dummy step
                         status=CFG_DRAFT_STATUS['finished'],
                         timestamp=str(datetime.now()))

            # Add a draft for the first step
            Workflow.set_extra_data(user_id=user_id, uuid=uuid,
                                    key='drafts', value={0: draft})

            workflow_status = CFG_WORKFLOW_STATUS.RUNNING
            while workflow_status != CFG_WORKFLOW_STATUS.COMPLETED:
                # Continue workflow
                deposition.run()
                set_form_status(user_id, uuid, CFG_DRAFT_STATUS['finished'])
                workflow_status = deposition.get_status()

            # Workflow is finished. Test if record is created
            recid = deposition.get_data('recid')
            assert recid is not None
            # Test that record id exists
            assert record_exists(recid) == 1

            # Test that the task exists
            task_id = deposition.get_data('task_id')
            assert task_id is not None

            bibtask = SchTASK.query.filter(SchTASK.id == task_id).first()
            assert bibtask is not None

            # Run bibupload, bibindex, webcoll manually
            cmd = "%s/bin/bibupload %s" % (CFG_PREFIX, task_id)
            assert not os.system(cmd)
            rec = get_record(recid)
            marc = rec.legacy_export_as_marc()
            for field in form:
                if isinstance(field, TextAreaField):
                    # If the field is associated with a marc field
                    if field.has_recjson_key() or field.has_cook_function():
                        assert "test " + field.name in marc