Пример #1
0
def test_set_keys(mock_pims_session, some_patient_id_keys):
    """Add an pseudonym-identifier pair"""
    connection = PIMSConnection(session=mock_pims_session)
    mock_pims_session.session.set_response_tuple(
        RequestsMockResponseExamples.
        KEYFILES_PSEUDONYMS_REIDENTIFY_NON_EXISTENT_RESPONSE)
    # keys need to be patientID to match mocked response above

    connection.set_keys(key_file=KeyFileFactory(), keys=some_patient_id_keys)
Пример #2
0
def test_set_keys_existing_pseudonym(mock_pims_session, some_patient_id_keys):
    """Setting a pseudonym that is already used for a different identifier should
    fail
    """
    connection = PIMSConnection(session=mock_pims_session)
    mock_pims_session.session.set_response_tuple(
        RequestsMockResponseExamples.DEIDENTIFY_FAILED_TO_INSERT)
    # keys need to be patientID to match mocked response above
    with pytest.raises(PIMSServerException):
        connection.set_keys(key_file=KeyFileFactory(),
                            keys=some_patient_id_keys)
Пример #3
0
def test_set_keys_existing_identity(mock_pims_session, some_patient_id_keys):
    """I want to add an pseudonym-identifier pair, but the identifier already
    exists
    """
    connection = PIMSConnection(session=mock_pims_session)
    mock_pims_session.session.set_response_tuple(
        RequestsMockResponseExamples.
        KEYFILES_PSEUDONYMS_REIDENTIFY_EXISTENT_RESPONSE)
    # keys need to be patientID to match mocked response above
    with pytest.raises(PIMSServerException):
        connection.set_keys(key_file=KeyFileFactory(),
                            keys=some_patient_id_keys)
Пример #4
0
def test_deidentify(mock_pims_session):
    connection = PIMSConnection(session=mock_pims_session)
    mock_pims_session.session.set_response_tuple(
        RequestsMockResponseExamples.DEIDENTIFY_CREATE_JSONOUTPUT_TRUE)
    identifiers = [IdentifierFactory(), IdentifierFactory()]
    keys = connection.pseudonymize(key_file=KeyFileFactory(),
                                   identifiers=identifiers)
    assert len(keys) == 2
    assert str(keys[0].identifier) == str(identifiers[0])

    mock_pims_session.session.set_response_tuple(
        RequestsMockResponseExamples.DEIDENTIFY_CREATE_JSONOUTPUT_TRUE_INVALID)

    with pytest.raises(PIMSSwaggerException) as e:
        connection.pseudonymize(key_file=KeyFileFactory(),
                                identifiers=identifiers)
Пример #5
0
def mock_project_requests(requests_mock):
    """Mock project that simulates actual requests.post calls. Will
    raise PIMSServerException for invalid return values, but allows checking what
    is sent to server
    """
    mock_session = Mock()
    project = Project(
        key_file_id=1,
        connection=PIMSConnection(
            session=PIMSSession(mock_session, base_url="/test")),
    )
    project.get_key_file = lambda: KeyFileFactory()  # make sure this passes
    return project
Пример #6
0
def test_pimsconnection(mock_pims_session):
    connection = PIMSConnection(session=mock_pims_session)
    mock_pims_session.session.set_response_tuple(
        RequestsMockResponseExamples.DEIDENTIFY_CREATE_JSONOUTPUT_TRUE)
    connection.pseudonymize(key_file=KeyFileFactory(),
                            identifiers=[IdentifierFactory()])

    mock_pims_session.session.set_response_tuple(
        RequestsMockResponseExamples.KEYFILES_PSEUDONYMS_REIDENTIFY_RESPONSE)
    connection.reidentify(key_file=KeyFileFactory(),
                          pseudonyms=[PseudonymFactory()])