-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtests.py
53 lines (36 loc) · 2.04 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
""" Tests. Test database testcontacts must be created in order for these to work. """
import unittest
import os
import server
import server_functions
import model
class LoggedInTestCase(unittest.TestCase):
""" Testing when user is logged in. """
def setUp(self):
self.client = server.app.test_client()
server.app.config['TESTING'] = True
# os.system('createdb testcontacts')
model.connect_to_db(server.app, "postgresql:///testcontacts")
model.fill_relationships_table()
model.test_data()
with self.client.session_transaction() as session:
session['user_id'] = 1
def tearDown(self):
model.db.session.close()
model.db.drop_all()
# os.system('dropdb testcontacts')
def test_index(self):
result = self.client.get('/', follow_redirects=True)
self.assertIn('<div class="sidenav">', result.data)
self.assertNotIn('<div class="topnav" id="landing-nav">', result.data)
class LoggedOutTestCase(unittest.TestCase):
""" Testing when user is logged out. """
def setUp(self):
self.client = server.app.test_client()
server.app.config['TESTING'] = True
def test_index(self):
result = self.client.get('/', follow_redirects=True)
self.assertIn('https://accounts.google.com/o/oauth2/v2/auth?scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fgmail.compose+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fgmail.labels+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fgmail.modify+https%3A%2F%2Fwww.google.com%2Fm8%2Ffeeds%2F+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcontacts.readonly+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email&redirect_uri=http%3A%2F%2Flocalhost%3A5000%2Foauthcallback&response_type=code&client_id=1031894893410-0e7i2f7kaoenh6s9htvvm3mb1cab1trc.apps.googleusercontent.com&access_type=offline', result.data)
self.assertNotIn('<div class="sidenav">', result.data)
if __name__ == "__main__":
unittest.main()