-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_yelandur.py
68 lines (49 loc) · 2.1 KB
/
test_yelandur.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
67
68
# -*- coding: utf-8 -*-
import unittest
from flask.ext.mongoengine import MongoEngine
from yelandur import create_app, create_apizer, helpers
class InitTestCase(unittest.TestCase):
def setUp(self):
self.app = create_app(mode='test')
def tearDown(self):
with self.app.test_request_context():
helpers.wipe_test_database()
def test_create_apizer(self):
# A mock app to work with
class App(object):
pass
mock_app = App()
mock_app.config = {'API_VERSION_URL': '/vX_mock_test'}
mock_apize = create_apizer(mock_app)
self.assertEqual(mock_apize('/test_url'), '/vX_mock_test/test_url')
# Now with a real app object
apize = create_apizer(self.app)
self.assertRegexpMatches(apize('/test_url'),
r'^/v[0-9]+/test_url$')
def test_create_app(self):
# Test configuration loading
self.assertTrue(self.app.config['TESTING'])
self.assertRaises(IOError, create_app, 'absent')
# MongoEngine is initialized
self.assertIsInstance(self.app.extensions['mongoengine'], MongoEngine)
# Blueprints are present
self.assertIn('auth', self.app.blueprints)
self.assertIn('users', self.app.blueprints)
self.assertIn('exps', self.app.blueprints)
self.assertIn('devices', self.app.blueprints)
self.assertIn('profiles', self.app.blueprints)
self.assertIn('results', self.app.blueprints)
class RootApiTestCase(unittest.TestCase):
def setUp(self):
self.app = create_app(mode='test')
self.client = self.app.test_client()
def tearDown(self):
with self.app.test_request_context():
helpers.wipe_test_database()
def test_root(self):
# Nothing is found out of the blueprints (/auth, /users, /devices,
# etc)
self.assertEqual(self.client.get('/').status_code, 404)
apize = create_apizer(self.app)
self.assertEqual(self.client.get(apize('')).status_code, 404)
self.assertEqual(self.client.get(apize('/')).status_code, 404)