コード例 #1
0
def test_eitem_refs(app, testdata):
    """Test creation of an eitem."""
    eitem = EItem.create(
        dict(
            pid="eitemid-99",
            document_pid="docid-1",
            created_by=dict(type="script", value="demo"),
        ))
    assert "$schema" in eitem
    assert "document" in eitem and "$ref" in eitem["document"]

    eitem = EItem.get_record_by_pid("eitemid-4")
    eitem = eitem.replace_refs()
    assert "document" in eitem and eitem["document"]["title"]
コード例 #2
0
def create_eitem(document_pid, open_access=True):
    """Create eitem record."""
    obj = {
        "document_pid": document_pid,
        "open_access": open_access,
        "created_by": {
            "type": "script",
            "value": "migration"
        },
    }
    record_uuid = uuid.uuid4()
    provider = EItemIdProvider.create(
        object_type="rec",
        object_uuid=record_uuid,
    )

    obj["pid"] = provider.pid.pid_value
    eitem = EItem.create(obj, record_uuid)
    eitems_logger.info(
        "CREATED",
        extra=dict(
            document_pid=document_pid,
            new_pid=eitem["pid"],
            status="SUCCESS",
        ),
    )
    return eitem
コード例 #3
0
def test_eitem_validation(db, testdata):
    """Test validation when updating an eitem."""
    eitem_pid = testdata["eitems"][0]["pid"]
    eitem = EItem.get_record_by_pid(eitem_pid)

    # change document pid
    eitem["document_pid"] = "not_found_doc"
    with pytest.raises(DocumentNotFoundError):
        eitem.commit()
コード例 #4
0
def create_eitem(document_pid, open_access=True):
    """Create eitem record."""
    obj = {"document_pid": document_pid, "open_access": open_access}
    record_uuid = uuid.uuid4()
    provider = EItemIdProvider.create(
        object_type="rec",
        object_uuid=record_uuid,
    )

    obj["pid"] = provider.pid.pid_value
    eitem = EItem.create(obj, record_uuid)
    return eitem
コード例 #5
0
 def files_resolver(eitem_pid):
     """Return the Document record for the given EItem or raise."""
     files = []
     for obj in EItem.get_record_by_pid(eitem_pid).files:
         files.append({
             "bucket": obj.bucket_id,
             "checksum": obj.file.checksum,
             "file_id": obj.file.id,
             "key": obj.key,
             "size": obj.file.size,
             "version_id": str(obj.version_id),
         })
     return files
コード例 #6
0
    def test_on_eitem_update():
        """Test eitem resolvers."""
        indexer = _get_mock()

        pid = "eitemid-1"
        eitem = EItem.get_record_by_pid(pid)
        EItemIndexer().index(eitem)

        referenced = _assert_origin(indexer, EITEM_PID_TYPE, pid)

        # should re-index documents
        n_documents = 1  # from test data
        _assert_contains(referenced, DOCUMENT_PID_TYPE)

        assert len(referenced) == n_documents
コード例 #7
0
ファイル: api.py プロジェクト: kprzerwa/cds-ils
def create_eitem(document_pid, open_access=True):
    """Create eitem record."""
    obj = {
        "document_pid": document_pid,
        "open_access": open_access,
        "created_by": {
            "type": "script",
            "value": "migration"
        },
    }
    record_uuid = uuid.uuid4()
    provider = EItemIdProvider.create(
        object_type="rec",
        object_uuid=record_uuid,
    )

    obj["pid"] = provider.pid.pid_value
    eitem = EItem.create(obj, record_uuid)
    return eitem