Пример #1
0
def test_cleanup_indexed_deposits(app, db, es, locations, users,
                                  deposit_metadata, sip_metadata_types):
    with app.test_request_context():
        datastore = app.extensions['security'].datastore
        login_user(datastore.get_user(users[0]['email']))
        id_ = uuid4()
        depid = zenodo_deposit_minter(id_, deposit_metadata)
        ZenodoDeposit.create(deposit_metadata, id_=id_)

    # Emulate a database "failure", which would wipe any models in the session
    db.session.remove()
    current_search.flush_and_refresh(index='deposits')

    # Deposit has been indexed in ES, but not commimted in DB
    assert PersistentIdentifier.query.filter(
        PersistentIdentifier.pid_type == depid.pid_type,
        PersistentIdentifier.pid_value == depid.pid_value).count() == 0
    assert (RecordsSearch(index='deposits').get_record(id_).execute()
            [0]._deposit.id == depid.pid_value)

    cleanup_indexed_deposits.apply()
    current_search.flush_and_refresh(index='deposits')

    assert PersistentIdentifier.query.filter(
        PersistentIdentifier.pid_type == depid.pid_type,
        PersistentIdentifier.pid_value == depid.pid_value).count() == 0
    assert len(RecordsSearch(index='deposits').get_record(id_).execute()) == 0
Пример #2
0
def test_identifier_schemes(app, db, es, locations, license_record,
                            sample_identifiers):
    """Test supported identifier schemes."""
    s = legacyjson.LegacyMetadataSchemaV1(strict=True)
    result = s.load(d(related_identifiers=[
        {'identifier': _id, 'scheme': scheme, 'relation': 'references'}
        for scheme, (_id, _) in sample_identifiers.items()
    ]))
    ZenodoDeposit.create(result.data).validate()
def test_identifier_schemes(app, db, es, locations, license_record,
                            sample_identifiers):
    """Test supported identifier schemes."""
    s = legacyjson.LegacyMetadataSchemaV1(strict=True)
    result = s.load(
        d(related_identifiers=[{
            'identifier': _id,
            'scheme': scheme,
            'relation': 'references'
        } for scheme, (_id, _) in sample_identifiers.items()]))
    ZenodoDeposit.create(result.data).validate()
Пример #4
0
def deposit(app, es, users, locations, deposit_metadata, sip_metadata_types):
    """New deposit with files."""
    with app.test_request_context():
        datastore = app.extensions['security'].datastore
        login_user(datastore.get_user(users[0]['email']))
        id_ = uuid4()
        zenodo_deposit_minter(id_, deposit_metadata)
        deposit = Deposit.create(deposit_metadata, id_=id_)
        db_.session.commit()
    current_search.flush_and_refresh(index='deposits')
    return deposit
Пример #5
0
def deposit(app, es, users, locations, deposit_metadata, sip_metadata_types):
    """New deposit with files."""
    with app.test_request_context():
        datastore = app.extensions['security'].datastore
        login_user(datastore.get_user(users[0]['email']))
        id_ = uuid4()
        zenodo_deposit_minter(id_, deposit_metadata)
        deposit = Deposit.create(deposit_metadata, id_=id_)
        db_.session.commit()
    current_search.flush_and_refresh(index='deposits')
    return deposit
Пример #6
0
def loaddemorecords(records, owner):
    """Load demo records."""
    with current_app.test_request_context():
        login_user(owner)
        for record in records:
            deposit_data = legacyjson_v1(record)
            deposit_id = uuid4()
            zenodo_deposit_minter(deposit_id, deposit_data)
            deposit = ZenodoDeposit.create(deposit_data, id_=deposit_id)
            db.session.commit()
            filename = record['files'][0]
            deposit.files[filename] = BytesIO(filename)
            db.session.commit()
            deposit.publish()
            db.session.commit()
Пример #7
0
def deposit(app, es, users, location):
    """New deposit with files."""
    record = dict(
        title='Test title',
        creators=[
            dict(name='Doe, John', affiliation='Atlantis'),
            dict(name='Smith, Jane', affiliation='Atlantis')
        ],
        description='Test Description',
        publication_date='2013-05-08',
        access_right='open'
    )
    with app.test_request_context():
        datastore = app.extensions['security'].datastore
        login_user(datastore.get_user(users[0]['email']))
        deposit = Deposit.create(record)
        deposit.commit()
        db_.session.commit()
    current_search.flush_and_refresh(index='deposits')
    return deposit
