-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusers_test_util.py
executable file
·55 lines (44 loc) · 1.89 KB
/
users_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
54
55
#!/usr/bin/python2.4
#
# Copyright 2009 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Utilities for writing unit tests that involve the AppEngine users API.
Based on code from the following post on gist.github, which demonstrate a set
of base classes that are designed to support the various AppEngine components:
https://gist.github.com/186251/6f1434f1ea0ccf5f618cbf3ac91b8dde07156977
"""
__author__ = '[email protected] (Matt Frantz)'
import os
try:
from google3.apphosting.api import user_service_stub
from google3.dotorg.gongo.appengine_cap2kml import appengine_test_util
except ImportError:
import appengine_test_util
from google.appengine.api import user_service_stub
class UsersTestBase(appengine_test_util.AppEngineTestBase):
"""Base class that allows unit tests to use the 'user' module."""
def setUp(self):
super(UsersTestBase, self).setUp()
self.__user_stub = user_service_stub.UserServiceStub()
self.apiproxy_stub_map.RegisterStub('user', self.__user_stub)
self.SetUser('[email protected]')
def SetUser(self, user_email, user_is_admin='0'):
"""Specifies the fake user that will appear to be running the unit tests.
Args:
user_email: Email of the fake user (str)
user_is_admin: If '1', the user has admin privileges; if '0', it does
not.
"""
os.environ['USER_EMAIL'] = user_email
os.environ['USER_IS_ADMIN'] = user_is_admin