def test_update_relations_with_modified_experiments(app, celery_app_with_context, celery_session_worker): experiment_data = faker.record("exp", with_control_number=True) experiment = InspireRecord.create(experiment_data) db.session.commit() experiment_control_number = experiment["control_number"] exp_ref = f"http://localhost:8000/api/experiments/{experiment_control_number}" data = faker.record("lit", with_control_number=True) data["accelerator_experiments"] = [{ "legacy_name": "LIGO", "record": { "$ref": exp_ref } }] record = InspireRecord.create(data, disable_relations_update=True) db.session.commit() task = update_relations.delay([record.id]) task.get(timeout=5) experiment_literature_relation = ExperimentLiterature.query.filter_by( experiment_uuid=experiment.id).one() assert experiment_literature_relation.literature_uuid == record.id
def test_update_relations_with_modified_institutions(inspire_app, celery_app_with_context, celery_session_worker): institution_data = faker.record("ins", with_control_number=True) institution = InspireRecord.create(institution_data) db.session.commit() institution_control_number = institution["control_number"] inst_ref = f"http://localhost:8000/api/institutions/{institution_control_number}" data = faker.record("lit", with_control_number=True) data["authors"] = [{ "full_name": "John Doe", "affiliations": [{ "value": "Institution", "record": { "$ref": inst_ref } }], }] record = InspireRecord.create(data, disable_relations_update=True) db.session.commit() task = update_relations.delay([record.id]) task.get(timeout=5) institution_literature_relation = InstitutionLiterature.query.filter_by( institution_uuid=institution.id).one() assert institution_literature_relation.literature_uuid == record.id
def test_update_relations_recalculate_citations_with_different_type_of_records_doesnt_throw_an_exception( inspire_app, celery_app_with_context, celery_session_worker): data_cited = faker.record("lit", with_control_number=True) record_cited = InspireRecord.create(data_cited, disable_relations_update=True) db.session.commit() record_cited_control_number = record_cited["control_number"] data_citing = faker.record( "lit", literature_citations=[record_cited_control_number], with_control_number=True, ) record_citing = InspireRecord.create(data_citing, disable_relations_update=True) db.session.commit() records = [ create_record_async("aut"), create_record_async("job"), create_record_async("jou"), create_record_async("exp"), create_record_async("con"), create_record_async("dat"), create_record_async("ins"), ] uuids = [record.id for record in records] + [record_cited.id, record_citing.id] task = update_relations.delay(uuids) results = task.get(timeout=5) uuids = [str(uuid) for uuid in uuids] assert results == uuids result_record_cited = RecordCitations.query.filter_by( cited_id=record_cited.id).one() assert record_citing.id == result_record_cited.citer_id record_cited = InspireRecord.get_record_by_pid_value( record_cited_control_number, "lit") record_cited_citation_count = 1 assert record_cited_citation_count == record_cited.citation_count
def test_update_relations(inspire_app, celery_app_with_context, celery_session_worker): conference_data = faker.record("con", with_control_number=True) conference_record = InspireRecord.create(conference_data) data_cited = faker.record("lit", with_control_number=True) record_cited = InspireRecord.create(data_cited, disable_relations_update=True) db.session.commit() record_cited_control_number = record_cited["control_number"] conference_control_number = conference_record["control_number"] conf_ref = f"http://localhost:8000/api/conferences/{conference_control_number}" data = faker.record( "lit", literature_citations=[record_cited_control_number], with_control_number=True, ) data["publication_info"] = [{"conference_record": {"$ref": conf_ref}}] data["document_type"] = ["conference paper"] record = InspireRecord.create(data, disable_relations_update=True) db.session.commit() uuids = [record_cited.id, record.id] task = update_relations.delay(uuids) task.get(timeout=5) result_record_cited = RecordCitations.query.filter_by( cited_id=record_cited.id).one() assert record.id == result_record_cited.citer_id record_cited = InspireRecord.get_record_by_pid_value( record_cited_control_number, "lit") expected_record_cited_citation_count = 1 assert expected_record_cited_citation_count == record_cited.citation_count conf_paper = ConferenceLiterature.query.filter_by( conference_uuid=conference_record.id).one() assert conf_paper.literature_uuid == record.id