當前位置: 首頁>>代碼示例>>Python>>正文


Python Testbed.setup_env方法代碼示例

本文整理匯總了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()
開發者ID:kellengreen,項目名稱:katnap,代碼行數:24,代碼來源:tests.py

示例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)
開發者ID:kellengreen,項目名稱:gaeshell,代碼行數:18,代碼來源:shell.py

示例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.
開發者ID:kaisellgren,項目名稱:pub-dartlang,代碼行數:70,代碼來源:testcase.py

示例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:
開發者ID:kellengreen,項目名稱:katnap,代碼行數:33,代碼來源:shell.py


注:本文中的google.appengine.ext.testbed.Testbed.setup_env方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。