def test_add_institution_sorts_by_current(): schema = load_schema('authors') subschema = schema['properties']['positions'] author = AuthorBuilder() author.add_institution(institution='Colgate University', start_date='1994-02-01') author.add_institution(institution='First University', start_date='1950-02-01', current=True) expected = [ { "institution": 'First University', "start_date": u'1950-02-01', "curated_relation": False, "current": True }, { "institution": 'Colgate University', "start_date": u'1994-02-01', "curated_relation": False, "current": False }, ] result = author.obj['positions'] assert validate(result, subschema) is None assert expected == result
def test_add_institution(): schema = load_schema('authors') subschema = schema['properties']['positions'] author = AuthorBuilder() author.add_institution(institution='Colgate University', start_date='1994-02-01', end_date='1995-01-31', rank='PHD', record={"$ref": "http://180"}, curated=True, current=False) expected = [{ "institution": 'Colgate University', "start_date": u'1994-02-01', "end_date": u'1995-01-31', "rank": 'PHD', "record": { "$ref": "http://180" }, "curated_relation": True, "current": False }] result = author.obj['positions'] assert validate(result, subschema) is None assert expected == result
def test_add_institution_normalizes_end_date(): schema = load_schema('authors') subschema = schema['properties']['positions'] author = AuthorBuilder() author.add_institution(institution='Colgate University', end_date='31 January 2005') expected = [{ "institution": 'Colgate University', "end_date": u'2005-01-31', "curated_relation": False, "current": False }] result = author.obj['positions'] assert validate(result, subschema) is None assert expected == result
def test_add_institution_normalizes_start_date(): schema = load_schema('authors') subschema = schema['properties']['positions'] author = AuthorBuilder() author.add_institution(institution='Colgate University', start_date='February 1 1994') expected = [{ "institution": 'Colgate University', "start_date": u'1994-02-01', "curated_relation": False, "current": False }] result = author.obj['positions'] assert validate(result, subschema) is None assert expected == result
def build_author(self, data): author = AuthorBuilder() for advisor in data.get('advisors', []): author.add_advisor(**advisor) for arxiv_category in data.get('arxiv_categories', []): author.add_arxiv_category(arxiv_category) blog = data.get('blog') author.add_blog(blog) comments = data.get('comments') author.add_private_note(comments) display_name = data.get('display_name') author.set_display_name(display_name) given_name = data.get('given_name') family_name = data.get('family_name') full_name = self.get_full_name(family_name, given_name) author.set_name(full_name) linkedin = data.get('linkedin') author.add_linkedin(linkedin) orcid = data.get('orcid') author.add_orcid(orcid) bai = data.get('bai') author.add_bai(bai) native_name = data.get('native_name') author.add_native_name(native_name) for position in data.get('positions', []): institution = position.get('institution') start_date = position.get('start_date') end_date = position.get('end_date') rank = position.get('rank') record = position.get('record') curated_relation = position.get('curated_relation', False) current = position.get('current', False) author.add_institution( institution, start_date=start_date, end_date=end_date, rank=rank, record=record, curated=curated_relation, current=current ) for project in data.get('project_membership', []): name = project.get('name') record = project.get('record') start_date = project.get('start_date') end_date = project.get('end_date') curated_relation = project.get('curated_relation', False) current = project.get('current', False) author.add_project( name, record=record, start_date=start_date, end_date=end_date, curated=curated_relation, current=current ) for email in data.get('public_emails', []): author.add_email_address(email) status = data.get('status') author.set_status(status) twitter = data.get('twitter') author.add_twitter(twitter) for website in data.get('websites', []): author.add_url(website) acquisition_source = data.get('acquisition_source') if acquisition_source: method = acquisition_source.get('method') submission_number = acquisition_source.get('submission_number') internal_uid = acquisition_source.get('internal_uid') email = acquisition_source.get('email') orcid = acquisition_source.get('orcid') source = acquisition_source.get('source') datetime = acquisition_source.get('datetime') author.add_acquisition_source( method, submission_number=submission_number, internal_uid=internal_uid, email=email, orcid=orcid, source=source, datetime=datetime, ) return author.obj
def build_author(self, data): author = AuthorBuilder() for advisor in data.get("advisors", []): curated = advisor.pop("curated_relation", False) author.add_advisor(**advisor, curated=curated) for arxiv_category in data.get("arxiv_categories", []): author.add_arxiv_category(arxiv_category) blog = data.get("blog") author.add_blog(blog) comments = data.get("comments") author.add_private_note(comments) display_name = data.get("display_name") author.set_display_name(display_name) given_name = data.get("given_name") family_name = data.get("family_name") full_name = self.get_full_name(family_name, given_name) author.set_name(full_name) alternate_name = data.get("alternate_name") author.add_name_variant(alternate_name) linkedin = data.get("linkedin") author.add_linkedin(linkedin) orcid = data.get("orcid") author.add_orcid(orcid) bai = data.get("bai") author.add_bai(bai) native_name = data.get("native_name") author.add_native_name(native_name) for position in data.get("positions", []): curated = position.pop("curated_relation", False) author.add_institution(**position, curated=curated) for project in data.get("project_membership", []): curated = project.pop("curated_relation", False) author.add_project(**project, curated=curated) for email in data.get("emails", []): author.add_email_address( email.get("value"), current=email.get("current"), hidden=email.get("hidden"), ) status = data.get("status") author.set_status(status) twitter = data.get("twitter") author.add_twitter(twitter) for website in data.get("websites", []): author.add_url(website) acquisition_source = data.get("acquisition_source") if acquisition_source: method = acquisition_source.get("method") submission_number = acquisition_source.get("submission_number") internal_uid = acquisition_source.get("internal_uid") email = acquisition_source.get("email") orcid = acquisition_source.get("orcid") source = acquisition_source.get("source") datetime = acquisition_source.get("datetime") author.add_acquisition_source( method, submission_number=submission_number, internal_uid=internal_uid, email=email, orcid=orcid, source=source, datetime=datetime, ) return author.obj
def test_add_institution_sorts_by_rank(): schema = load_schema('authors') subschema = schema['properties']['positions'] author = AuthorBuilder() author.add_institution(institution='Colgate University', rank='MASTER') author.add_institution(institution='Colgate University', rank='PHD') author.add_institution(institution='Colgate University', rank='VISITOR') author.add_institution(institution='Colgate University', rank='STAFF') author.add_institution(institution='Colgate University', rank='SENIOR') author.add_institution(institution='Colgate University', rank='OTHER') author.add_institution(institution='Colgate University', rank='UNDERGRADUATE') author.add_institution(institution='Colgate University') author.add_institution(institution='Colgate University', rank='POSTDOC') author.add_institution(institution='Colgate University', rank='JUNIOR') expected = [ { "institution": 'Colgate University', "rank": 'STAFF', "curated_relation": False, "current": False }, { "institution": 'Colgate University', "rank": 'SENIOR', "curated_relation": False, "current": False }, { "institution": 'Colgate University', "rank": 'JUNIOR', "curated_relation": False, "current": False }, { "institution": 'Colgate University', "rank": 'VISITOR', "curated_relation": False, "current": False }, { "institution": 'Colgate University', "rank": 'POSTDOC', "curated_relation": False, "current": False }, { "institution": 'Colgate University', "rank": 'PHD', "curated_relation": False, "current": False }, { "institution": 'Colgate University', "rank": 'MASTER', "curated_relation": False, "current": False }, { "institution": 'Colgate University', "rank": 'UNDERGRADUATE', "curated_relation": False, "current": False }, { "institution": 'Colgate University', "rank": 'OTHER', "curated_relation": False, "current": False }, { "institution": 'Colgate University', "curated_relation": False, "current": False }, ] result = author.obj['positions'] assert validate(result, subschema) is None assert expected == result