-
Notifications
You must be signed in to change notification settings - Fork 5
/
test_util.py
53 lines (40 loc) · 1.65 KB
/
test_util.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
#!/usr/bin/env python
"""Base class for tests involving the AppEngine stack."""
import os
import time
import unittest
from google.appengine.api import apiproxy_stub_map
from google.appengine.api import datastore_file_stub
from google.appengine.api import mail_stub
from google.appengine.api import urlfetch_stub
from google.appengine.api import user_service_stub
APP_ID = u'freesideatlanta-members'
AUTH_DOMAIN = 'gmail.com'
LOGGED_IN_USER = '[email protected]'
class AppEngineTestBase(unittest.TestCase):
"""Base class for tests involving the AppEngine stack."""
def setUp(self):
# Ensure we're in UTC.
os.environ['TZ'] = 'UTC'
time.tzset()
# Start with a fresh api proxy.
apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap()
# Use a fresh stub datastore.
self.__datastore_stub = datastore_file_stub.DatastoreFileStub(
APP_ID, '/dev/null', '/dev/null')
apiproxy_stub_map.apiproxy.RegisterStub(
'datastore_v3', self.__datastore_stub)
os.environ['APPLICATION_ID'] = APP_ID
# Use a fresh stub UserService.
apiproxy_stub_map.apiproxy.RegisterStub(
'user', user_service_stub.UserServiceStub())
os.environ['AUTH_DOMAIN'] = AUTH_DOMAIN
os.environ['USER_EMAIL'] = LOGGED_IN_USER
# Use a fresh urlfetch stub.
apiproxy_stub_map.apiproxy.RegisterStub(
'urlfetch', urlfetch_stub.URLFetchServiceStub())
# Use a fresh mail stub.
apiproxy_stub_map.apiproxy.RegisterStub(
'mail', mail_stub.MailServiceStub())
def tearDown(self):
self.__datastore_stub.Clear()