-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.py
More file actions
49 lines (36 loc) · 1.31 KB
/
tests.py
File metadata and controls
49 lines (36 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import unittest
from app import app
app.config['TESTING'] = True
app.config['SECRET_KEY'] = 'test_secret_key'
class TestApp(unittest.TestCase):
# set up and tear down
def setUp(self):
self.app = app.test_client()
self.app.testing = True
def tearDown(self):
pass
# test home page
def test_homepage_requires_login(self):
response = self.app.get('/')
self.assertEqual(response.status_code, 302)
self.assertIn('login', response.location)
# test login
def test_login_page_loads(self):
response = self.app.get('/login')
self.assertEqual(response.status_code, 200)
self.assertIn(b'login', response.data)
def test_valid_login(self):
response = self.app.post('/login', data = dict(
email = 'test@example.com',
password = 'password123'
), follow_redirects = True)
self.assertEqual(response.status_code, 200)
self.assertIn(b'Login successful.', response.data)
def test_invalid_login(self):
response = self.app.post('/login', data = dict(
email = 'wrong@example.com',
password = 'wrongpassword'
), follow_redirects = True)
self.assertIn(b'Login Failed.', response.data)
if __name__ == '__main__':
unittest.main()