def test_experiments_create_or_update_with_new_record(inspire_app): data = faker.record("exp") record = ExperimentsRecord.create_or_update(data) control_number = str(record["control_number"]) record_db = RecordMetadata.query.filter_by(id=record.id).one() assert record == record_db.json record_pid = PersistentIdentifier.query.filter_by( pid_type="exp", pid_value=str(control_number)).one() assert record.model.id == record_pid.object_uuid assert control_number == record_pid.pid_value
def test_experiments_create_or_update_with_existing_record(inspire_app): data = faker.record("exp", with_control_number=True) record = ExperimentsRecord.create(data) assert data["control_number"] == record["control_number"] data_update = {"description": "UPDATED"} data.update(data_update) record_updated = ExperimentsRecord.create_or_update(data) control_number = str(record_updated["control_number"]) assert record["control_number"] == record_updated["control_number"] record_updated_db = RecordMetadata.query.filter_by(id=record_updated.id).one() assert data == record_updated_db.json record_updated_pid = PersistentIdentifier.query.filter_by( pid_type="exp", pid_value=str(control_number) ).one() assert record_updated.model.id == record_updated_pid.object_uuid assert control_number == record_updated_pid.pid_value