def test_author_urls(can_edit, populate_students_field): can_edit.return_value = False populate_students_field.return_value = [] schema = AuthorsDetailSchema() data = { "ids": [{ "schema": "WIKIPEDIA", "value": "John_Ellis_(physicist)" }], "urls": [{ "value": "https://www.kcl.ac.uk/nms/depts/physics/people/academicstaff/ellis.aspx" }], } author = faker.record("aut", data=data, with_control_number=True) expected_wikipedia_url = "https://en.wikipedia.org/wiki/John_Ellis_(physicist)" expected_wikipedia = "Wikipedia" result = schema.dumps(author).data result_data = orjson.loads(result) result_urls = result_data.get("urls") assert expected_wikipedia_url in result_urls[1].get("value") assert expected_wikipedia in result_urls[1].get("description")
def test_returns_should_display_position_false_if_position_is_current(): schema = AuthorsDetailSchema() data = { "name": { "value": "Doe, John", "preferred_name": "J Doe" }, "ids": [{ "schema": "INSPIRE BAI", "value": "John.Doe.1" }], "positions": [{ "institution": "CERN", "current": True }], } author = faker.record("aut", data=data) expected_result = False result = schema.dumps(author).data result_data = json.loads(result) result_should_display_positions = result_data.get( "should_display_positions") assert expected_result == result_should_display_positions
def test_author_advisors_has_first_and_last_names(): schema = AuthorsDetailSchema() data = { "advisors": [ { "degree_type": "other", "ids": [{"schema": "INSPIRE ID", "value": "INSPIRE-00100407"}], "name": "Stenger, Victor J.", }, {"degree_type": "other", "name": "Learned, John Gregory"}, ] } author = faker.record("aut", data=data, with_control_number=True) expected_advisors = [ { "first_name": "Victor J.", "last_name": "Stenger", "degree_type": "other", "name": "Stenger, Victor J.", "ids": [{"schema": "INSPIRE ID", "value": "INSPIRE-00100407"}], }, { "first_name": "John Gregory", "last_name": "Learned", "degree_type": "other", "name": "Learned, John Gregory", }, ] result = schema.dumps(author).data result_data = json.loads(result) result_advisors = result_data.get("advisors") assert expected_advisors == result_advisors
def test_should_display_positions_with_multiple_positions_with_start_date(): schema = AuthorsDetailSchema() data = { "name": { "value": "Doe, John", "preferred_name": "J Doe" }, "ids": [{ "schema": "INSPIRE BAI", "value": "John.Doe.1" }], "positions": [{ "institution": "CERN", "start_date": "2015", "current": True }], } author = faker.record("aut", data=data, with_control_number=True) expected_result = True result = schema.dumps(author).data result_data = json.loads(result) result_should_display_positions = result_data.get( "should_display_positions") assert expected_result == result_should_display_positions
def test_should_display_positions_with_multiple_positions_with_rank( can_edit, populate_students_field): can_edit.return_value = False populate_students_field.return_value = [] schema = AuthorsDetailSchema() data = { "name": { "value": "Doe, John", "preferred_name": "J Doe" }, "ids": [{ "schema": "INSPIRE BAI", "value": "John.Doe.1" }], "positions": [{ "institution": "CERN", "rank": "PHD", "current": True }], } author = faker.record("aut", data=data, with_control_number=True) expected_result = True result = schema.dumps(author).data result_data = orjson.loads(result) result_should_display_positions = result_data.get( "should_display_positions") assert expected_result == result_should_display_positions
def test_author_does_not_have_id_fields(): schema = AuthorsDetailSchema() author = faker.record("aut") result = schema.dumps(author).data result_data = json.loads(result) assert "linkedin" not in result_data assert "twitter" not in result_data assert "orcid" not in result_data
def test_facet_author_name_without_ids(): schema = AuthorsDetailSchema() data = {"name": {"value": "Doe, John"}} author = faker.record("aut", data=data) expected_result = "BAI_John Doe" result = schema.dumps(author).data result_data = json.loads(result) result_facet_author_name = result_data.get("facet_author_name") assert expected_result == result_facet_author_name
def test_author_linkedin(): schema = AuthorsDetailSchema() data = {"ids": [{"value": "harunurhan", "schema": "LINKEDIN"}]} author = faker.record("aut", data=data, with_control_number=True) expected_linkedin = "harunurhan" result = schema.dumps(author).data result_data = json.loads(result) result_linkedin = result_data.get("linkedin") assert expected_linkedin == result_linkedin
def test_author_orcid(): schema = AuthorsDetailSchema() data = {"ids": [{"value": "0000-0001-8058-0014", "schema": "ORCID"}]} author = faker.record("aut", data=data, with_control_number=True) expected_orcid = "0000-0001-8058-0014" result = schema.dumps(author).data result_data = json.loads(result) result_orcid = result_data.get("orcid") assert expected_orcid == result_orcid
def test_author_bai(): schema = AuthorsDetailSchema() data = {"ids": [{"schema": "INSPIRE BAI", "value": "John.Doe.1"}]} author = faker.record("aut", data=data, with_control_number=True) expected_bai = "John.Doe.1" result = schema.dumps(author).data result_data = json.loads(result) result_bai = result_data.get("bai") assert expected_bai == result_bai
def test_author_twitter(): schema = AuthorsDetailSchema() data = {"ids": [{"value": "harunurhan", "schema": "TWITTER"}]} author = faker.record("aut", data=data, with_control_number=True) expected_twitter = "harunurhan" result = schema.dumps(author).data result_data = json.loads(result) result_twitter = result_data.get("twitter") assert expected_twitter == result_twitter
def test_author_orcid(can_edit, populate_students_field): can_edit.return_value = False populate_students_field.return_value = [] schema = AuthorsDetailSchema() data = {"ids": [{"value": "0000-0001-8058-0014", "schema": "ORCID"}]} author = faker.record("aut", data=data, with_control_number=True) expected_orcid = "0000-0001-8058-0014" result = schema.dumps(author).data result_data = orjson.loads(result) result_orcid = result_data.get("orcid") assert expected_orcid == result_orcid
def test_author_bai(can_edit, populate_students_field): can_edit.return_value = False populate_students_field.return_value = [] schema = AuthorsDetailSchema() data = {"ids": [{"schema": "INSPIRE BAI", "value": "John.Doe.1"}]} author = faker.record("aut", data=data, with_control_number=True) expected_bai = "John.Doe.1" result = schema.dumps(author).data result_data = orjson.loads(result) result_bai = result_data.get("bai") assert expected_bai == result_bai
def test_author_does_not_have_id_fields(can_edit, populate_students_field): can_edit.return_value = False populate_students_field.return_value = [] schema = AuthorsDetailSchema() author = faker.record("aut", with_control_number=True) result = schema.dumps(author).data result_data = orjson.loads(result) assert "linkedin" not in result_data assert "twitter" not in result_data assert "orcid" not in result_data assert "bai" not in result_data
def test_author_linkedin(can_edit, populate_students_field): can_edit.return_value = False populate_students_field.return_value = [] schema = AuthorsDetailSchema() data = {"ids": [{"value": "harunurhan", "schema": "LINKEDIN"}]} author = faker.record("aut", data=data, with_control_number=True) expected_linkedin = "harunurhan" result = schema.dumps(author).data result_data = orjson.loads(result) result_linkedin = result_data.get("linkedin") assert expected_linkedin == result_linkedin
def test_facet_author_name_with_preferred_name_and_control_number(): schema = AuthorsDetailSchema() data = { "name": {"value": "Doe, John", "preferred_name": "J Doe"}, "control_number": 1, } author = faker.record("aut", data=data) expected_result = "1_J Doe" result = schema.dumps(author).data result_data = json.loads(result) result_facet_author_name = result_data.get("facet_author_name") assert expected_result == result_facet_author_name
def test_should_display_positions_without_positions(): schema = AuthorsDetailSchema() data = { "name": {"value": "Doe, John", "preferred_name": "J Doe"}, "ids": [{"schema": "INSPIRE BAI", "value": "John.Doe.1"}], } author = faker.record("aut", data=data, with_control_number=True) expected_result = False result = schema.dumps(author).data result_data = json.loads(result) result_should_display_positions = result_data.get("should_display_positions") assert expected_result == result_should_display_positions
def test_facet_author_name_without_preferred_name(can_edit, populate_students_field): can_edit.return_value = False populate_students_field.return_value = [] schema = AuthorsDetailSchema() data = {"name": {"value": "Doe, John"}, "control_number": 1} author = faker.record("aut", data=data) expected_result = "1_John Doe" result = schema.dumps(author).data result_data = orjson.loads(result) result_facet_author_name = result_data.get("facet_author_name") assert expected_result == result_facet_author_name
def test_only_public_and_current_emails(): schema = AuthorsDetailSchema() data = { "email_addresses": [ {"value": "*****@*****.**", "current": True, "hidden": True}, {"value": "*****@*****.**", "current": True, "hidden": False}, {"value": "*****@*****.**", "current": False, "hidden": False}, {"value": "*****@*****.**", "current": False, "hidden": True}, ] } author = faker.record("aut", data=data, with_control_number=True) expected_email_addresses = [ {"value": "*****@*****.**", "current": True, "hidden": False} ] result = schema.dumps(author).data result_data = json.loads(result) result_email_addresses = result_data.get("email_addresses") assert expected_email_addresses == result_email_addresses
def test_facet_author_name_without_preferred_name(): schema = AuthorsDetailSchema() data = { "name": { "value": "Doe, John" }, "ids": [{ "schema": "INSPIRE BAI", "value": "John.Doe.1" }], } author = faker.record("aut", data=data) expected_result = "John.Doe.1_John Doe" result = schema.dumps(author).data result_data = json.loads(result) result_facet_author_name = result_data.get("facet_author_name") assert expected_result == result_facet_author_name