-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_unit.py
52 lines (37 loc) · 1.51 KB
/
test_unit.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
import unittest
#from flask.ext.testing import TestCase
from crud import app,db
from crud.models import Messages
import json
class FlaskrTestCase(unittest.TestCase):
def setUp(self):
app.config.from_object('config.TestingConfig')
self.app = app.test_client()
db.drop_all()
db.create_all()
def tearDown(self):
pass
def test_index(self):
response = self.app.get('/',content_type='html/text')
self.assertEqual(response.status_code, 200)
def test_render(self):
response = self.app.get('/',content_type='html/text')
self.assertIn(b'Sample app for testing Web Services', response.data)
def post_message(self,nick,text):
return self.app.post(
'/api',
#data=dict(nick=nick,text=text),
data=json.dumps(dict(nick=nick,text=text)),
content_type='application/json')
def test_message_post(self):
response = self.post_message('Libert','Just Like you Imagined')
self.assertEqual(response.status_code, 200)
self.assertIn(b'Just Like you Imagined',response.data)
# response2 = self.app.get('/',content_type='html/text')
# self.assertIn(b'Just Like you Imagined', response2.data)
def test_message_get(self):
self.post_message('Libert','Just Like you Imagined')
response = self.app.get('/api',content_type='application/json')
self.assertIn(b'Just Like you Imagined', response.data)
if __name__ == '__main__':
unittest.main()