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


Python Client.test_login方法代码示例

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


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

示例1: DatastoreBackendTestCase

# 需要导入模块: from kay.utils.test import Client [as 别名]
# 或者: from kay.utils.test.Client import test_login [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)
开发者ID:IanLewis,项目名称:kay,代码行数:32,代码来源:auth_test.py

示例2: GoogleBackendTestCase

# 需要导入模块: from kay.utils.test import Client [as 别名]
# 或者: from kay.utils.test.Client import test_login [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)
开发者ID:IanLewis,项目名称:kay,代码行数:35,代码来源:auth_test.py

示例3: RestTestCase

# 需要导入模块: from kay.utils.test import Client [as 别名]
# 或者: from kay.utils.test.Client import test_login [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)
开发者ID:IanLewis,项目名称:kay,代码行数:61,代码来源:rest_test.py

示例4: StackedDecoratorsTestCase

# 需要导入模块: from kay.utils.test import Client [as 别名]
# 或者: from kay.utils.test.Client import test_login [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)
开发者ID:dbordak,项目名称:pyblog,代码行数:19,代码来源:decorator_test.py

示例5: DatastoreBackendTestCase

# 需要导入模块: from kay.utils.test import Client [as 别名]
# 或者: from kay.utils.test.Client import test_login [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]")
开发者ID:gmist,项目名称:kay-ru,代码行数:46,代码来源:auth_test.py

示例6: GAEMABackendTestCase

# 需要导入模块: from kay.utils.test import Client [as 别名]
# 或者: from kay.utils.test.Client import test_login [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)
开发者ID:IanLewis,项目名称:kay,代码行数:44,代码来源:auth_test.py

示例7: CronOnlyAdminTestCase

# 需要导入模块: from kay.utils.test import Client [as 别名]
# 或者: from kay.utils.test.Client import test_login [as 别名]
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,代码行数:24,代码来源:decorator_test.py

示例8: CacheTestCase

# 需要导入模块: from kay.utils.test import Client [as 别名]
# 或者: from kay.utils.test.Client import test_login [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)
开发者ID:dbordak,项目名称:pyblog,代码行数:54,代码来源:tests.py

示例9: RestJSONTestCase

# 需要导入模块: from kay.utils.test import Client [as 别名]
# 或者: from kay.utils.test.Client import test_login [as 别名]
class RestJSONTestCase(GAETestBase):
  KIND_NAME_UNSWAPPED = False
  USE_PRODUCTION_STUBS = True
  CLEANUP_USED_KIND = True

  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_json(self):

    headers = Headers({"Accept": "application/json"})

    response = self.client.get('/rest/metadata', headers=headers)
    self.assertEqual(response.status_code, 403)

    self.client.test_login(email="[email protected]")
    response = self.client.get('/rest/metadata', headers=headers)
    self.assertEqual(response.status_code, 403)

    self.client.test_login(email="[email protected]", is_admin="1")
    response = self.client.get('/rest/metadata', headers=headers)
    self.assertEqual(response.status_code, 200)

    self.client.test_logout()
    response = self.client.get('/rest/metadata/RestModel', headers=headers)
    self.assertEqual(response.status_code, 403)

    self.client.test_login(email="[email protected]")
    response = self.client.get('/rest/metadata/RestModel', headers=headers)
    self.assertEqual(response.status_code, 403)

    self.client.test_login(email="[email protected]", is_admin="1")
    response = self.client.get('/rest/metadata/RestModel', headers=headers)
    self.assertEqual(response.status_code, 200)


    self.client.test_logout()
    response = self.client.post(
      '/rest/RestModel',
      data='{"RestModel": {"i_prop": 12, "s_prop": "string"}}',
      content_type="application/json; charset=utf-8")
    self.assertEqual(response.status_code, 403)

    self.client.test_login(email="[email protected]")
    response = self.client.post(
      '/rest/RestModel',
      data='{"RestModel": {"i_prop": 12, "s_prop": "string"}}',
      content_type="application/json; charset=utf-8")
    self.assertEqual(response.status_code, 403)

    self.client.test_login(email="[email protected]", is_admin="1")
    response = self.client.post(
      '/rest/RestModel',
      data='{"RestModel": {"i_prop": 12, "s_prop": "string"}}',
      content_type="application/json; charset=utf-8")
    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)

    self.client.test_logout()
    response = self.client.post(
      '/rest/RestModel/%s' % key,
      data='{"RestModel": {"i_prop": 14}}',
      content_type="application/json; charset=utf-8")
    self.assertEqual(response.status_code, 403)

    self.client.test_login(email="[email protected]")
    response = self.client.post(
      '/rest/RestModel/%s' % key,
      data='{"RestModel": {"i_prop": 14}}',
      content_type="application/json; charset=utf-8")
    self.assertEqual(response.status_code, 403)

    self.client.test_login(email="[email protected]", is_admin="1")
    response = self.client.post(
      '/rest/RestModel/%s' % key,
      data='{"RestModel": {"i_prop": 14}}',
      content_type="application/json; charset=utf-8")
    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.post(
      '/rest/RestModel',
      data='[{"RestModel": {"i_prop": 1, "s_prop": "foobar1"}},{"RestModel": {"i_prop": 2, "s_prop": "foobar2"}}]',
      content_type="application/json; charset=utf-8")
    self.assertEqual(response.status_code, 200)
#.........这里部分代码省略.........
开发者ID:dbordak,项目名称:pyblog,代码行数:103,代码来源:rest_test.py

示例10: TsuhanTest

# 需要导入模块: from kay.utils.test import Client [as 别名]
# 或者: from kay.utils.test.Client import test_login [as 别名]
class TsuhanTest(GAETestBase):
    CLEANUP_USED_KIND = False
    USE_PRODUCTION_STUBS = True
    KIND_NAME_UNSWAPPED=False
    USE_REMOTE_STUBS=False

    def setUp(self):
        init_recording()
        app = get_application()
        self.client = Client(app, BaseResponse)
        self.client.test_login()

    def tearDown(self):
        self.client.test_logout()
        disable_recording()

    def test_index(self):
        response = self.client.open(
            path=url_for('core/index'),
            method='GET',
            data=dict(),
        )
        self.assertEqual(response.status_code, 200)

    def test_products(self):
        response = self.client.open(
            path=url_for('core/products',category_code='01',list_per_page=20,page_index=0),
            method='GET',
            data=dict(),
        )
        self.assertEqual(response.status_code, 200)

    def test_tags(self):
        response = self.client.open(
            path=url_for('core/tags',tags=u'タグ',list_per_page=20,page_index=0),
            method='GET',
            data=dict(),
        )
        self.assertEqual(response.status_code, 200)

    def test_search(self):
        response = self.client.open(
            path=url_for('core/search',words=u'検索ワード',list_per_page=20,page_index=0),
            method='GET',
            data=dict(),
        )
        self.assertEqual(response.status_code, 200)

    def test_detail(self):
        response = self.client.open(
            path=url_for('core/detail',article_id='421135'),
            method='GET',
            data=dict(),
        )
        self.assertEqual(response.status_code, 200)

    def test_sitemap(self):
        response = self.client.open(
            path=url_for('core/sitemap'),
            method='GET',
            data=dict(),
        )
        self.assertEqual(response.status_code, 404)
开发者ID:cedarjp,项目名称:tsuhan-be,代码行数:65,代码来源:__init__.py


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