-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_user.py
33 lines (25 loc) · 981 Bytes
/
test_user.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
import unittest
import os
import json
from app import create_app, db
class UserTestCase(unittest.TestCase):
def setUp(self):
self.app = create_app(config_name="testing")
self.client = self.app.test_client
self.user = {'first_name': 'Ryan', 'last_name': 'Hantak', 'email': 'rhantak@example.com', 'password': 'password'}
with self.app.app_context():
db.create_all()
def test_user_creation(self):
res = self.client().post('/users', json=self.user)
data = json.loads(res.get_data(as_text=True))
self.assertEqual(len(data['token']), 32)
self.assertEqual(res.status_code, 201)
self.assertIn('Ryan', str(res.data))
self.assertIn('Hantak', str(res.data))
self.assertIn('rhantak@example.com', str(res.data))
def tearDown(self):
with self.app.app_context():
db.session.remove()
db.drop_all()
if __name__ == "__main__":
unittest.main()