def test_seminars_create_with_invalid_data(inspire_app): data = faker.record("sem", with_control_number=True) data["invalid_key"] = "should throw an error" record_control_number = str(data["control_number"]) with pytest.raises(ValidationError): SeminarsRecord.create(data) record_pid = PersistentIdentifier.query.filter_by( pid_value=record_control_number).one_or_none() assert record_pid is None
def test_seminars_create_with_existing_control_number(inspire_app): data = faker.record("sem", with_control_number=True) existing_object_uuid = uuid.uuid4() create_pidstore( object_uuid=existing_object_uuid, pid_type="sem", pid_value=data["control_number"], ) with pytest.raises(PIDAlreadyExists): SeminarsRecord.create(data)
def test_cn_redirection_works_for_seminars(inspire_app): redirected_record = create_record("sem") record = create_record( "sem", data={"deleted_records": [redirected_record["self"]]}) original_record = SeminarsRecord.get_uuid_from_pid_value( redirected_record["control_number"], original_record=True) new_record = SeminarsRecord.get_uuid_from_pid_value( redirected_record["control_number"]) assert original_record != new_record assert original_record == redirected_record.id assert new_record == record.id
def test_create_record_from_db_depending_on_its_pid_type(inspire_app): data = faker.record("sem") record = InspireRecord.create(data) assert type(record) == SeminarsRecord assert record.pid_type == "sem" record = SeminarsRecord.create(data) assert type(record) == SeminarsRecord assert record.pid_type == "sem"
def test_seminars_create_or_update_with_new_record(inspire_app): data = faker.record("sem") record = SeminarsRecord.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="sem", pid_value=str(control_number)).one() assert record.model.id == record_pid.object_uuid assert control_number == record_pid.pid_value
def test_seminars_create_or_update_with_existing_record(inspire_app): data = faker.record("sem", with_control_number=True) record = SeminarsRecord.create(data) assert data["control_number"] == record["control_number"] data_update = {"timezone": "Europe/Zurich"} data.update(data_update) record_updated = SeminarsRecord.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="sem", pid_value=str(control_number)).one() assert record_updated.model.id == record_updated_pid.object_uuid assert control_number == record_updated_pid.pid_value
def test_subclasses_for_seminars(): expected = {"sem": SeminarsRecord} assert expected == SeminarsRecord.get_subclasses()