def test_api_bill_post(self): self.login(self.get_default_test_username(), self.get_default_test_password()) benchmark = 0.015 y = 100 t0 = time.time() for x in range(0, y): self.apiCreateNewBill(testUtils.random_name_generator(), testUtils.random_number_generator()) t1 = time.time() total1 = t1-t0 t0 = time.time() for x in range(0, y): self.apiCreateNewBill(testUtils.random_name_generator(), testUtils.random_number_generator()) t1 = time.time() total2 = t1-t0 t0 = time.time() for x in range(0, y): self.apiCreateNewBill(testUtils.random_name_generator(), testUtils.random_number_generator()) t1 = time.time() total3 = t1-t0 average = ((total1/y)+(total2/y)+(total3/y))/3 print("Bill Average: " + str(average)) print("Bill Percent Variance: "+ str(testUtils.percent_difference(benchmark,average))+"%") assert testUtils.percent_difference(benchmark,average) < 10 self.logout()
def setUp(self): self.set_default_test_password(testUtils.random_password_generator()) self.set_default_test_name("~~~" + testUtils.random_name_generator() + "~~~") self.set_default_test_username(testUtils.random_email_generator()) self.set_default_test_date(datetime.utcnow()) application.debug = False application.config['TESTING'] = True self.app = application.test_client() init_db() newUser = self.createNewUser(email=self.get_default_test_username(), new_password=self.get_default_test_password(), first_name=self.get_default_test_name(), last_name=self.get_default_test_name(), active=True, confirmed_at=True, next_pay_date=True) self.set_user_id(newUser.id)
def apiCreateNewUser(self, **kwargs): password = kwargs.get('new_password') confirm_password = kwargs.get('confirm_new_password') email = kwargs.get('email') next_pay_date = kwargs.get('next_pay_date') pay_recurrance_flag = kwargs.get('pay_recurrance_flag') confirmed_at = kwargs.get('confirmed_at') if email is None: email = testUtils.random_name_generator() if password is None and confirm_password is None: val = testUtils.random_password_generator() password = val confirm_password = val if password == self.get_default_test_password() and confirm_password is None: confirm_password = self.get_default_test_password() if isinstance(next_pay_date, datetime): next_pay_date = next_pay_date elif next_pay_date is True: next_pay_date = self.get_default_test_date() elif next_pay_date is False: next_pay_date = None else: next_pay_date = self.get_default_test_date() if pay_recurrance_flag is None: pay_recurrance_flag = "B" if isinstance(confirmed_at, datetime): confirmed_at = confirmed_at if confirmed_at: confirmed_at = self.get_default_test_date() else: confirmed_at = None return self.app.post('api/me/', data=json.dumps( {'email':email, 'confirm_email':email, 'new_password':password, 'confirm_new_password':confirm_password, 'first_name': self.get_default_test_name(), 'last_name': self.get_default_test_name(), 'confirmed_at': testUtils.dump_date(confirmed_at), 'pay_recurrance_flag': pay_recurrance_flag, 'next_pay_date': testUtils.dump_date(next_pay_date)}), content_type='application/json')
def test_api_me_post_success(self): self.login(self.get_default_test_username(), self.get_default_test_password()) self.pr = cProfile.Profile() self.pr.enable() #CREATING y BILLS for x in range(0, 100): self.apiCreateNewBill(testUtils.random_name_generator(), testUtils.random_number_generator()) p = Stats (self.pr) p.strip_dirs() p.sort_stats ('cumtime') p.print_stats () self.logout()