-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
66 lines (52 loc) · 2.21 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
64
65
66
import unittest
from flask.ext.testing import TestCase
# from flask_testing import TestCase
import app as ap
# from app import index, test, dashboard, terms, request_submitTestForm, auth_signup, auth_activate, auth_forgotpassword, login, logout, request_getUserInfo, listings_getall, listings_create, profile_get, profile_changescreenname, profile_addclass, profile_removeclass, profile_edit, listings_respond, init_connection, chat_msg_send, sendMessageToRecipient, tutor_accepted, chatbox, set_client, handle_custom_event, send_user_msg, server_response
class MyTest(TestCase):
def create_app(self):
return ap.app
def test_index(self):
self.client.get('/')
self.assert_template_used('index.html')
def test_test(self):
self.client.get('/test')
self.assertTrue(ap.test() == "test123")
# def test_dashboard(self):
# self.client.get('/dashboard')
# self.assert_template_used('dashboard.html')
def test_signup(self):
resp = self.client.get('/auth/signup')
# Ensure that valid fields result in success.
resp = self.client.post('auth/signup', {
'signupemail': 'qtadmin@case.edu',
'signuppassword': 'Password1',
}, follow_redirects=False)
self.assertEqual(resp.status_code, 302)
if __name__== '__main__':
unittest.main()
#/////
# from flask import Flask
# from flask_testing import LiveServerTestCase
#////
class MyTest(LiveServerTestCase):
def create_app(self):
app = Flask(__name__)
app.config['TESTING'] = True
# Default port is 5000
app.config['LIVESERVER_PORT'] = 5000
# Default timeout is 5 seconds
app.config['LIVESERVER_TIMEOUT'] = 10
return app
def test_server_is_up_and_running(self):
response = urllib2.urlopen(self.get_server_url())
self.assertEqual(response.code, 200)
def test_request_getUserInfo(self):
response = self.i.get("/request/getUserInfo")
data = json.loads(response.get_data(as_text=True))
self.assertEqual(data['userid', 'email', 'password', 'displayname'], 1, "test@case.edu", "password", "TestUser")
#test if flask was set up correctly
def test_index(self):
tester = app.test_client(self)
response = tester.get('/login', context_type = 'html/text')
self.assertEqual(response.status_code, 200)