コード例 #1
0
def test_id_is_not_written_to_record_for_stale_data_push(
    mock_hal_create, mock_update_record_with_new_ids, inspire_app, get_fixture
):
    hal_create_receipt = Deposit_Receipt()
    hal_create_receipt.id = "hal:123456"
    mock_hal_create.return_value = hal_create_receipt

    def side_effect(*args, **kwargs):
        if side_effect.counter == 0:
            side_effect.counter += 1
            raise StaleDataError
        else:
            return update_record_with_new_ids(*args, **kwargs)

    side_effect.counter = 0
    mock_update_record_with_new_ids.side_effect = side_effect

    record_json = orjson.loads(get_fixture("hal_preprod_record.json"))
    record_data = faker.record("lit", data=record_json)
    record = InspireRecord.create(record_data)

    institute_json = orjson.loads(get_fixture("hal_preprod_institute.json"))
    institute_data = faker.record("ins", data=institute_json)
    InspireRecord.create(institute_data)

    _hal_push(record)
    record = InspireRecord.get_record_by_pid_value(record["control_number"], "lit")
    assert get_values_for_schema(record["external_system_identifiers"], "HAL") == [
        "hal:123456"
    ]
コード例 #2
0
def test_push_happy_flow(inspire_app, get_fixture):
    record_json = orjson.loads(get_fixture("hal_preprod_record.json"))
    record_data = faker.record("lit", data=record_json)
    record = InspireRecord.create(record_data)

    institute_json = orjson.loads(get_fixture("hal_preprod_institute.json"))
    institute_data = faker.record("ins", data=institute_json)
    InspireRecord.create(institute_data)

    # hal create
    receipt = _hal_push(record)

    assert receipt
    assert receipt.parsed

    hal_id = receipt.id
    assert hal_id
    updated_record = InspireRecord.get_record_by_pid_value(
        record["control_number"], "lit"
    )
    assert (
        get_values_for_schema(
            get_value(updated_record, "external_system_identifiers", []), "HAL"
        )[0]
        == hal_id
    )

    # hal update
    receipt = _hal_push(record)
    assert receipt
    assert receipt.parsed
コード例 #3
0
def test_lock_is_created_for_hal_push_task(mocked_lock, inspire_app, get_fixture):
    record_json = orjson.loads(get_fixture("hal_preprod_record.json"))
    record_data = faker.record("lit", data=record_json)
    record = InspireRecord.create(record_data)

    institute_json = orjson.loads(get_fixture("hal_preprod_institute.json"))
    institute_data = faker.record("ins", data=institute_json)
    InspireRecord.create(institute_data)

    _hal_push(record)
    recid = record["control_number"]
    lock_name = f"hal:{recid}"

    assert mocked_lock.mock_calls[0][1][0] == lock_name
    assert mocked_lock.mock_calls[0][2] == {"blocking": True}