本文整理汇总了Python中google.appengine.ext.testbed.Testbed.init_urlfetch_stub方法的典型用法代码示例。如果您正苦于以下问题:Python Testbed.init_urlfetch_stub方法的具体用法?Python Testbed.init_urlfetch_stub怎么用?Python Testbed.init_urlfetch_stub使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类google.appengine.ext.testbed.Testbed
的用法示例。
在下文中一共展示了Testbed.init_urlfetch_stub方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: StubManager
# 需要导入模块: from google.appengine.ext.testbed import Testbed [as 别名]
# 或者: from google.appengine.ext.testbed.Testbed import init_urlfetch_stub [as 别名]
class StubManager(object):
def __init__(self):
self.active_stubs = None
self.pre_test_stubs = None
def setup_stubs(self, connection):
if self.active_stubs is not None:
return
if not have_appserver:
self.setup_local_stubs(connection)
def activate_test_stubs(self, connection):
from google.appengine.ext.testbed import Testbed
self.testbed = Testbed()
if self.active_stubs == 'test':
return
os.environ['HTTP_HOST'] = "%s.appspot.com" % appid
appserver_opts = connection.settings_dict.get('DEV_APPSERVER_OPTIONS', {})
high_replication = appserver_opts.get('high_replication', False)
datastore_opts = {}
if high_replication:
from google.appengine.datastore import datastore_stub_util
datastore_opts['consistency_policy'] = datastore_stub_util.PseudoRandomHRConsistencyPolicy(probability=1)
self.testbed.activate()
self.pre_test_stubs = self.active_stubs
self.active_stubs = 'test'
self.testbed.init_datastore_v3_stub(**datastore_opts)
self.testbed.init_memcache_stub()
self.testbed.init_taskqueue_stub(auto_task_running=True, root_path=PROJECT_DIR)
self.testbed.init_urlfetch_stub()
self.testbed.init_user_stub()
self.testbed.init_xmpp_stub()
self.testbed.init_channel_stub()
def deactivate_test_stubs(self):
if self.active_stubs == 'test':
self.testbed.deactivate()
self.active_stubs = self.pre_test_stubs
def setup_local_stubs(self, connection):
if self.active_stubs == 'local':
return
from .base import get_datastore_paths
from google.appengine.tools import dev_appserver_main
args = dev_appserver_main.DEFAULT_ARGS.copy()
args.update(get_datastore_paths(connection.settings_dict))
args.update(connection.settings_dict.get('DEV_APPSERVER_OPTIONS', {}))
log_level = logging.getLogger().getEffectiveLevel()
logging.getLogger().setLevel(logging.WARNING)
from google.appengine.tools import dev_appserver
dev_appserver.SetupStubs('dev~' + appid, **args)
logging.getLogger().setLevel(log_level)
self.active_stubs = 'local'
def setup_remote_stubs(self, connection):
if self.active_stubs == 'remote':
return
if not connection.remote_api_path:
from ..utils import appconfig
for handler in appconfig.handlers:
if handler.script in REMOTE_API_SCRIPTS:
connection.remote_api_path = handler.url.split('(', 1)[0]
break
server = '%s.%s' % (connection.remote_app_id, connection.domain)
remote_url = 'https://%s%s' % (server, connection.remote_api_path)
logging.info("Setting up remote_api for '%s' at %s." %
(connection.remote_app_id, remote_url))
if not have_appserver:
logging.info(
"Connecting to remote_api handler.\n\n"
"IMPORTANT: Check your login method settings in the "
"App Engine Dashboard if you have problems logging in. "
"Login is only supported for Google Accounts.")
from google.appengine.ext.remote_api import remote_api_stub
remote_api_stub.ConfigureRemoteApi(None,
connection.remote_api_path, auth_func, servername=server,
secure=connection.secure_remote_api,
rpc_server_factory=rpc_server_factory)
retry_delay = 1
while retry_delay <= 16:
try:
remote_api_stub.MaybeInvokeAuthentication()
except HTTPError, e:
if not have_appserver:
logging.info("Retrying in %d seconds..." % retry_delay)
time.sleep(retry_delay)
retry_delay *= 2
else:
break
else:
示例2: StubManager
# 需要导入模块: from google.appengine.ext.testbed import Testbed [as 别名]
# 或者: from google.appengine.ext.testbed.Testbed import init_urlfetch_stub [as 别名]
class StubManager(object):
def __init__(self):
self.testbed = Testbed()
self.active_stubs = None
self.pre_test_stubs = None
def setup_stubs(self, connection):
if self.active_stubs is not None:
return
if not have_appserver:
self.setup_local_stubs(connection)
def activate_test_stubs(self):
if self.active_stubs == 'test':
return
self.testbed.activate()
self.pre_test_stubs = self.active_stubs
self.active_stubs = 'test'
self.testbed.init_datastore_v3_stub()
self.testbed.init_memcache_stub()
self.testbed.init_taskqueue_stub()
self.testbed.init_urlfetch_stub()
self.testbed.init_user_stub()
self.testbed.init_xmpp_stub()
self.testbed.init_channel_stub()
def deactivate_test_stubs(self):
if self.active_stubs == 'test':
self.testbed.deactivate()
self.active_stubs = self.pre_test_stubs
def setup_local_stubs(self, connection):
if self.active_stubs == 'local':
return
from .base import get_datastore_paths
from google.appengine.tools import dev_appserver_main
args = dev_appserver_main.DEFAULT_ARGS.copy()
args.update(get_datastore_paths(connection.settings_dict))
args.update(connection.settings_dict.get('DEV_APPSERVER_OPTIONS', {}))
log_level = logging.getLogger().getEffectiveLevel()
logging.getLogger().setLevel(logging.WARNING)
from google.appengine.tools import dev_appserver
dev_appserver.SetupStubs(appid, **args)
logging.getLogger().setLevel(log_level)
self.active_stubs = 'local'
def setup_remote_stubs(self, connection):
if self.active_stubs == 'remote':
return
if not connection.remote_api_path:
from ..utils import appconfig
for handler in appconfig.handlers:
if handler.script == REMOTE_API_SCRIPT:
connection.remote_api_path = handler.url.split('(', 1)[0]
break
server = '%s.%s' % (connection.remote_app_id, connection.domain)
remote_url = 'https://%s%s' % (server, connection.remote_api_path)
logging.info('Setting up remote_api for "%s" at %s' %
(connection.remote_app_id, remote_url))
if not have_appserver:
print('Connecting to remote_api handler.\n\n'
'IMPORTANT: Check your login method settings in the '
'App Engine Dashboard if you have problems logging in. '
'Login is only supported for Google Accounts.\n')
from google.appengine.ext.remote_api import remote_api_stub
remote_api_stub.ConfigureRemoteApi(None,
connection.remote_api_path, auth_func, servername=server,
secure=connection.secure_remote_api,
rpc_server_factory=rpc_server_factory)
retry_delay = 1
while retry_delay <= 16:
try:
remote_api_stub.MaybeInvokeAuthentication()
except HTTPError, e:
if not have_appserver:
print 'Retrying in %d seconds...' % retry_delay
time.sleep(retry_delay)
retry_delay *= 2
else:
break
else:
示例3: fix_sys_path
# 需要导入模块: from google.appengine.ext.testbed import Testbed [as 别名]
# 或者: from google.appengine.ext.testbed.Testbed import init_urlfetch_stub [as 别名]
#!/usr/bin/env python
# coding: utf-8
import os
import logging
from dev_appserver import fix_sys_path
fix_sys_path()
from google.appengine.ext.testbed import Testbed
tb = Testbed()
tb.activate()
os.environ['APPLICATION_ID'] = 'rss-xmpp'
tb.init_xmpp_stub()
tb.init_datastore_v3_stub()
tb.init_urlfetch_stub()
from rss_xmpp.main import *
from google.appengine.api import xmpp
from rss_xmpp import feedcrawler
import unittest
url = 'http://feeds.feedburner.com/github'
class XMPPTestMessage(xmpp.Message):
def reply(self, body, message_type="chat", raw_xml=False, send_message=xmpp.send_message):
super(XMPPTestMessage, self).reply(body, message_type, raw_xml, send_message)
logging.debug('\nSent message:\n' + '='*80 + '\n' + body + '='*80 + '\n')
class TestRSSXMPP(unittest.TestCase):
示例4: FunctionalClientTest
# 需要导入模块: from google.appengine.ext.testbed import Testbed [as 别名]
# 或者: from google.appengine.ext.testbed.Testbed import init_urlfetch_stub [as 别名]
class FunctionalClientTest(TestCase):
def setUp(self):
from google.appengine.ext.testbed import Testbed
self.testbed = Testbed()
self.testbed.activate()
self.testbed.init_urlfetch_stub()
self.username = os.environ.get('NETPRINT_USERNAME')
self.password = os.environ.get('NETPRINT_PASSWORD')
if self.username is None or self.password is None:
raise SkipTest("Need both "
"NETPRINT_USERNAME and NETPRINT_PASSWORD")
def tearDown(self):
self.testbed.deactivate()
def _getOUT(self):
import httplib2
from netprint import Client
httplib2.debuglevel = 1
return Client(httplib2.Http(),
'Mozilla/5.0 '
'(Macintosh; U;Intel Mac OS X 10_6_3; ja-jp) '
'AppleWebKit/533.16 (KHTML, like Gecko) '
'Version/5.0 Safari/533.16')
@attr('functional', 'heavy')
def test_login(self):
client = self._getOUT()
client.login(self.username, self.password, retry=1)
self.assertIsNotNone(client.session_key)
@attr('functional', 'heavy')
def test_session_error(self):
from netprint import UnexpectedContent
client1 = self._getOUT()
client2 = self._getOUT()
client1.login(self.username, self.password, 1)
client2.login(self.username, self.password, 1)
self.assertNotEqual(client1.session_key, client2.session_key)
self.assertRaises(UnexpectedContent, client1.reload)
@attr('functional', 'heavy')
def test_send_delete(self):
client = self._getOUT()
client.login(self.username, self.password, retry=1)
client.send('tests/data/数独01.jpg')
client.reload()
self.assertIn(u'数独01', [item.name for item in client.list()])
client.delete(item)
client.reload()
self.assertNotIn(u'数独01', [item.name for item in client.list()])
@attr('functional', 'heavy')
def test_send_delete_with_fileobj(self):
client = self._getOUT()
client.login(self.username, self.password, retry=1)
client.send(file('tests/data/数独01.jpg'))
client.reload()
self.assertIn(u'数独01', [item.name for item in client.list()])
client.delete(item)
client.reload()
self.assertNotIn(u'数独01', [item.name for item in client.list()])
示例5: StubManager
# 需要导入模块: from google.appengine.ext.testbed import Testbed [as 别名]
# 或者: from google.appengine.ext.testbed.Testbed import init_urlfetch_stub [as 别名]
class StubManager(object):
def __init__(self):
self.testbed = None
self.active_stubs = None
self.pre_test_stubs = None
def setup_stubs(self, connection):
if self.active_stubs is not None:
return
if not have_appserver:
self.activate_stubs(connection)
def activate_stubs(self, connection):
try:
from google.appengine.tools import dev_appserver_main
self.setup_local_stubs(connection)
except ImportError:
self.activate_test_stubs(connection)
def reset_stubs(self, connection, datastore_path=None):
if self.active_stubs == "test":
self.deactivate_test_stubs()
self.activate_test_stubs(connection, datastore_path)
elif self.active_stubs == "local":
self.setup_local_stubs(connection)
elif self.active_stubs == "remote":
self.setup_remote_stubs(connection)
def activate_test_stubs(self, connection, datastore_path=None):
if self.active_stubs == "test":
return
if self.testbed is None:
from google.appengine.ext.testbed import Testbed
self.testbed = Testbed()
self.testbed.activate()
self.pre_test_stubs = self.active_stubs
self.active_stubs = "test"
os.environ["APPLICATION_ID"] = "dev~" + appid
os.environ["HTTP_HOST"] = "%s.appspot.com" % appid
appserver_opts = connection.settings_dict.get("DEV_APPSERVER_OPTIONS", {})
high_replication = appserver_opts.get("high_replication", False)
require_indexes = appserver_opts.get("require_indexes", False)
use_sqlite = appserver_opts.get("use_sqlite", False)
datastore_opts = {"require_indexes": require_indexes, "use_sqlite": use_sqlite}
if high_replication:
from google.appengine.datastore import datastore_stub_util
datastore_opts["consistency_policy"] = datastore_stub_util.PseudoRandomHRConsistencyPolicy(probability=1)
self.testbed.init_datastore_v3_stub(datastore_file=datastore_path, **datastore_opts)
self.testbed.init_memcache_stub()
self.testbed.init_taskqueue_stub(auto_task_running=True, root_path=PROJECT_DIR)
self.testbed.init_urlfetch_stub()
self.testbed.init_user_stub()
self.testbed.init_xmpp_stub()
self.testbed.init_channel_stub()
self.testbed.init_app_identity_stub()
self.testbed.init_blobstore_stub()
self.testbed.init_files_stub()
self.testbed.init_images_stub()
def deactivate_test_stubs(self):
if self.active_stubs == "test":
self.testbed.deactivate()
self.active_stubs = self.pre_test_stubs
def setup_local_stubs(self, connection):
if self.active_stubs == "local":
return
from .base import get_datastore_paths
from google.appengine.tools import dev_appserver_main
args = dev_appserver_main.DEFAULT_ARGS.copy()
args.update(get_datastore_paths(connection.settings_dict))
args.update(connection.settings_dict.get("DEV_APPSERVER_OPTIONS", {}))
log_level = logging.getLogger().getEffectiveLevel()
logging.getLogger().setLevel(logging.WARNING)
try:
from google.appengine.tools import dev_appserver
except ImportError:
from google.appengine.tools import old_dev_appserver as dev_appserver
dev_appserver.SetupStubs("dev~" + appid, **args)
logging.getLogger().setLevel(log_level)
self.active_stubs = "local"
def setup_remote_stubs(self, connection):
if self.active_stubs == "remote":
return
#.........这里部分代码省略.........