def test_get_by_email(): uc = UserCache() uc.update('David Bowie') uc.update('David Robert Jones <*****@*****.**>') uc.update('David Bowie <*****@*****.**>') uc.update('*****@*****.**') assert uc.get('*****@*****.**')['email'] == '*****@*****.**'
def test_different_names_with_the_same_email(): uc = UserCache() uc.update('David Bowie') uc.update('David Robert Jones <*****@*****.**>') uc.update('David Bowie <*****@*****.**>') uc.update('David Robert Jones') uc.update('Bowie David <*****@*****.**>') users = uc.all() assert len(users) == 1 and users[0]['email'] == '*****@*****.**'
def test_merge_full_and_email(): uc = UserCache() uc.update('David Bowie <*****@*****.**>') uc.update('*****@*****.**') assert uc.all() == [{ 'first_name': 'David', 'last_name': 'Bowie', 'email': '*****@*****.**' }]
def test_get_by_full(): uc = UserCache() uc.update('*****@*****.**') uc.update('David Bowie <*****@*****.**>') assert uc.get('David Bowie <*****@*****.**>') == { 'first_name': 'David', 'last_name': 'Bowie', 'email': '*****@*****.**' }
def build_user_cache(rawdata): """ Go over all scm data to build a full UserCache """ uc = UserCache() for typ, data in rawdata: for role in ROLES & set(data.keys()): for ustring in data[role]: uc.update(ustring) return uc
def test_cannot_merge_name_and_email(): uc = UserCache() uc.update('David Bowie') uc.update('*****@*****.**') assert uc.all() == [ { 'first_name': '', 'last_name': '', 'email': '*****@*****.**' }, ]
def test_user_without_email_will_be_ignored(): uc = UserCache() uc.update('Brian May') uc.update('Roger Taylor') uc.update('Freddie Mercury <*****@*****.**>') assert uc.get('Brian May') is None assert uc.all() == [{ 'first_name': 'Freddie', 'last_name': 'Mercury', 'email': '*****@*****.**' }]
def test_cannot_merge_diff_emails(): uc = UserCache() uc.update('*****@*****.**') uc.update('*****@*****.**') assert uc.all() == [ { 'first_name': '', 'last_name': '', 'email': '*****@*****.**' }, { 'first_name': '', 'last_name': '', 'email': '*****@*****.**' }, ]
def test_cannot_merge_diff_names(): uc = UserCache() uc.update('Eric Clapton') uc.update('Eric Johnson') assert uc.all() == []