-
Notifications
You must be signed in to change notification settings - Fork 7
/
tests.py
100 lines (68 loc) · 2.76 KB
/
tests.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# Before running the test
# In your virtual environment, type in the following to the terminal
# pip install coverage
# Test things along the way of building test as well
# <How to test the test>
# ipython -i server.py # to go into the interactive mode
# ctrl + c # to quit server from running
# <Test example1>
# tc = app.test_client(); tc
# expected result >>> <FlaskClient <Flask 'server'>
# indicates that now you can generate a test client
# <Test example2>
# resp = tc.get('/'); resp
# expected result >>> <Response streamed [200 OK]>
# indicates the route '/' is returning 200 on client
# So if the browser will be running, you will get a page
import unittest
from unittest import TestCase
from server import app
class HomepageIntegrationTest(TestCase):
"""A smoke test."""
def setUp(self):
"""Setsup a temporary ground for testing"""
# make a test client <FlaskClient <Flask u'server'>>
tc = app.test_client()
self.client = tc
def test_homepage(self):
"""Tests the viability of the homepage"""
resp = self.client.get('/')
# make request to / route <Response streamed [200 OK]>
# in interactive mode, try dir(resp) to see possible commands
# data gets a string of the entire body of the HTML page
# put whatever string you expect from that data on
# '/' page to check. In this case, something from index.html
self.assertIn("Employee Roster", resp.data)
def tearDown(self):
"""Clean up"""
db.session.close()
db.drop_all()
class DatabaseIntegrationTest(TestCase):
def setUp(self):
# Connect to our testdb
connect_to_db(app, "postgresql:///testdb")
db.create_all()
# possibly seed it with example_data()
# make test_client
def tearDown(self):
"""Clean up"""
db.session.close()
db.drop_all()
def test_login(self):
"""Tests if the login/logout is working"""
rest = self.client.get('/logged')
def test_employees(self):
# make request to /employees route
resp = self.client.get('/employees')
self.assertEqual(200, resp.status_code)
self.assertNotEqual(404, resp.status_code)
self.assertIn("Employee Search", resp.data)
# "add emloyee" test
# before change, make tests & commit before
# For login feature, user the following id & password to check the model.
# [email protected] pass: aaa123 (admin=’true’)
# [email protected] pass: bbb123 (yes date_employeed, no date_departed, admin=’false’)
# [email protected] pass: ccc123 (yes date_employeed, no date_departed, admin=’false’)
# [email protected] pass: ddd123(yes date_employeed, no date_departed, admin=’false’)
if __name__ == "__main__":
unittest.main()