def test_username_is_not_unique(self): ''' a username must not be the same as someone else's ''' new_user('jamesusername', 'James Smith', '*****@*****.**', '1') self.assertRaises(NameError, new_user, 'jamesusername', 'James Smith', '*****@*****.**', '2')
def create_and_return_local_user(self, username='******', googleID = '123'): ''' create a user with a default email address and formal name, return that object a helper function for tests that require a local (app) user to operate ''' new_user(username = username, email='*****@*****.**', formalName ='James Smith', googleID = googleID) return get_user_by_username(username)
def test_new_user_non_unique_username(self): ''' a new user with a username that already exists shoudl raise a NameError ''' new_user('jamesusername', 'James Smith', '*****@*****.**', '1') self.assertEqual(User.query().count(), 1) self.assertRaises(NameError, new_user, 'jamesusername', 'Bill Bradley', '*****@*****.**', '2') self.assertEqual(User.query().count(), 1)
def test_new_user_implementation(self): ''' test that the new user controller is working correctly ''' new_user('jamesusername', 'James Smith', '*****@*****.**', '12345678') self.assertEqual(User.query().count(), 1) new_user('foobar', 'James Smith', '*****@*****.**', '2') self.assertEqual(User.query().count(), 2)
def test_edit_existing_user(self): ''' test that the edit user function is working as it should ''' this_username = '******' new_user(this_username, 'James Smith', '*****@*****.**', '12345678') edit_user(this_username, formalName='Nathan Smith') user = get_user_by_username(this_username) self.assertEqual(user.formalName, 'Nathan Smith')
def test_new_user_non_unique_username(self): ''' a new user with a username that already exists shoudl raise a NameError ''' new_user('jamesusername', 'James Smith', '*****@*****.**', '1') self.assertEqual(User.query().count(), 1) self.assertRaises(NameError, new_user, 'jamesusername', 'Bill Bradley', '*****@*****.**', '2') self.assertEqual(User.query().count(), 1)
def test_new_user_implementation(self): ''' test that the new user controller is working correctly ''' new_user('jamesusername', 'James Smith', '*****@*****.**', '12345678') self.assertEqual(User.query().count(), 1) new_user('foobar', 'James Smith', '*****@*****.**', '2') self.assertEqual(User.query().count(), 2)
def test_username_is_not_unique(self): ''' a username must not be the same as someone else's ''' new_user('jamesusername', 'James Smith', '*****@*****.**', '1') self.assertRaises(NameError, new_user, 'jamesusername', 'James Smith', '*****@*****.**', '2')
def test_edit_existing_user(self): ''' test that the edit user function is working as it should ''' this_username = '******' new_user(this_username, 'James Smith', '*****@*****.**', '12345678') edit_user(this_username, formalName ='Nathan Smith') user = get_user_by_username(this_username) self.assertEqual(user.formalName, 'Nathan Smith')
def post(self, user_id = None): """ a post request is a NEW user """ parser = reqparse.RequestParser() parser.add_argument('formalName', type=str) parser.add_argument('username', type=str) parser.add_argument('sponsorCode', type=str) args = parser.parse_args() try: email = users.get_current_user().email() sponsor_code = args['sponsorCode'] if sponsor_code and sponsor_code != '': if not verify_code(sponsor_code): raise NameError('Invalid Sponsor Code') validate_username(args['username']) user = new_user( username = args['username'], formalName = args['formalName'], email = email, googleID = users.get_current_user().user_id() ) if not user: raise NameError('There was a problem creating your user account, please try again') new_customer( email = email, user = user, coupon_code = sponsor_code ) except Exception as e: logging.info(e) return {"error" : str(e) } else: return {"success" : "user successfully created"}
def post(self, user_id=None): """ a post request is a NEW user """ parser = reqparse.RequestParser() parser.add_argument('formalName', type=str) parser.add_argument('username', type=str) parser.add_argument('sponsorCode', type=str) args = parser.parse_args() try: email = users.get_current_user().email() sponsor_code = args['sponsorCode'] if sponsor_code and sponsor_code != '': if not verify_code(sponsor_code): raise NameError('Invalid Sponsor Code') validate_username(args['username']) user = new_user(username=args['username'], formalName=args['formalName'], email=email, googleID=users.get_current_user().user_id()) if not user: raise NameError( 'There was a problem creating your user account, please try again' ) new_customer(email=email, user=user, coupon_code=sponsor_code) except Exception as e: logging.info(e) return {"error": str(e)} else: return {"success": "user successfully created"}