-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_server.py
More file actions
64 lines (53 loc) 路 2.2 KB
/
Copy pathtest_server.py
File metadata and controls
64 lines (53 loc) 路 2.2 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import unittest
from server import app
class FlaskTestCase(unittest.TestCase):
def setUp(self):
self.app = app.test_client()
self.app.testing = True
def test_index_route(self):
response = self.app.get('/')
self.assertEqual(response.status_code, 302)
self.assertIn('/login', response.headers['Location'])
def test_login(self):
self.app.post('/login', data=dict(
email='john@example.com',
password='password123'
), follow_redirects=True)
def test_logout(self):
response = self.app.get('/logout', follow_redirects=True)
self.assertEqual(response.status_code, 200)
self.assertIn(b'You have been logged out', response.data)
def test_dashboards_route(self):
with self.app.session_transaction() as session:
session['user_id'] = 1
response = self.app.get('/dashboards')
self.assertEqual(response.status_code, 200)
self.assertIn(b'User Dashboards', response.data)
def test_create_dashboard_route(self):
with self.app.session_transaction() as session:
session['user_id'] = 1
response = self.app.post('/create-dashboard', data=dict(
title='New Dashboard',
language='Python'
), follow_redirects=True)
self.assertEqual(response.status_code, 200)
self.assertIn(b'New Dashboard', response.data)
def test_delete_dashboard_route(self):
with self.app.session_transaction() as session:
session['user_id'] = 1
response = self.app.post('/delete-dashboard', data=dict(
dashboard_id=1
), follow_redirects=True)
self.assertEqual(response.status_code, 200)
self.assertNotIn(b'Dashboard 1', response.data)
def test_edit_dashboard_route(self):
with self.app.session_transaction() as session:
session['user_id'] = 1
response = self.app.post('/edit-dashboard', data=dict(
dashboard_id=1,
title='New Title'
), follow_redirects=True)
self.assertEqual(response.status_code, 200)
self.assertIn(b'New Title', response.data)
if __name__ == '__main__':
unittest.main()