Repository navigation
Expand file tree
/
Copy pathtests.py
More file actions
100 lines (77 loc) · 3.3 KB
/
Copy pathtests.py
File metadata and controls
100 lines (77 loc) · 3.3 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
'''
Run the tests using testrunner.py script in the project root directory.
Usage: testrunner.py SDK_PATH TEST_PATH
Run unit tests for App Engine apps.
SDK_PATH Path to the SDK installation
TEST_PATH Path to package containing test modules
Options:
-h, --help show this help message and exit
'''
import unittest
import webapp2
import os
import webtest
from google.appengine.ext import testbed
from mock import Mock
from mock import patch
import application
from application import models
from application import config as boilerplate_config
import config
import routes
from application import routes as boilerplate_routes
from application.lib import utils
from application.lib import captcha
from application.lib import i18n
from application.lib import test_helpers
# setting HTTP_HOST in extra_environ parameter for TestApp is not enough for taskqueue stub
os.environ['HTTP_HOST'] = 'localhost'
# globals
network = False
# mock Internet calls
if not network:
i18n.get_territory_from_ip = Mock(return_value=None)
class AppTest(unittest.TestCase, test_helpers.HandlerHelpers):
def setUp(self):
# create a WSGI application.
webapp2_config = boilerplate_config.config
webapp2_config.update(config.config)
self.app = webapp2.WSGIApplication(config=webapp2_config)
routes.add_routes(self.app)
boilerplate_routes.add_routes(self.app)
self.testapp = webtest.TestApp(self.app, extra_environ={'REMOTE_ADDR' : '127.0.0.1'})
# use absolute path for templates
self.app.config['webapp2_extras.jinja2']['template_path'] = [os.path.join(os.path.dirname(application.__file__), '../templates'), os.path.join(os.path.dirname(application.__file__), 'templates')]
# activate GAE stubs
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
self.testbed.init_memcache_stub()
self.testbed.init_urlfetch_stub()
self.testbed.init_taskqueue_stub()
self.testbed.init_mail_stub()
self.mail_stub = self.testbed.get_stub(testbed.MAIL_SERVICE_NAME)
self.taskqueue_stub = self.testbed.get_stub(testbed.TASKQUEUE_SERVICE_NAME)
self.testbed.init_user_stub()
self.headers = {'User-Agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) Version/6.0 Safari/536.25',
'Accept-Language' : 'en_US'}
# fix configuration if this is still a raw boilerplate code - required by test with mails
if not utils.is_email_valid(self.app.config.get('contact_sender')):
if not utils.is_email_valid(self.app.config.get('contact_recipient')):
def tearDown(self):
self.testbed.deactivate()
def test_config_environment(self):
self.assertEquals(self.app.config.get('environment'), 'testing')
class ModelTest(unittest.TestCase):
def setUp(self):
# activate GAE stubs
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
self.testbed.init_memcache_stub()
def tearDown(self):
self.testbed.deactivate()
if __name__ == "__main__":
unittest.main()