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"}
def test_new_customer_with_valid_card(self): ''' a new customer with a valid card should be created on stripe with a successfuly response ''' stripeToken = self.generate_sample_token() user = self.create_and_return_local_user() self.assertIsNone(user.stripeID) #should have no stripe ID before self.assertTrue(new_customer(stripeToken, "*****@*****.**", user)) self.assertIn('cus_', user.stripeID) #should have a stripe ID afterwards
def test_new_customer_with_valid_card(self): ''' a new customer with a valid card should be created on stripe with a successfuly response ''' stripeToken = self.generate_sample_token() user = self.create_and_return_local_user() self.assertIsNone(user.stripeID) #should have no stripe ID before self.assertTrue(new_customer(stripeToken, "*****@*****.**", user)) self.assertIn('cus_', user.stripeID) #should have a stripe ID afterwards
def test_new_customer_with_none_user(self): ''' a new customer call without passing a user should not trigger a stripe customer creation ''' self.assertFalse( new_customer(stripeToken='', email='*****@*****.**', user=None))
def test_new_customer_with_none_user(self): ''' a new customer call without passing a user should not trigger a stripe customer creation ''' self.assertFalse(new_customer(stripeToken='', email='*****@*****.**', user=None))