def test_user_del_email(self): """ Test to delete email address for a user """ mr_jones = models.User(username='******') mr_jones_primary_email = models.UserEmail( email='*****@*****.**', user=mr_jones, primary=True) mr_jones_secondary_email = models.UserEmail( email='*****@*****.**', user=mr_jones) mr_jones_spare_email = models.UserEmail(email='*****@*****.**', user=mr_jones) db.session.add_all([ mr_jones, mr_jones_primary_email, mr_jones_secondary_email, mr_jones_spare_email, ]) db.session.commit() # scenario 1: when email requested to be deleted is primary primary_email = mr_jones_primary_email.email mr_jones.del_email(primary_email) db.session.commit() result1 = mr_jones.emails self.assertIsInstance(result1, list) self.assertCountEqual(result1, [mr_jones_secondary_email, mr_jones_spare_email]) self.assertTrue(mr_jones_secondary_email.primary) # scenario 2: when email requested to be delete is not primary spare_email = mr_jones_spare_email.email mr_jones.del_email(spare_email) db.session.commit() result2 = mr_jones.emails self.assertIsInstance(result2, list) self.assertCountEqual(result2, [mr_jones_secondary_email]) self.assertTrue(mr_jones_secondary_email.primary)
def test_getuser(self): """ Test for retrieving username by prepending @ """ # scenario 1: with @ starting in name and extid crusoe = self.fixtures.crusoe service_twitter = 'twitter' oauth_token = environ.get('TWITTER_OAUTH_TOKEN') oauth_token_type = 'Bearer' # NOQA: S105 externalid = models.UserExternalId( service=service_twitter, user=crusoe, userid=crusoe.email.email, username=crusoe.username, oauth_token=oauth_token, oauth_token_type=oauth_token_type, ) db.session.add(externalid) db.session.commit() result1 = models.getuser('@crusoe') self.assertIsInstance(result1, models.User) self.assertEqual(result1, crusoe) # scenario 2: with @ in name and not extid d_email = '*****@*****.**' daenerys = models.User( username='******', fullname="Daenerys Targaryen", email=d_email ) daenerys_email = models.UserEmail(email=d_email, user=daenerys) db.session.add_all([daenerys, daenerys_email]) db.session.commit() result2 = models.getuser(d_email) self.assertIsInstance(result2, models.User) self.assertEqual(result2, daenerys) result3 = models.getuser('@daenerys') self.assertIsNone(result3) # scenario 3: with no @ starting in name, check by UserEmailClaim j_email = '*****@*****.**' jonsnow = models.User(username='******', fullname="Jon Snow") jonsnow_email_claimed = models.UserEmailClaim(email=j_email, user=jonsnow) db.session.add_all([jonsnow, jonsnow_email_claimed]) db.session.commit() result4 = models.getuser(j_email) self.assertIsInstance(result4, models.User) self.assertEqual(result4, jonsnow) # scenario 5: with no @ anywhere in name, fetch username arya = models.User(username='******', fullname="Arya Stark") db.session.add(arya) db.session.commit() result5 = models.getuser('arya') self.assertEqual(result5, arya) # scenario 6: with no starting with @ name and no UserEmailClaim or UserEmail cersei = models.User(username='******', fullname="Cersei Lannister") db.session.add(cersei) db.session.commit() result6 = models.getuser('*****@*****.**') self.assertIsNone(result6)
def test_useremail_unicode(self): """ Test for verifying email is returned in unicode format """ crusoe = self.fixtures.crusoe email = crusoe.email.email result = str(models.UserEmail(email=email)) self.assertIsInstance(result, str) assert email in result
def test_useremail_email(self): """ Test for verifying UserEmail instance's email property """ oakley = self.fixtures.oakley email = '*****@*****.**' oakley_new_email = models.UserEmail(email=email, user=oakley) result = oakley_new_email.email self.assertIsInstance(result, str) self.assertEqual(email, result)
def test_user_email(self): """ Test to retrieve UserEmail property email """ # scenario 1: when there is primary email address crusoe = self.fixtures.crusoe self.assertIsInstance(crusoe.email, models.UserEmail) self.assertEqual(crusoe.email, crusoe.email) # scenario 2: when there is no primary email address mr_pilkington = models.User(username='******') mr_pilkington_email = models.UserEmail( user=mr_pilkington, email='*****@*****.**') db.session.add_all([mr_pilkington, mr_pilkington_email]) db.session.commit() self.assertEqual(mr_pilkington.email.email, mr_pilkington_email.email) self.assertTrue(mr_pilkington.email.primary) # scenario 3: when no email address is on db clover = models.User(username='******') db.session.add(clover) db.session.commit() self.assertEqual(clover.email, '')