def test_fix_entries_by_update_date(inspire_app, clean_celery_session): literature_data = faker.record("lit", with_control_number=True) literature_data.update({ "authors": [{ "full_name": "George, Smith", "ids": [{ "value": "Smith.G.1", "schema": "INSPIRE BAI" }], }] }) record_1 = InspireRecord.create(literature_data) literature_data_2 = faker.record("lit", with_control_number=True) literature_data_2.update({ "authors": [{ "full_name": "Xiu, Li", "ids": [{ "value": "X.Liu.1", "schema": "INSPIRE BAI" }], }] }) record_2 = InspireRecord.create(literature_data_2) db.session.add( RecordsAuthors( author_id="A.Test.1", id_type="INSPIRE BAI", record_id=record_1.id, )) db.session.add( RecordsAuthors( author_id="A.Test.2", id_type="INSPIRE BAI", record_id=record_2.id, )) db.session.commit() def assert_all_entries_in_db(): assert len(RecordsAuthors.query.all()) == 4 retry_until_pass(assert_all_entries_in_db) LiteratureRecord.fix_entries_by_update_date() def assert_all_entries_in_db(): assert len(RecordsAuthors.query.all()) == 2 retry_until_pass(assert_all_entries_in_db, retry_interval=3)
def generate_entries_for_collaborations_in_authors_records_table(self): """Generates RecordsAuthors objects table based on record data for collaborations""" collaborations_field = "collaborations.value" table_entries_buffer = [] for collaboration in self.get_value(collaborations_field, []): table_entries_buffer.append( RecordsAuthors( author_id=collaboration, id_type=AuthorSchemaType.collaboration.value, record_id=self.id, )) return table_entries_buffer
def generate_entries_for_authors_in_authors_records_table(self): """Generates RecordsAuthors objects table based on record data for authors""" authors_ids_field = "authors.ids" table_entries_buffer = [] for author in self.get_value(authors_ids_field, []): for id in author: try: table_entries_buffer.append( RecordsAuthors( author_id=id["value"], id_type=id["schema"], record_id=self.id, )) except KeyError: LOGGER.exception( "id entry is missing keys", recid=self.get("control_number"), uuid=str(self.id), ) return table_entries_buffer