def test_user_registration(self): tester=app.test_client(self) db.drop_all() db.create_all() tester.post('/registration',data=dict(username='******', email='*****@*****.**', password='******', confirm_password='******')) response = tester.post('/home',data=dict(username="******",password='******'), follow_redirects=True) self.assertIn(b'Change Profile', response.data)
def test_check_history_table(self): with app.test_request_context(): tester=app.test_client(self) db.drop_all() db.create_all() tester.post('/registration',data=dict(username='******', email='*****@*****.**', password='******', confirm_password='******')) tester.post('/home',data=dict(username="******",password='******'), follow_redirects=True) login_user(User.query.first()) tester.post('/profile',data=dict(name="bob",address1='123456123456',address2="789456789456",city="Denver",state="CO",zipcode='80228'), follow_redirects=True) gallons = 975 day = 1 rates = [] totals = [] for quote in range(31): suggestRate, total = calculateRateAndTotal(gallons) rates.append(bytes(str(suggestRate),"ascii")) totals.append(bytes(str(total),"ascii")) tester.post('/quote',data=dict(gallonsRequested=str(gallons),deliveryDate='2020-07-'+str(day),deliveryAddress="123456123456 789456789456",rate=str(suggestRate),total=str(total),submit="True"), follow_redirects=True) gallons += 1 day += 1 response = tester.get('/history',content_type='html/text') for quote in range(31): self.assertIn(rates[quote],response.data) self.assertIn(totals[quote],response.data)
def test_initial_profile_submission(self): tester=app.test_client(self) db.drop_all() db.create_all() tester.post('/registration',data=dict(username='******', email='*****@*****.**', password='******', confirm_password='******')) tester.post('/home',data=dict(username="******",password='******'), follow_redirects=True) response = tester.post('/profile',data=dict(name="bob",address1='123456123456',address2="789456789456",city="Denver",state="TX",zipcode='45454'), follow_redirects=True) self.assertIn(b'Your information has been saved', response.data)
def test_redirection_to_profile_from_quote(self): tester=app.test_client(self) db.drop_all() db.create_all() tester.post('/registration',data=dict(username='******', email='*****@*****.**', password='******', confirm_password='******')) tester.post('/home',data=dict(username="******",password='******'), follow_redirects=True) response = tester.get('/quote',content_type='html/text', follow_redirects=True) self.assertIn(b'Change Profile', response.data)
def test_if_quote_submits(self): tester=app.test_client(self) db.drop_all() db.create_all() tester.post('/registration',data=dict(username='******', email='*****@*****.**', password='******', confirm_password='******')) tester.post('/home',data=dict(username="******",password='******'), follow_redirects=True) tester.post('/profile',data=dict(name="bob",address1='123456123456',address2="789456789456",city="Denver",state="CO",zipcode='45454'), follow_redirects=True) response = tester.post('/quote',data=dict(gallonsRequested="546",deliveryDate='2020-07-20',deliveryAddress="123456123456 Sample Drive",rate="2.00",total="1092",submit="True"), follow_redirects=True) self.assertIn(b'Your quote has been saved', response.data)
def test_if_quote_fails_to_calculate_before_submission(self): tester=app.test_client(self) db.drop_all() db.create_all() tester.post('/registration',data=dict(username='******', email='*****@*****.**', password='******', confirm_password='******')) tester.post('/home',data=dict(username="******",password='******'), follow_redirects=True) tester.post('/profile',data=dict(name="bob",address1='123456123456',address2="789456789456",city="Denver",state="CO",zipcode='45454'), follow_redirects=True) response = tester.post('/quote',data=dict(gallonsRequested="546",deliveryDate='2020-07-20',submit="True"), follow_redirects=True) self.assertIn(b'Please calculate quote before submitting', response.data)
def test_existing_profile_data_recall(self): tester=app.test_client(self) db.drop_all() db.create_all() tester.post('/registration',data=dict(username='******', email='*****@*****.**', password='******', confirm_password='******')) tester.post('/home',data=dict(username="******",password='******'), follow_redirects=True) tester.post('/profile',data=dict(name="bob",address1='123456123456',address2="789456789456",city="Denver",state="CO",zipcode='45454'), follow_redirects=True) response = tester.get('/profile',content_type='html/text') self.assertIn(b'bob', response.data)
def test_logout_redirect(self): with app.test_request_context(): tester=app.test_client(self) db.drop_all() db.create_all() tester.post('/registration',data=dict(username='******', email='*****@*****.**', password='******', confirm_password='******')) tester.post('/home',data=dict(username="******",password='******'), follow_redirects=True) login_user(User.query.first()) response = tester.get('/logout',content_type='html/text', follow_redirects=True) self.assertIn(b"Login Here", response.data)
def test_valid_login(self): tester=app.test_client(self) db.drop_all() db.create_all() hashed_password = bcrypt.generate_password_hash("123456")#.decode('utf-8') user = User(username="******", email="*****@*****.**", password=hashed_password) db.session.add(user) db.session.commit() response=tester.post('/home',data=dict(username="******",password='******'), follow_redirects=True) self.assertIn(b'Change Profile',response.data)
def test_rate_for_new_non_texans_with_more_than_1000_gallons(self): with app.test_request_context(): tester=app.test_client(self) db.drop_all() db.create_all() tester.post('/registration',data=dict(username='******', email='*****@*****.**', password='******', confirm_password='******')) tester.post('/home',data=dict(username="******",password='******'), follow_redirects=True) login_user(User.query.first()) tester.post('/profile',data=dict(name="bob",address1='123456123456',address2="789456789456",city="Denver",state="CO",zipcode='80228'), follow_redirects=True) suggestRate, total = calculateRateAndTotal(1234) self.assertEqual(suggestRate,Decimal('1.74')) self.assertEqual(total,Decimal('2147.16'))
def test_rate_for_old_non_texans_with_more_than_1000_gallons(self): with app.test_request_context(): tester=app.test_client(self) db.drop_all() db.create_all() tester.post('/registration',data=dict(username='******', email='*****@*****.**', password='******', confirm_password='******')) tester.post('/home',data=dict(username="******",password='******'), follow_redirects=True) login_user(User.query.first()) tester.post('/profile',data=dict(name="bob",address1='123456123456',address2="789456789456",city="Denver",state="CO",zipcode='80228'), follow_redirects=True) tester.post('/quote',data=dict(gallonsRequested="899",deliveryDate='2020-07-20',deliveryAddress="123456123456 789456789456",rate="1.73",total="1555.27",submit="True"), follow_redirects=True) suggestRate, total = calculateRateAndTotal(2255) self.assertEqual(suggestRate,Decimal('1.72')) self.assertEqual(total,Decimal('3878.6'))
def test_rate_for_old_texans_with_more_than_1000_gallons(self): with app.test_request_context(): tester=app.test_client(self) db.drop_all() db.create_all() tester.post('/registration',data=dict(username='******', email='*****@*****.**', password='******', confirm_password='******')) tester.post('/home',data=dict(username="******",password='******'), follow_redirects=True) login_user(User.query.first()) tester.post('/profile',data=dict(name="bob",address1='123456123456',address2="789456789456",city="Houston",state="TX",zipcode='77777'), follow_redirects=True) tester.post('/quote',data=dict(gallonsRequested="546",deliveryDate='2020-07-20',deliveryAddress="123456123456 Sample Drive",rate="2.00",total="1092",submit="True"), follow_redirects=True) suggestRate, total = calculateRateAndTotal(2002) self.assertEqual(suggestRate,Decimal('1.7')) self.assertEqual(total,Decimal('3403.4'))
def test_redirection_to_profile_from_registration(self): with app.test_request_context(): tester=app.test_client(self) db.drop_all() db.create_all() hashed_password = bcrypt.generate_password_hash("123456")#.decode('utf-8') user = User(username="******", email="*****@*****.**", password=hashed_password) db.session.add(user) db.session.commit() login_user(user) tester.post('/home',data=dict(username="******",password='******'), follow_redirects=True) response = tester.get('/registration',content_type='html/text', follow_redirects=True) self.assertIn(b'Change Profile', response.data)
def test_redirection_to_quote_if_profile_exists(self): with app.test_request_context(): tester=app.test_client(self) db.drop_all() db.create_all() hashed_password = bcrypt.generate_password_hash("123456")#.decode('utf-8') user = User(username="******", email="*****@*****.**", password=hashed_password) db.session.add(user) db.session.commit() login_user(user) profile = Profile(name="bob", address1="Sample Drive", address2="", city="Houston",state="TX", zipcode="77777", user_id=current_user.id) db.session.add(profile) db.session.commit() response = tester.post('/home',data=dict(username="******",password='******'), follow_redirects=True) self.assertIn(b'Get Your Quote', response.data)
def test_invalid_login(self): tester=app.test_client(self) db.drop_all() db.create_all() response=tester.post('/home',data=dict(username="******",password='******'), follow_redirects=True) self.assertIn(b'Login failed. Check username and password',response.data)
def setUp(self): app.config['TESTING'] = True app.config['WTF_CSRF_ENABLED'] = False app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db' self.app = app.test_client() db.create_all()