def test_it_normalizes_email_address(email, restricted): email_address = EmailAddress(email, restricted) assert normalize(email_address) == { 'access': 'restricted' if restricted else 'public', 'value': email, }
def test_it_normalizes_affiliation(yesterday, restricted): address = Address(countries.get('gb'), 'City', 'Region') affiliation = Affiliation('1', address=address, organisation='Org', department='Dep', starts=yesterday, restricted=restricted) assert normalize(affiliation) == { 'access': 'restricted' if restricted else 'public', 'value': { "name": ["Dep", "Org"], "address": { "formatted": [ "City", "Region", "United Kingdom of Great Britain and Northern Ireland" ], "components": { "locality": ["City"], "area": ["Region"], "country": "United Kingdom of Great Britain and Northern Ireland" } } }, }
def test_it_normalizes_profile_with_single_email_address( id_, preferred, index, orcid, email): profile = Profile(id_, Name(preferred, index), orcid) profile.add_email_address(email) normalized_profile = normalize(profile) assert len(normalized_profile['emailAddresses']) == 1
def test_it_normalizes_profiles(id_, preferred, index): profile = Profile(id_, Name(preferred, index)) assert normalize(profile) == { 'id': id_, 'name': { 'preferred': preferred, 'index': index }, 'emailAddresses': [], 'affiliations': [] }
def test_it_normalizes_profile_with_multiple_email_addresses_with_primary_address_first( ): primary_address = '*****@*****.**' profile = Profile('12345678', Name('Foo Bar', 'Bar, Foo'), '0000-0002-1825-0097') profile.add_email_address('*****@*****.**') profile.add_email_address('*****@*****.**') profile.add_email_address(primary_address, primary=True) normalized_profile = normalize(profile) assert len(normalized_profile['emailAddresses']) == 3 assert normalized_profile['emailAddresses'][0]['value'] == primary_address
def test_it_normalizes_profile_with_orcid(): profile = Profile('12345678', Name('Foo Bar', 'Bar, Foo'), '0000-0002-1825-0097') assert normalize(profile) == { 'id': '12345678', 'name': { 'preferred': 'Foo Bar', 'index': 'Bar, Foo', }, 'emailAddresses': [], 'affiliations': [], 'orcid': '0000-0002-1825-0097' }
def test_it_normalizes_profile_with_an_affiliation(yesterday): address = Address(countries.get('gb'), 'City', 'Region') affiliation = Affiliation('1', address=address, organisation='Org', department='Dep', starts=yesterday) profile = Profile('12345678', Name('Foo Bar', 'Bar, Foo')) profile.add_affiliation(affiliation) assert normalize(profile) == { 'id': '12345678', 'name': { 'preferred': 'Foo Bar', 'index': 'Bar, Foo', }, 'emailAddresses': [], 'affiliations': [{ 'access': 'public', 'value': { "name": ["Dep", "Org"], "address": { "formatted": [ "City", "Region", "United Kingdom of Great Britain and Northern Ireland" ], "components": { "locality": ["City"], "area": ["Region"], "country": "United Kingdom of Great Britain and Northern Ireland" } } }, }] }
def test_it_normalizes_scalars(string, num): assert normalize(string) == string assert normalize(num) == num