Example #1
0
def test_redirection_invalidates_correctly_pid_objects(inspire_app):
    pid_1 = PersistentIdentifier.create(
        pid_type="a",
        pid_value="1",
        status=PIDStatus.REGISTERED,
        object_uuid=uuid.uuid4(),
    )

    pid_2 = PersistentIdentifier.create(
        pid_type="a",
        pid_value="2",
        status=PIDStatus.REGISTERED,
        object_uuid=uuid.uuid4(),
    )

    pid_3 = PersistentIdentifier.create(
        pid_type="a",
        pid_value="3",
        status=PIDStatus.REGISTERED,
        object_uuid=uuid.uuid4(),
    )

    InspireRedirect.redirect(pid_1, pid_2)
    redirection = InspireRedirect.get(pid_1)

    assert redirection.original_pid == pid_1
    assert redirection.new_pid == pid_2

    assert pid_1.status == PIDStatus.REDIRECTED
    assert pid_1.redirection == redirection
    assert pid_2.redirected_pids == [redirection]
    assert pid_3.redirected_pids == []

    pid_2.status = PIDStatus.DELETED
    InspireRedirect.redirect(pid_1, pid_3)

    assert redirection.original_pid == pid_1
    assert redirection.new_pid == pid_3

    assert pid_1.status == PIDStatus.REDIRECTED
    assert pid_1.redirection == redirection
    assert pid_2.redirected_pids == []
    assert pid_3.redirected_pids == [redirection]
    assert pid_2.status == PIDStatus.DELETED
    redirection.delete()

    assert pid_1.status == PIDStatus.DELETED

    assert pid_1.redirection is None
    assert len(pid_2.redirected_pids) == 0

    with pytest.raises(PidRedirectionMissing):
        InspireRedirect.get(pid_1)
Example #2
0
def test_get_redirection_object(inspire_app):
    pid_1 = PersistentIdentifier.create(pid_type="a",
                                        pid_value="1",
                                        status=PIDStatus.REGISTERED)
    pid_2 = PersistentIdentifier.create(pid_type="a",
                                        pid_value="2",
                                        status=PIDStatus.REGISTERED)

    InspireRedirect.redirect(pid_1, pid_2)

    redirection = InspireRedirect.get(pid_1)
    assert redirection.original_pid.pid_type == pid_1.pid_type
    assert redirection.original_pid.pid_value == pid_1.pid_value
    assert redirection.new_pid.pid_type == pid_2.pid_type
    assert redirection.new_pid.pid_value == pid_2.pid_value

    with pytest.raises(PidRedirectionMissing):
        InspireRedirect.get(pid_2)
Example #3
0
def test_deleting_redirection_object(inspire_app):
    pid_1 = PersistentIdentifier.create(pid_type="a",
                                        pid_value="1",
                                        status=PIDStatus.REGISTERED)
    pid_2 = PersistentIdentifier.create(pid_type="a",
                                        pid_value="2",
                                        status=PIDStatus.REGISTERED)

    InspireRedirect.redirect(pid_1, pid_2)

    assert pid_1.status == PIDStatus.REDIRECTED

    redirection = InspireRedirect.get(pid_1)
    redirection.delete()

    assert pid_1.status == PIDStatus.DELETED

    with pytest.raises(PidRedirectionMissing):
        InspireRedirect.get(pid_1)