当前位置: 首页>>代码示例>>Python>>正文


Python test.Client类代码示例

本文整理汇总了Python中kay.utils.test.Client的典型用法代码示例。如果您正苦于以下问题:Python Client类的具体用法?Python Client怎么用?Python Client使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Client类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: CronOnlyDebugTestCase

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")
开发者ID:dbordak,项目名称:pyblog,代码行数:30,代码来源:decorator_test.py

示例2: SessionMiddlewareWithSecureCookieTestCase

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')
开发者ID:dbordak,项目名称:pyblog,代码行数:25,代码来源:session_test.py

示例3: ServerErrorTest

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))
开发者ID:nax589,项目名称:kay-framework,代码行数:27,代码来源:server_error_tests.py

示例4: EReporterTest

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!")
开发者ID:dbordak,项目名称:pyblog,代码行数:35,代码来源:ereporter_test.py

示例5: DatastoreBackendTestCase

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)
开发者ID:IanLewis,项目名称:kay,代码行数:30,代码来源:auth_test.py

示例6: MaintenanceCheckTestCase

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)
开发者ID:gmist,项目名称:kay-ru,代码行数:53,代码来源:decorator_test.py

示例7: CronOnlyTestCase

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)
开发者ID:gmist,项目名称:kay-ru,代码行数:16,代码来源:decorator_test.py

示例8: DatastoreBackendTestCase

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]")
开发者ID:gmist,项目名称:kay-ru,代码行数:44,代码来源:auth_test.py

示例9: setUp

    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()]
开发者ID:nax589,项目名称:kay-framework,代码行数:10,代码来源:server_error_tests.py

示例10: setUp

 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()
开发者ID:IanLewis,项目名称:kay,代码行数:12,代码来源:auth_test.py

示例11: ServerErrorTest

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))
开发者ID:gdgkyoto,项目名称:kyoto-gtug,代码行数:21,代码来源:server_error_tests.py

示例12: CronOnlyAdminTestCase

class CronOnlyAdminTestCase(GAETestBase):

  def setUp(self):
    s = LazySettings(settings_module='kay.tests.decorator_settings')
    s.DEBUG = True
    app = get_application(settings=s)
    self.client = Client(app, BaseResponse)

  def test_cron_only_admin(self):
    from kay.auth.models import DatastoreUser
    user = DatastoreUser(
        key_name=DatastoreUser.get_key_name("foobar"),
        user_name="foobar",
        password=DatastoreUser.hash_password("password")
    )
    user.is_admin = True
    user.put()

    self.client.test_login(username='foobar')
    response = self.client.get('/cron')
    self.assertEqual(response.status_code, 200)
    self.assertTrue(response.data == "OK")
开发者ID:gmist,项目名称:kay-ru,代码行数:22,代码来源:decorator_test.py

示例13: setUp

  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,
    ) 
开发者ID:dbordak,项目名称:pyblog,代码行数:14,代码来源:ereporter_test.py

示例14: SessionMiddlewareOnCookieWithSecureAttributeTestCase

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.')
开发者ID:dbordak,项目名称:pyblog,代码行数:20,代码来源:session_test.py

示例15: setUp

  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'])
开发者ID:dbordak,项目名称:pyblog,代码行数:22,代码来源:decorator_test.py


注:本文中的kay.utils.test.Client类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。