本文整理汇总了Python中google.appengine.ext.testbed.Testbed.setup_env方法的典型用法代码示例。如果您正苦于以下问题:Python Testbed.setup_env方法的具体用法?Python Testbed.setup_env怎么用?Python Testbed.setup_env使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类google.appengine.ext.testbed.Testbed
的用法示例。
在下文中一共展示了Testbed.setup_env方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SimpleTest
# 需要导入模块: from google.appengine.ext.testbed import Testbed [as 别名]
# 或者: from google.appengine.ext.testbed.Testbed import setup_env [as 别名]
class SimpleTest(unittest.TestCase):
"""
"""
def setUp(self):
"""
"""
self.testbed = Testbed()
self.testbed.setup_env(app_id='dev~foobar')
self.testbed.activate()
self.testbed.init_memcache_stub()
self.testbed.init_datastore_v3_stub(datastore_file='/tmp/appengine.foobar.kgreen/datastore.db',
use_sqlite=True)
def tearDown(self):
self.testbed.deactivate()
def test_index(self):
model = DataModel(name='users',
value=[PropertyModel(name='first', value='John'),
PropertyModel(name='last', value='Dough')])
model.put()
示例2: Testbed
# 需要导入模块: from google.appengine.ext.testbed import Testbed [as 别名]
# 或者: from google.appengine.ext.testbed.Testbed import setup_env [as 别名]
from __future__ import absolute_import, division, print_function, unicode_literals
from google.appengine.ext.testbed import Testbed
app_id = 'gaeshell'
user = 'kgreen'
datastore_file = '/tmp/appengine.{0}.{1}/datastore.db'.format(app_id, user)
testbed = Testbed()
testbed.setup_env(app_id='dev~{0}'.format(app_id))
testbed.activate()
testbed.init_memcache_stub()
testbed.init_datastore_v3_stub(datastore_file=datastore_file, use_sqlite=True)
print('-' * 80)
import script
print('-' * 80)
示例3: TestCase
# 需要导入模块: from google.appengine.ext.testbed import Testbed [as 别名]
# 或者: from google.appengine.ext.testbed.Testbed import setup_env [as 别名]
#.........这里部分代码省略.........
return self.__users[name]
def admin_user(self, name = None):
"""Constructs an admin user object.
Arguments:
name: A string to distinguish this user from others. Users with
different names will be distinct, and the same name will always
refer to the same user. Admin users have a separate namespace from
non-admin users.
Returns: The user object.
"""
if self.__admins.has_key(name):
return self.__admins[name]
email = '[email protected]'
if name:
email = 'test-admin-%[email protected]' % name
self.__admins[name] = users.User(email = email)
return self.__admins[name]
def be_normal_user(self, name = None):
"""Log in as a non-admin user.
Arguments:
name: A string to distinguish this user from others. Users with
different names will be distinct, and the same name will always
refer to the same user. Admin users have a separate namespace from
non-admin users.
"""
self.testbed.setup_env(
user_email = self.normal_user(name).email(),
overwrite = True)
def be_admin_user(self, name = None):
"""Log in as an admin user.
Arguments:
name: A string to distinguish this user from others. Users with
different names will be distinct, and the same name will always
refer to the same user. Admin users have a separate namespace from
non-admin users.
"""
self.testbed.setup_env(
user_email = self.admin_user(name).email(),
user_is_admin = '1',
overwrite = True)
def dont_be_oauth_user(self):
"""Don't consider the user to be logged in via OAuth."""
self.testbed.setup_env(
oauth_error_code=str(UserServiceError.OAUTH_INVALID_REQUEST),
oauth_error_detail='',
oauth_last_scope='https://www.googleapis.com/auth/userinfo.email')
def be_normal_oauth_user(self, name=None):
"""Log in as a non-admin OAuth user.
Arguments:
name: A string to distinguish this user from others. Users with
different names will be distinct, and the same name will always
refer to the same user. Admin users have a separate namespace from
non-admin users.
示例4: Testbed
# 需要导入模块: from google.appengine.ext.testbed import Testbed [as 别名]
# 或者: from google.appengine.ext.testbed.Testbed import setup_env [as 别名]
from __future__ import absolute_import, division, print_function, unicode_literals
from google.appengine.ext import ndb
from google.appengine.ext.testbed import Testbed
testbed = Testbed()
testbed.setup_env(app_id='dev~foobar')
testbed.activate()
testbed.init_memcache_stub()
testbed.init_datastore_v3_stub(datastore_file='/tmp/appengine.foobar.kgreen/datastore.db', use_sqlite=True)
print('-' * 80)
class Environment(ndb.Model):
pass
class DataProperties(ndb.Expando):
_default_indexed = False
class DataObject(ndb.Expando):
name = ndb.StringProperty(indexed=True)
properties = ndb.LocalStructuredProperty(DataProperties, compressed=True)
def addRelationship(parent_model, child_model, related_name=None, async=True):
"""
"""
related_name = 'related__{0}'.format(related_name or child_model.name)
try: