-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
63 lines (49 loc) · 2.34 KB
/
test.py
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
from flaskr import app, db
import flaskr
import unittest
from flask_testing import TestCase
class FlaskrTestCase(unittest.TestCase):
# url /login повертає код 200
def test_login_code(self):
tester = app.test_client(self)
response = tester.get('/login', content_type = 'html/text')
self.assertEqual(response.status_code, 200)
# слово Login - частина html за url /login
def test_login_page(self):
tester = app.test_client(self)
response = tester.get('/login', content_type = 'html/text')
self.assertTrue(b'Login' in response.data)
# коли залогінився правильно редіректнуло на добру сторінку
def test_login_correct(self):
tester = app.test_client(self)
response = tester.post('/login', data = dict(username = 'admin', password = 'default'), follow_redirects = True)
self.assertTrue(b'u were logged in' in response.data)
# коли залогінився неправильно не редіректнуло на добру сторінку
def test_login_incorrect(self):
tester = app.test_client(self)
response = tester.post('/login', data = dict(username = 'incorrect', password = 'default'), follow_redirects = True)
self.assertTrue(b'Bad username' in response.data)
# logout працює добре
def test_logout(self):
tester = app.test_client(self)
response = tester.post('/login', data = dict(username = 'admin', password = 'default'), follow_redirects = True)
response = tester.get('/logout', follow_redirects = True)
self.assertTrue(b'logout succeded' in response.data)
# index page вимагає Login
def test_logout(self):
tester = app.test_client(self)
response = tester.post('/login', data = dict(username = 'admin', password = 'default'), follow_redirects = True)
response = tester.get('/logout', follow_redirects = True)
self.assertTrue(b'logout succeded' in response.data)
# index page містить login here
def test_index_login(self):
tester = app.test_client(self)
response = tester.get('/', content_type = 'html/text')
self.assertTrue(b'loGin here' in response.data)
# main page містить замітки
def test_index_post(self):
tester = app.test_client(self)
response = tester.get('/', content_type = 'html/text')
self.assertTrue(b'redact' in response.data)
if __name__ == '__main__':
unittest.main()