def test_legacyjson_to_record_translation(app, db, es, grant_record,
                                          license_record, locations):
    """Test the translator legacy_zenodo and zenodo_legacy."""
    test_data = dict(metadata=dict(
        access_right='embargoed',
        communities=[{
            'identifier': 'cfa'
        }],
        conference_acronym='Some acronym',
        conference_dates='Some dates',
        conference_place='Some place',
        conference_title='Some title',
        conference_url='http://someurl.com',
        conference_session='VI',
        conference_session_part='1',
        creators=[
            dict(name="Doe, John",
                 affiliation="Atlantis",
                 orcid="0000-0002-1825-0097",
                 gnd="170118215"),
            dict(name="Smith, Jane", affiliation="Atlantis")
        ],
        description="Some description",
        doi="10.1234/foo.bar",
        embargo_date=(datetime.utcnow().date() +
                      timedelta(days=2)).isoformat(),
        grants=[
            dict(id="282896"),
        ],
        imprint_isbn="Some isbn",
        imprint_place="Some place",
        imprint_publisher="Some publisher",
        journal_issue="Some issue",
        journal_pages="Some pages",
        journal_title="Some journal name",
        journal_volume="Some volume",
        keywords=["Keyword 1", "keyword 2"],
        subjects=[
            dict(scheme="gnd", identifier="1234567899", term="Astronaut"),
            dict(scheme="gnd", identifier="1234567898", term="Amish"),
        ],
        license="CC0-1.0",
        notes="Some notes",
        partof_pages="SOme part of",
        partof_title="Some part of title",
        prereserve_doi=True,
        publication_date="2013-09-12",
        publication_type="book",
        references=[
            "Reference 1",
            "Reference 2",
        ],
        related_identifiers=[
            dict(identifier='10.1234/foo.bar2', relation='isCitedBy'),
            dict(identifier='10.1234/foo.bar3', relation='cites'),
            dict(identifier='2011ApJS..192...18K',
                 relation='isAlternativeIdentifier'),
        ],
        thesis_supervisors=[
            dict(name="Doe Sr., John", affiliation="Atlantis"),
            dict(name="Smith Sr., Jane",
                 affiliation="Atlantis",
                 orcid="http://orcid.org/0000-0002-1825-0097",
                 gnd="http://d-nb.info/gnd/170118215")
        ],
        thesis_university="Some thesis_university",
        contributors=[
            dict(name="Doe Sr., Jochen", affiliation="Atlantis", type="Other"),
            dict(name="Smith Sr., Marco",
                 affiliation="Atlantis",
                 orcid="http://orcid.org/0000-0002-1825-0097",
                 gnd="http://d-nb.info/gnd/170118215",
                 type="DataCurator")
        ],
        title="Test title",
        upload_type="publication",
    ))
    ZenodoDeposit.create(
        legacyjson.LegacyRecordSchemaV1(
            strict=True).load(test_data).data).validate()
Пример #9
0
def test_legacyjson_to_record_translation(app, db, es, grant_records,
                                          license_record, locations,
                                          communities):
    """Test the translator legacy_zenodo and zenodo_legacy."""
    test_data = dict(
        metadata=dict(
            access_right='embargoed',
            communities=[{'identifier': 'c1'}],
            conference_acronym='Some acronym',
            conference_dates='Some dates',
            conference_place='Some place',
            conference_title='Some title',
            conference_url='http://someurl.com',
            conference_session='VI',
            conference_session_part='1',
            creators=[
                dict(name="Doe, John", affiliation="Atlantis",
                     orcid="0000-0002-1825-0097", gnd="170118215"),
                dict(name="Smith, Jane", affiliation="Atlantis")
            ],
            description="Some description",
            doi="10.1234/foo.bar",
            embargo_date=(
                datetime.utcnow().date() + timedelta(days=2)).isoformat(),
            grants=[dict(id="282896"), ],
            imprint_isbn="Some isbn",
            imprint_place="Some place",
            imprint_publisher="Some publisher",
            journal_issue="Some issue",
            journal_pages="Some pages",
            journal_title="Some journal name",
            journal_volume="Some volume",
            keywords=["Keyword 1", "keyword 2"],
            subjects=[
                dict(scheme="gnd", identifier="1234567899", term="Astronaut"),
                dict(scheme="gnd", identifier="1234567898", term="Amish"),
            ],
            license="CC0-1.0",
            notes="Some notes",
            partof_pages="SOme part of",
            partof_title="Some part of title",
            prereserve_doi=True,
            publication_date="2013-09-12",
            publication_type="book",
            references=[
                "Reference 1",
                "Reference 2",
            ],
            related_identifiers=[
                dict(identifier='10.1234/foo.bar2', relation='isCitedBy'),
                dict(identifier='10.1234/foo.bar3', relation='cites'),
                dict(
                    identifier='2011ApJS..192...18K',
                    relation='isAlternativeIdentifier'),
            ],
            thesis_supervisors=[
                dict(name="Doe Sr., John", affiliation="Atlantis"),
                dict(name="Smith Sr., Jane", affiliation="Atlantis",
                     orcid="http://orcid.org/0000-0002-1825-0097",
                     gnd="http://d-nb.info/gnd/170118215")
            ],
            thesis_university="Some thesis_university",
            contributors=[
                dict(name="Doe Sr., Jochen", affiliation="Atlantis",
                     type="Other"),
                dict(name="Smith Sr., Marco", affiliation="Atlantis",
                     orcid="http://orcid.org/0000-0002-1825-0097",
                     gnd="http://d-nb.info/gnd/170118215",
                     type="DataCurator")
            ],
            title="Test title",
            upload_type="publication",
        )
    )
    ZenodoDeposit.create(
        legacyjson.LegacyRecordSchemaV1(strict=True).load(test_data).data
    ).validate()