def test_contributor_affiliations_indexing(running_app,
                                           minimal_record_with_contributor):
    minimal_record = minimal_record_with_contributor
    draft = RDMDraft.create(minimal_record).commit()

    # Dump draft - dumps will dereference relations which inturn updates the
    # internal record dict so dump and record should be identical.
    dump = draft.dumps()
    assert dump["metadata"]["contributors"][0]["affiliations"] == [{
        "id":
        "cern",
        "name":
        "CERN",
        "@v":
        f"{running_app.affiliations_v._record.id}::1"
    }]

    # Load draft again - should produce an identical record.
    loaded_draft = RDMDraft.loads(dump)
    assert dict(draft) == dict(loaded_draft)

    # Calling commit() will clear the dereferenced relation.
    loaded_draft.commit()
    loaded_aff = loaded_draft["metadata"]["contributors"][0]["affiliations"]
    assert loaded_aff == [{"id": "cern"}]
Ejemplo n.º 2
0
def test_languages_indexing(running_app, minimal_record):
    """Test languages relationship."""
    minimal_record["metadata"]["languages"] = [{"id": "eng"}]
    draft = RDMDraft.create(minimal_record).commit()

    # Dump draft - dumps will dereference relations which inturn updates the
    # internal record dict so dump and record should be identical.
    dump = draft.dumps()
    assert dump["metadata"]["languages"] == [{
        "id":
        "eng",
        "title": {
            "en": "English",
            "da": "Engelsk"
        },
        "@v":
        f"{running_app.languages_v._record.id}::1"
    }]

    # Load draft again - should produce an identical record.
    loaded_draft = RDMDraft.loads(dump)
    assert dict(draft) == dict(loaded_draft)

    # Calling commit() will clear the dereferenced relation.
    loaded_draft.commit()
    assert loaded_draft["metadata"]["languages"] == [{"id": "eng"}]
Ejemplo n.º 3
0
def test_idempotence_dumps_loads(running_app, minimal_record):
    """Idempotence of dumps and loads."""
    # This simple test asserts a key property of the dumps and loads methods.
    # A record that's dumped, must when loaded produce exactly the same dict
    # representation of a record. This key property ensures that it doesn't
    # matter if a record is loaded from primary storage (database) or secondary
    # storages (index, files, ...). A record when loaded behaves like a normal
    # record.

    # If this tests fails likely either a system fields pre/post_dump/load
    # method is having an issue, or it might be an Elasticsearch dumper.

    # DO NOT CHANGE TEST UNLESS YOU ABSOLUTELY KNOW WHAT YOU'RE DOING
    draft = RDMDraft.create(minimal_record)
    loaded_draft = RDMDraft.loads(draft.dumps())
    assert dict(draft) == dict(loaded_draft)
def test_resource_types_indexing(running_app, minimal_record):
    """Test dereferencing characteristics/features really."""
    minimal_record["metadata"]["resource_type"] = {"id": "image-photo"}
    draft = RDMDraft.create(minimal_record).commit()

    # TODO/WARNING: draft.dumps() modifies draft
    dump = draft.dumps()
    assert dump["metadata"]["resource_type"] == {
        "id": "image-photo",
        "title": {
            "en": "Photo"
        },
        "@v": f"{running_app.resource_type_item._record.id}::1"
    }

    # Load draft again - should produce an identical record.
    loaded_draft = RDMDraft.loads(dump)
    assert dict(draft) == dict(loaded_draft)

    # Calling commit() will clear the dereferenced relation.
    loaded_draft.commit()
    assert loaded_draft["metadata"]["resource_type"] == {"id": "image-photo"}
Ejemplo n.º 5
0
def test_subjects_indexing(running_app, minimal_record):
    """Test dereferencing characteristics/features really."""
    minimal_record["metadata"]["subjects"] = [{"id": "A-D000007"}]
    draft = RDMDraft.create(minimal_record).commit()

    # Dumping should return dereferenced representation
    dump = draft.dumps()
    assert dump["metadata"]["subjects"] == [{
        "id":
        "A-D000007",
        "title": {
            "en": "Abdominal Injuries"
        },
        "@v":
        f"{running_app.subject_v._record.id}::1"
    }]
    # NOTE/WARNING: draft.dumps() modifies the draft too
    assert draft["metadata"]["subjects"] == [{
        "id":
        "A-D000007",
        "title": {
            "en": "Abdominal Injuries"
        },
        "@v":
        f"{running_app.subject_v._record.id}::1"
    }]

    # Loading draft again should produce an identical record.
    loaded_draft = RDMDraft.loads(dump)
    assert dict(draft) == dict(loaded_draft)

    # Calling commit() should clear the dereferenced relation.
    draft.commit()
    assert draft["metadata"]["subjects"] == [{"id": "A-D000007"}]

    # subjects should be reachable through relations
    subject = next(draft.relations.subjects())
    assert "A-D000007" == subject["id"]