-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.py
60 lines (44 loc) · 1.46 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
from flask.ext.testing import TestCase
from flask.ext.testing import LiveServerTestCase
from app import app as FlaskApp
from flask import Flask
import urllib2
# to conduct the tests,
# first install nose: pip install nose
# just cd to the dir containing the test.py,and run command "nosetests"
class IsLiveTest(LiveServerTestCase):
def create_app(self):
FlaskApp.config["TESTING"] = True
FlaskApp.config["LIVESERVER_PORT"] = 8943
#return FlaskApp
return FlaskApp
def test_server_is_up_and_running(self):
response = urllib2.urlopen(self.get_server_url())
self.assertEqual(response.code,200)
class JsonAndOtherTest(TestCase):
def create_app(self):
FlaskApp.config["TESTING"] = True
FlaskApp.config["LIVESERVER_PORT"] = 8943
#return FlaskApp
return FlaskApp
def test_json_get(self):
response = self.client.get("/json_get/")
print response.json
self.assertEqual(
response.json,
dict(
success=True,
args={"code":1,"status":"OK"}
)
)
def test_json_post(self):
params = {"a":"b"}
from flask import jsonify
from flask import json
json_str = json.dumps(params)
response = self.client.post("/json_post/",data = json_str)
self.assertEqual(response.json,dict(
post_params=params,
success=True
)
)