def test_useremailclaim_all(self): """ Test for retrieving all UserEmailClaim instances given an email address """ gail = models.User(username='******', fullname='Gail Hawthorne') peeta = models.User(username='******', fullname='Peeta Mallark') email = '*****@*****.**' claim_by_gail = models.UserEmailClaim(email=email, user=gail) claim_by_peeta = models.UserEmailClaim(email=email, user=peeta) db.session.add(claim_by_gail) db.session.add(claim_by_peeta) db.session.commit() result = models.UserEmailClaim.all(email) self.assertCountEqual(set(result), {claim_by_gail, claim_by_peeta})
def test_UserEmailClaim_all(self): """ Test for retrieving all UserEmailClaim instances given an email address """ gail = models.User(username=u'gail', fullname=u'Gail Hawthorne') peeta = models.User(username=u'peeta', fullname=u'Peeta Mallark') email = u'*****@*****.**' claim_by_gail = models.UserEmailClaim(email=email, user=gail) claim_by_peeta = models.UserEmailClaim(email=email, user=peeta) db.session.add(claim_by_gail) db.session.add(claim_by_peeta) db.session.commit() result = models.UserEmailClaim.all(email) self.assertIsInstance(result, list) self.assertItemsEqual(result, [claim_by_gail, claim_by_peeta])
def test_ownermixin_owner(self): """Test to verify setting of owner property on any OwnerMixin inherited instance""" crusoe = self.fixtures.crusoe # scenario 1: check owner of existing UserEmail instance crusoe_email = self.fixtures.crusoe_email self.assertEqual(crusoe_email.owner, crusoe) # scenario 2: check owner when owner is org client = self.fixtures.client batdog = self.fixtures.batdog dachshunds = self.fixtures.dachshunds self.assertEqual(client.owner, batdog) # scenaio 3: check owner when new UserEmailClaim instance spock = models.User(username=u'spock') spock_email_claim = models.UserEmailClaim( email=u'*****@*****.**', user=spock) self.assertEqual(spock_email_claim.owner, spock) # scenario 4: set user as owner on some OwnerMixin inherited instance spock_phone = models.UserPhoneClaim(phone=u'+9112345678', user=spock) spock_phone.owner = spock self.assertEqual(spock_phone.owner, spock) # scenario 5: set organization as owner on some OwnerMixin inherited instance spock_phone.owner = batdog self.assertEqual(spock_phone.owner, batdog) # scenario 6: set Team as owner on some OwnerMixin inherited instance spock_phone.owner = dachshunds self.assertEqual(spock_phone.owner, dachshunds) # scenario 7: when owner not insance of User, organization or Team with self.assertRaises(ValueError): spock_phone.owner = client
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_useremailclaim_email(self): """ Test for verifying UserEmailClaim email property """ effie = models.User(username=u'effie', fullname=u'Miss. Effie Trinket') email = u'*****@*****.**' claim_by_effie = models.UserEmailClaim(email=email, user=effie) self.assertIsInstance(claim_by_effie.email, unicode) self.assertEqual(claim_by_effie.email, email)
def test_UserEmailClaim(self): crusoe = self.fixtures.crusoe domain = u'batdogs.ca' new_email = u'crusoe@' + domain md5sum = md5(new_email).hexdigest() result = models.UserEmailClaim(email=new_email, user=crusoe) db.session.add(result) db.session.commit() self.assertIsInstance(result, models.UserEmailClaim) self.assertEqual(md5sum, result.md5sum) self.assertEqual(domain, result.domain) self.assertEqual(crusoe, result.user) assert u'<UserEmailClaim {email} of {user}>'.format( email=new_email, user=repr(crusoe)[1:-1]) in (repr(result))
def test_UserEmailClaim_get(self): """ Test for retrieving a UserEmailClaim instance given a user """ katnis = models.User(username=u'katnis', fullname=u'Katnis Everdeen') email = u'*****@*****.**' email_claim = models.UserEmailClaim(email=email, user=katnis) db.session.add(email_claim) db.session.commit() result = models.UserEmailClaim.get(email, katnis) self.assertIsInstance(result, models.UserEmailClaim) self.assertEqual(result.email, email) self.assertEqual(result.user, katnis)
def test_useremailclaim_permissions(self): """ Test for verifying whether user has verify permission on a UserEmailClaim instance """ crusoe = self.fixtures.crusoe email = u'*****@*****.**' email_claim = models.UserEmailClaim(email=email, user=crusoe) permissions_expected = ['verify'] result = email_claim.permissions(crusoe) self.assertIsInstance(result, set) permissions_received = [] for each in result: permissions_received.append(each) self.assertItemsEqual(permissions_expected, permissions_received)