本文整理汇总了Python中kay.utils.test.Client.get方法的典型用法代码示例。如果您正苦于以下问题:Python Client.get方法的具体用法?Python Client.get怎么用?Python Client.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kay.utils.test.Client
的用法示例。
在下文中一共展示了Client.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SessionMiddlewareWithSecureCookieTestCase
# 需要导入模块: from kay.utils.test import Client [as 别名]
# 或者: from kay.utils.test.Client import get [as 别名]
class SessionMiddlewareWithSecureCookieTestCase(GAETestBase):
KIND_NAME_UNSWAPPED = False
USE_PRODUCTION_STUBS = True
CLEANUP_USED_KIND = True
def setUp(self):
s = LazySettings(settings_module='kay.tests.securecookie_session_settings')
app = get_application(settings=s)
self.client = Client(app, BaseResponse)
def tearDown(self):
pass
def test_countup(self):
response = self.client.get('/countup')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data, '1')
response = self.client.get('/countup')
self.assertEqual(response.data, '2')
response = self.client.get('/countup')
self.assertEqual(response.data, '3')
response = self.client.get('/countup')
self.assertEqual(response.data, '4')
response = self.client.get('/countup')
self.assertEqual(response.data, '5')
示例2: CronOnlyDebugTestCase
# 需要导入模块: from kay.utils.test import Client [as 别名]
# 或者: from kay.utils.test.Client import get [as 别名]
class CronOnlyDebugTestCase(GAETestBase):
def setUp(self):
s = LazySettings(settings_module='kay.tests.settings')
s.DEBUG = True
app = get_application(settings=s)
self.client = Client(app, BaseResponse)
def test_cron_only_failure(self):
from kay.utils import is_dev_server
response = self.client.get("/cron")
if is_dev_server():
self.assertEqual(response.status_code, 200)
else:
self.assertEqual(response.status_code, 403)
response = self.client.get("/class_based_test_root/cron")
if is_dev_server():
self.assertEqual(response.status_code, 200)
else:
self.assertEqual(response.status_code, 403)
def test_cron_only(self):
response = self.client.get("/cron",
headers=(('X-AppEngine-Cron', 'true'),))
self.assertEqual(response.status_code, 200)
self.assertTrue(response.data == "OK")
response = self.client.get("/class_based_test_root/cron",
headers=(('X-AppEngine-Cron', 'true'),))
self.assertEqual(response.status_code, 200)
self.assertTrue(response.data == "OK")
示例3: DatastoreBackendTestCase
# 需要导入模块: from kay.utils.test import Client [as 别名]
# 或者: from kay.utils.test.Client import get [as 别名]
class DatastoreBackendTestCase(GAETestBase):
KIND_NAME_UNSWAPPED = False
USE_PRODUCTION_STUBS = True
CLEANUP_USED_KIND = True
KIND_PREFIX_IN_TEST = 't2'
def setUp(self):
from kay.auth import create_new_user
s = LazySettings(settings_module='kay.tests.datastore_settings')
app = get_application(settings=s)
self.client = Client(app, BaseResponse)
create_new_user("foobar", "password", is_admin=False)
def tearDown(self):
self.client.test_logout()
def test_login(self):
response = self.client.get(url_for('auth_testapp/index'))
self.assertEqual(response.status_code, 200)
response = self.client.get(url_for('auth_testapp/secret'))
self.assertEqual(response.status_code, 302)
self.assert_(response.headers.get('Location').endswith(
'/auth/login?next=http%253A%252F%252Flocalhost%252Fsecret'))
self.client.test_login(username='foobar')
response = self.client.get(url_for('auth_testapp/secret'))
self.assertEqual(response.status_code, 200)
self.client.test_logout()
response = self.client.get(url_for('auth_testapp/secret'))
self.assertEqual(response.status_code, 302)
示例4: GoogleBackendTestCase
# 需要导入模块: from kay.utils.test import Client [as 别名]
# 或者: from kay.utils.test.Client import get [as 别名]
class GoogleBackendTestCase(GAETestBase):
KIND_NAME_UNSWAPPED = False
USE_PRODUCTION_STUBS = True
CLEANUP_USED_KIND = True
KIND_PREFIX_IN_TEST = 't1'
def setUp(self):
try:
self.original_user = os.environ['USER_EMAIL']
self.original_is_admin = os.environ['USER_IS_ADMIN']
del os.environ['USER_EMAIL']
del os.environ['USER_IS_ADMIN']
except Exception:
pass
s = LazySettings(settings_module='kay.tests.google_settings')
app = get_application(settings=s)
self.client = Client(app, BaseResponse)
self.client.test_logout()
def tearDown(self):
self.client.test_logout()
def test_login(self):
response = self.client.get(url_for('auth_testapp/index'))
self.assertEqual(response.status_code, 200)
response = self.client.get(url_for('auth_testapp/secret'))
self.assertEqual(response.status_code, 302)
self.client.test_login(email="[email protected]", is_admin="1")
response = self.client.get(url_for('auth_testapp/secret'))
self.assertEqual(response.status_code, 200)
self.client.test_logout()
response = self.client.get(url_for('auth_testapp/secret'))
self.assertEqual(response.status_code, 302)
示例5: EReporterTest
# 需要导入模块: from kay.utils.test import Client [as 别名]
# 或者: from kay.utils.test.Client import get [as 别名]
class EReporterTest(GAETestBase):
def setUp(self):
s = LazySettings(
settings_module='kay.tests.ereporter_settings')
app = get_application(settings=s)
self.client = Client(app, BaseResponse)
#self.client.test_logout()
# Suppress logging error messages
self._base_logger = logging.getLogger("")
self._old_logging_handlers = self._base_logger.handlers
self._base_logger.handlers = filter(
lambda h: not isinstance(h, logging.StreamHandler),
self._old_logging_handlers,
)
def tearDown(self):
self.client.test_logout()
self._base_logger.handlers = self._old_logging_handlers
def test_ereporter(self):
from kay.ext.ereporter.models import ExceptionRecord
self.assertEqual(ExceptionRecord.all().count(), 0, "ExceptionRecord objects already exist!")
response = self.client.get(url_for('ereporter_testapp/index'))
self.assertEqual(response.status_code, 500, "Expected 500 error code.")
self.assertEqual(ExceptionRecord.all().count(), 1)
# Simulate the key expiring.
memcache.flush_all();
response = self.client.get(url_for('ereporter_testapp/index'))
self.assertEqual(response.status_code, 500, "Expected 500 error code.")
self.assertEqual(ExceptionRecord.all().count(), 1, "More than one ExceptionRecord object was created!")
self.assertEqual(ExceptionRecord.all()[0].count, 2, "ExceptionRecord count not incremented!")
示例6: MaintenanceCheckTestCase
# 需要导入模块: from kay.utils.test import Client [as 别名]
# 或者: from kay.utils.test.Client import get [as 别名]
class MaintenanceCheckTestCase(unittest.TestCase):
def setUp(self):
apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap()
stub = datastore_file_stub.DatastoreFileStub('test','/dev/null',
'/dev/null')
apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', stub)
apiproxy_stub_map.apiproxy.RegisterStub(
'user', user_service_stub.UserServiceStub())
apiproxy_stub_map.apiproxy.RegisterStub(
'memcache', memcache_stub.MemcacheServiceStub())
apiproxy_stub_map.apiproxy.RegisterStub(
'urlfetch', urlfetch_stub.URLFetchServiceStub())
s = LazySettings(settings_module='kay.tests.settings')
app = get_application(settings=s)
self.client = Client(app, BaseResponse)
if apiproxy_stub_map.apiproxy\
._APIProxyStubMap__stub_map.has_key('capability_service'):
del(apiproxy_stub_map.apiproxy\
._APIProxyStubMap__stub_map['capability_service'])
def tearDown(self):
pass
def test_success(self):
"""Test with normal CapabilityServiceStub"""
apiproxy_stub_map.apiproxy.RegisterStub(
'capability_service',
capability_stub.CapabilityServiceStub())
response = self.client.get('/')
self.assertEqual(response.status_code, 200)
def test_failure(self):
"""Test with DisabledCapabilityServiceStub
"""
apiproxy_stub_map.apiproxy.RegisterStub(
'capability_service',
mocked_capability_stub.DisabledCapabilityServiceStub())
response = self.client.get('/')
self.assertEqual(response.status_code, 302)
self.assertEqual(response.headers['Location'],
'http://localhost/maintenance_page')
response = self.client.get('/index2')
self.assertEqual(response.status_code, 302)
self.assertEqual(response.headers['Location'],
'http://localhost/no_decorator')
response = self.client.get('/no_decorator')
self.assertEqual(response.status_code, 200)
示例7: ServerErrorTest
# 需要导入模块: from kay.utils.test import Client [as 别名]
# 或者: from kay.utils.test.Client import get [as 别名]
class ServerErrorTest(GAETestBase):
"""
Regression test for issue 54 that checks to make sure
that responses for error conditions extend BaseResponse.
http://code.google.com/p/kay-framework/issues/detail?id=54
"""
def setUp(self):
s = LazySettings(settings_module="kay.tests.regressiontests.server_error_settings")
app = get_application(settings=s)
self.client = Client(app, BaseResponse)
self.client.test_logout()
# Suppress logging error messages
self._base_logger = logging.getLogger("")
self._old_logging_handlers = self._base_logger.handlers
self._base_logger.handlers = [NullHandler()]
def tearDown(self):
self.client.test_logout()
self._base_logger.handlers = self._old_logging_handlers
def test_login(self):
response = self.client.get(url_for("server_error_testapp/index"))
self.assertEqual(response.status_code, 500)
self.assertTrue(isinstance(response, BaseResponse))
示例8: CronOnlyTestCase
# 需要导入模块: from kay.utils.test import Client [as 别名]
# 或者: from kay.utils.test.Client import get [as 别名]
class CronOnlyTestCase(GAETestBase):
def setUp(self):
s = LazySettings(settings_module='kay.tests.settings')
app = get_application(settings=s)
self.client = Client(app, BaseResponse)
def test_cron_only(self):
response = self.client.get("/cron",
headers=(('X-AppEngine-Cron', 'true'),))
self.assertEqual(response.status_code, 200)
self.assertTrue(response.data == "OK")
def test_cron_only_failure(self):
response = self.client.get("/cron")
self.assertEqual(response.status_code, 403)
示例9: StackedDecoratorsTestCase
# 需要导入模块: from kay.utils.test import Client [as 别名]
# 或者: from kay.utils.test.Client import get [as 别名]
class StackedDecoratorsTestCase(GAETestBase):
def setUp(self):
s = LazySettings(settings_module='kay.tests.stacked_decorators.settings')
app = get_application(settings=s)
self.client = Client(app, BaseResponse)
def test_stacked_decorators(self):
self.client.test_login(email='[email protected]')
response = self.client.get('/')
self.assertEqual(response.status_code, 200)
response = self.client.get('/class')
self.assertEqual(response.status_code, 200)
response = self.client.get('/ndb')
self.assertEqual(response.status_code, 200)
response = self.client.get('/class_ndb')
self.assertEqual(response.status_code, 200)
示例10: RestTestCase
# 需要导入模块: from kay.utils.test import Client [as 别名]
# 或者: from kay.utils.test.Client import get [as 别名]
class RestTestCase(GAETestBase):
KIND_NAME_UNSWAPPED = False
USE_PRODUCTION_STUBS = True
CLEANUP_USED_KIND = True
KIND_PREFIX_IN_TEST = "t2"
def setUp(self):
s = LazySettings(settings_module='kay.tests.rest_settings')
app = get_application(settings=s)
self.client = Client(app, BaseResponse)
self.client.test_logout()
def tearDown(self):
self.client.test_logout()
def test_rest_operations(self):
self.client.test_login(email="[email protected]", is_admin="1")
response = self.client.get('/rest/metadata')
self.assertEqual(response.status_code, 200)
response = self.client.get('/rest/metadata/RestModel')
self.assertEqual(response.status_code, 200)
response = self.client.post('/rest/RestModel', data='<?xml version="1.0" encoding="utf-8"?><RestModel><i_prop>12</i_prop><s_prop>string</s_prop></RestModel>')
self.assertEqual(response.status_code, 200)
key = response.data
elm = RestModel.get(key)
self.assertEqual(elm.s_prop, "string")
self.assertEqual(elm.i_prop, 12)
response = self.client.post(
'/rest/RestModel/%s' % key,
data='<?xml version="1.0" encoding="utf-8"?><RestModel><i_prop>14</i_prop></RestModel>')
self.assertEqual(response.status_code, 200)
key2 = response.data
self.assertEqual(key, key2)
elm = RestModel.get(key)
self.assertEqual(elm.s_prop, "string")
self.assertEqual(elm.i_prop, 14)
response = self.client.get('/rest/RestModel')
self.assertEqual(response.status_code, 200)
response = self.client.get('/rest/RestModel/%s' % key)
self.assertEqual(response.status_code, 200)
response = self.client.get('/rest/RestModel/%s/s_prop' % key)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data, "string")
response = self.client.get('/rest/RestModel/%s/i_prop' % key)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data, "14")
response = self.client.delete('/rest/RestModel/%s' % key)
self.assertEqual(response.status_code, 200)
response = self.client.get('/rest/RestModel/%s' % key)
self.assertEqual(response.status_code, 404)
示例11: DatastoreBackendTestCase
# 需要导入模块: from kay.utils.test import Client [as 别名]
# 或者: from kay.utils.test.Client import get [as 别名]
class DatastoreBackendTestCase(GAETestBase):
KIND_NAME_UNSWAPPED = False
USE_PRODUCTION_STUBS = True
CLEANUP_USED_KIND = True
KIND_PREFIX_IN_TEST = 't2'
def setUp(self):
s = LazySettings(settings_module='kay.tests.datastore_settings')
app = get_application(settings=s)
self.client = Client(app, BaseResponse)
def tearDown(self):
self.client.test_logout()
def test_login(self):
from kay.auth import create_new_user
create_new_user("foobar", "password", is_admin=False)
response = self.client.get(url_for('auth_testapp/index'))
self.assertEqual(response.status_code, 200)
response = self.client.get(url_for('auth_testapp/secret'))
self.assertEqual(response.status_code, 302)
self.assert_(response.headers.get('Location').endswith(
'/auth/login?next=http%253A%252F%252Flocalhost%252Fsecret'))
self.client.test_login(username='foobar')
response = self.client.get(url_for('auth_testapp/secret'))
self.assertEqual(response.status_code, 200)
self.client.test_logout()
response = self.client.get(url_for('auth_testapp/secret'))
self.assertEqual(response.status_code, 302)
def test_create_inactive_user(self):
from kay.auth.models import DatastoreUser
from kay.utils import crypto
user = DatastoreUser.create_inactive_user("testuser", "password",
"[email protected]",
do_registration=False)
self.assertEqual(user.key().name(),
DatastoreUser.get_key_name("testuser"))
self.assertEqual(user.user_name, "testuser")
self.assertTrue(crypto.check_pwhash(user.password, "password"))
self.assertEqual(user.email, "[email protected]")
示例12: GAEMABackendTestCase
# 需要导入模块: from kay.utils.test import Client [as 别名]
# 或者: from kay.utils.test.Client import get [as 别名]
class GAEMABackendTestCase(GAETestBase):
KIND_NAME_UNSWAPPED = False
USE_PRODUCTION_STUBS = True
CLEANUP_USED_KIND = True
KIND_PREFIX_IN_TEST = 't3'
def setUp(self):
s = LazySettings(settings_module='kay.tests.gaema_settings')
app = get_application(settings=s)
self.client = Client(app, BaseResponse)
def tearDown(self):
self.client.test_logout(service='shehas.net')
def test_login(self):
response = self.client.get(url_for('gaema_testapp/index'))
self.assertEqual(response.status_code, 200)
response = self.client.get(url_for('gaema_testapp/secret',
domain_name='shehas.net'))
self.assertEqual(response.status_code, 302)
self.assert_(response.headers.get('Location').endswith(
'/_ah/gaema/marketplace_login/a/shehas.net'))
self.client.test_login(service='shehas.net',
user_data={'claimed_id': 'http://shehas.net/123',
'email': '[email protected]'})
response = self.client.get(url_for('gaema_testapp/secret',
domain_name='shehas.net'))
self.assertEqual(response.status_code, 200)
response = self.client.get(url_for('gaema_testapp/secret',
domain_name='example.com'))
self.assertEqual(response.status_code, 302)
self.assert_(response.headers.get('Location').endswith(
'/_ah/gaema/marketplace_login/a/example.com'))
self.client.test_logout(service='shehas.net')
response = self.client.get(url_for('gaema_testapp/secret',
domain_name='shehas.net'))
self.assertEqual(response.status_code, 302)
示例13: CacheTestCase
# 需要导入模块: from kay.utils.test import Client [as 别名]
# 或者: from kay.utils.test.Client import get [as 别名]
class CacheTestCase(GAETestBase):
def setUp(self):
s = LazySettings(settings_module='kay.tests.cache_test.settings')
self.app = get_application(settings=s)
self.client = Client(self.app, BaseResponse)
memcache.flush_all()
def test_cache_middleware(self):
# make sure that CACHE_MIDDLEWARE_ANONYMOUSE_ONLY works
self.client.test_login(email='[email protected]')
response = self.client.get(url_for('cache_testapp/index'))
self.assertEqual(response.status_code, 200)
c = memcache.get('http://localhost/?lang=en', namespace='CACHE_MIDDLEWARE')
self.assertEqual(c, None)
self.client.test_logout()
# user logout, so the cache works
response = self.client.get(url_for('cache_testapp/index'))
self.assertEqual(response.status_code, 200)
c = memcache.get('http://localhost/?lang=en', namespace='CACHE_MIDDLEWARE')
self.assertEqual(c.data, response.data)
def test_cache_decorator_with_function_view(self):
# make sure that CACHE_MIDDLEWARE_ANONYMOUSE_ONLY works
self.client.test_login(email='[email protected]')
response = self.client.get(url_for('cache_testapp/decorator'))
self.assertEqual(response.status_code, 200)
c = memcache.get('http://localhost/decorator?lang=en',
namespace='CACHE_DECORATOR')
self.assertEqual(c, None)
self.client.test_logout()
# user logout, so the cache works
response = self.client.get(url_for('cache_testapp/decorator'))
self.assertEqual(response.status_code, 200)
c = memcache.get('http://localhost/decorator?lang=en',
namespace='CACHE_DECORATOR')
self.assertEqual(c.data, response.data)
def test_cache_decorator_with_class_view(self):
# make sure that CACHE_MIDDLEWARE_ANONYMOUSE_ONLY works
self.client.test_login(email='[email protected]')
response = self.client.get(url_for('cache_testapp/decorator_class'))
self.assertEqual(response.status_code, 200)
c = memcache.get('http://localhost/decorator_class?lang=en',
namespace='CACHE_DECORATOR')
self.assertEqual(c, None)
self.client.test_logout()
# user logout, so the cache works
response = self.client.get(url_for('cache_testapp/decorator_class'))
self.assertEqual(response.status_code, 200)
c = memcache.get('http://localhost/decorator_class?lang=en',
namespace='CACHE_DECORATOR')
self.assertEqual(c.data, response.data)
示例14: SessionMiddlewareOnCookieWithSecureAttributeTestCase
# 需要导入模块: from kay.utils.test import Client [as 别名]
# 或者: from kay.utils.test.Client import get [as 别名]
class SessionMiddlewareOnCookieWithSecureAttributeTestCase(GAETestBase):
KIND_NAME_UNSWAPPED = False
USE_PRODUCTION_STUBS = True
CLEANUP_USED_KIND = True
def setUp(self):
import os
s = LazySettings(settings_module='kay.tests.cookie_session_settings')
app = get_application(settings=s)
self.client = Client(app, BaseResponse)
self.server_name = os.environ['SERVER_NAME']
def tearDown(self):
pass
def test_if_cookie_is_marked_as_secure(self):
url = 'https://%s/countup' % self.server_name
response = self.client.get('/countup', url)
self.assert_('secure' in response.headers['Set-Cookie'],
'The Set-Cookie header does not contain secure flag.')
示例15: ServerErrorTest
# 需要导入模块: from kay.utils.test import Client [as 别名]
# 或者: from kay.utils.test.Client import get [as 别名]
class ServerErrorTest(GAETestBase):
def setUp(self):
s = LazySettings(
settings_module='kay.tests.regressiontests.server_error_settings')
app = get_application(settings=s)
self.client = Client(app, BaseResponse)
self.client.test_logout()
# Suppress logging error messages
self._base_logger = logging.getLogger("")
self._old_logging_handlers = self._base_logger.handlers
self._base_logger.handlers = [NullHandler()]
def tearDown(self):
self.client.test_logout()
self._base_logger.handlers = self._old_logging_handlers
def test_login(self):
response = self.client.get(url_for('server_error_testapp/index'))
self.assertEqual(response.status_code, 500)
self.assertTrue(isinstance(response, BaseResponse))