def test_add_keyword(): expected = { '_collections': ['Conferences'], 'keywords': [{ 'schema': 'INSPIRE', 'source': 'arxiv', 'value': '29.27.Fh' }] } builder = ConferenceBuilder() builder.add_keyword('29.27.Fh', schema='INSPIRE', source='arxiv') assert builder.record == expected
def build_conference(self, data) -> dict: """Process data from form and build a conference record. Args: data (ConferenceRecord): record to serialize Return: dict: a conference record """ builder = ConferenceBuilder() builder.add_title(title=data.get("name"), subtitle=data.get("subtitle")) builder.set_short_description(value=data.get("description", "")) builder.set_opening_date(get_value(data, "dates[0]")) builder.set_closing_date(get_value(data, "dates[1]")) builder.add_inspire_categories(data.get("field_of_interest", [])) builder.add_public_note(value=data.get("additional_info", "")) builder.add_series( name=data.get("series_name"), number=data.get("series_number") ) for address in data.get("addresses"): builder.add_address( cities=[address.get("city")], state=address.get("state"), place_name=address.get("venue"), country_code=country_name_to_code(address.get("country")), ) for contact in data.get("contacts", []): builder.add_contact(**contact) for acr in data.get("acronyms", []): builder.add_acronym(acr) for website in data.get("websites", []): builder.add_url(website) for keyword in data.get("keywords", []): builder.add_keyword(value=keyword) builder.record["$schema"] = url_for( "invenio_jsonschemas.get_schema", schema_path="records/conferences.json", _external=True, ) return builder.record
def test_conference_builder(conference_data): builder = ConferenceBuilder() private_notes = conference_data['_private_notes'] builder.add_private_note(**private_notes[0]) builder.add_private_note(**private_notes[1]) builder.add_private_note(**private_notes[2]) builder.add_private_note(**private_notes[3]) builder.add_acronym(conference_data['acronyms'][0]) builder.add_address(**conference_data['addresses'][0]) alternative_titles = conference_data['alternative_titles'] builder.add_alternative_title(**alternative_titles[0]) builder.add_alternative_title(**alternative_titles[1]) builder.add_alternative_title(**alternative_titles[2]) builder.set_cnum(cnum=conference_data['cnum']) contact_details = conference_data['contact_details'] builder.add_contact(**contact_details[0]) builder.add_contact(**contact_details[1]) builder.add_contact(**contact_details[2]) builder.add_contact(**contact_details[3]) builder.set_core(conference_data['core']) external_ids = conference_data['external_system_identifiers'] builder.add_external_system_identifier(**external_ids[0]) builder.add_external_system_identifier(**external_ids[1]) builder.add_external_system_identifier(**external_ids[2]) builder.add_external_system_identifier(**external_ids[3]) inspire_cats = ["Gravitation and Cosmology", "General Physics"] builder.add_inspire_categories(subject_terms=inspire_cats, source="user") builder.add_inspire_categories(subject_terms=["Math and Math Physics"], source="curator") builder.add_inspire_categories(subject_terms=["Astrophysics"], source="magpie") keywords = conference_data['keywords'] builder.add_keyword(**keywords[0]) builder.add_keyword(**keywords[1]) public_notes = conference_data['public_notes'] builder.add_public_note(**public_notes[0]) builder.add_public_note(**public_notes[1]) builder.add_public_note(**public_notes[2]) builder.add_public_note(**public_notes[3]) series = conference_data['series'] builder.add_series(**series[0]) builder.add_series(**series[1]) builder.set_short_description(**conference_data['short_description']) builder.set_closing_date(conference_data['closing_date']) builder.set_opening_date(conference_data['opening_date']) titles = conference_data['titles'] for title in titles: builder.add_title(**title) urls = conference_data['urls'] for url in urls: builder.add_url(**url) builder.validate_record() assert builder.record == conference_data