def test_process_crossref_name(self, crossref_client): contributor = AuthUserFactory() # Given name and no family name contributor.given_name = 'Hey' contributor.family_name = '' contributor.save() meta = crossref_client._process_crossref_name(contributor) imputed_names = impute_names(contributor.fullname) assert meta == {'surname': imputed_names['family'], 'given_name': imputed_names['given']} # Just one name contributor.fullname = 'Ke$ha' contributor.given_name = '' contributor.family_name = '' contributor.save() meta = crossref_client._process_crossref_name(contributor) assert meta == {'surname': contributor.fullname} # Number and ? in given name contributor.fullname = 'Scotty2Hotty? Ronald Garland II' contributor.given_name = '' contributor.family_name = '' contributor.save() meta = crossref_client._process_crossref_name(contributor) assert meta == {'given_name': 'ScottyHotty Ronald', 'surname': 'Garland', 'suffix': 'II'} # Long suffix is truncated to 10 characters long_suffix = 'PhD MD Esq MPH IV' contributor.given_name = 'Mark' contributor.family_name = 'Henry' contributor.suffix = long_suffix contributor.save() meta = crossref_client._process_crossref_name(contributor) assert meta['suffix'] == long_suffix[:crossref.CROSSREF_SUFFIX_LIMIT] # Long given_names and surnames are truncated to limit long_given = 'Maaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaark' long_surname = 'Henryyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy' contributor.given_name = long_given contributor.family_name = long_surname contributor.save() meta = crossref_client._process_crossref_name(contributor) assert meta['given_name'] == long_given[:crossref.CROSSREF_GIVEN_NAME_LIMIT] assert meta['surname'] == long_surname[:crossref.CROSSREF_SURNAME_LIMIT] # Unparsable given or surname just returns fullname as surname unparsable_fullname = 'Author (name withheld until double-blind peer review completes and this name is also really long)' contributor.given_name = '' contributor.family_name = '' contributor.fullname = unparsable_fullname contributor.save() meta = crossref_client._process_crossref_name(contributor) assert meta == {'surname': unparsable_fullname[:crossref.CROSSREF_SURNAME_LIMIT]}
def user(self): user = AuthUserFactory() user.fullname = user.fullname + ',a' user.save() return user