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


Python client.Client方法代码示例

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


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

示例1: setUpClass

# 需要导入模块: from django.test import client [as 别名]
# 或者: from django.test.client import Client [as 别名]
def setUpClass(cls):
        cls.factory = RequestFactory()
        cls.client = Client()
        cls.user = User.objects.create_user("test", "test@archesproject.org", "password")

        rdm_admin_group = Group.objects.get(name="RDM Administrator")
        cls.user.groups.add(rdm_admin_group)
        cls.anonymous_user = User.objects.get(username="anonymous")

        cls.token = "abc"
        cls.oauth_client_id = OAUTH_CLIENT_ID
        cls.oauth_client_secret = OAUTH_CLIENT_SECRET

        sql_str = CREATE_TOKEN_SQL.format(token=cls.token, user_id=cls.user.pk)
        cursor = connection.cursor()
        cursor.execute(sql_str) 
开发者ID:archesproject,项目名称:arches,代码行数:18,代码来源:auth_tests.py

示例2: client

# 需要导入模块: from django.test import client [as 别名]
# 或者: from django.test.client import Client [as 别名]
def client():
    from django.test.client import Client

    class _Client(Client):
        def login(self, user=None, backend="django.contrib.auth.backends.ModelBackend", **credentials):
            if user is None:
                return super(_Client, self).login(**credentials)

            with mock.patch('django.contrib.auth.authenticate') as authenticate:
                user.backend = backend
                authenticate.return_value = user
                return super(_Client, self).login(**credentials)

        @property
        def json(self):
            return PartialMethodCaller(obj=self, content_type='application/json;charset="utf-8"')

    return _Client() 
开发者ID:fossevents,项目名称:fossevents.in,代码行数:20,代码来源:fixtures.py

示例3: setUp

# 需要导入模块: from django.test import client [as 别名]
# 或者: from django.test.client import Client [as 别名]
def setUp(self):
        self.client = Client()

        try:

            try:
                self.user = User.objects.get(username='lennon@thebeatles.com')
            except User.DoesNotExist:
                self.user = User()
                self.user.set_password('johnpassword')
                self.user.username = 'lennon@thebeatles.com'
                self.user.email = 'lennon@thebeatles.com'
                self.user.is_active = True
                self.user.save()

            fbuserprofile = UnifiUser()
            fbuserprofile.user = self.user
            fbuserprofile.save()
        except Exception as exp:
            print("EXCEPTION:LoginTestCase-->", str(exp))
            pass 
开发者ID:bsab,项目名称:django-unifi-portal,代码行数:23,代码来源:test_login.py

示例4: test_middleware_with_internal_ips

# 需要导入模块: from django.test import client [as 别名]
# 或者: from django.test.client import Client [as 别名]
def test_middleware_with_internal_ips(self):
        """
        A user that visits the site from an IP in INTERNAL_IPS should
        be able to use the site normally
        """
        self.turn_maintenance_mode_on()

        # Use a new Client instance to be able to set the REMOTE_ADDR
        # used by INTERNAL_IPS
        client = Client(REMOTE_ADDR='127.0.0.1')

        with self.settings(INTERNAL_IPS=('127.0.0.1',)):
            response = client.get(self.home_url)
            self.assertContains(
                response, text=self.home_page_text, count=1, status_code=200
            ) 
开发者ID:alsoicode,项目名称:django-maintenancemode-2,代码行数:18,代码来源:tests.py

示例5: setUp

# 需要导入模块: from django.test import client [as 别名]
# 或者: from django.test.client import Client [as 别名]
def setUp(self):
        super(ApiTestCase, self).setUp()
        self.loadAdminBoundaries()
        self.user_password = 'mypassword' 
        self.test_user = User.objects.create_user('testuser', 'admin@example.com', self.user_password)
        self.c = Client() 
开发者ID:LibraryOfCongress,项目名称:gazetteer,代码行数:8,代码来源:tests.py

示例6: setUp

# 需要导入模块: from django.test import client [as 别名]
# 或者: from django.test.client import Client [as 别名]
def setUp(self):
        self.expected_resource_count = 2
        self.client = Client()
        self.data_type_graphid = "330802c5-95bd-11e8-b7ac-acde48001122"
        self.resource_instance_id = "f562c2fa-48d3-4798-a723-10209806c068"
        self.user = User.objects.get(username="ben")
        self.group = Group.objects.get(pk=2)
        resource = Resource(pk=self.resource_instance_id)
        resource.graph_id = self.data_type_graphid
        resource.remove_resource_instance_permissions() 
开发者ID:archesproject,项目名称:arches,代码行数:12,代码来源:permission_tests.py

示例7: test_get_oauth_token

# 需要导入模块: from django.test import client [as 别名]
# 或者: from django.test.client import Client [as 别名]
def test_get_oauth_token(self):
        key = "{0}:{1}".format(self.oauth_client_id, self.oauth_client_secret)
        client = Client(HTTP_AUTHORIZATION="Basic %s" % base64.b64encode(key.encode("UTF-8")).decode("UTF-8"))

        # make sure we can POST to the authorize endpoint and get back the proper form
        # response = client.post(reverse('auth'), {'username': 'test', 'password': 'password', 'next': 'oauth2:authorize'})
        # response = client.get(reverse('oauth2:authorize'), {
        #     'client_id': self.oauth_client_id,
        #     'state': 'random_state_string',
        #     'response_type': 'code'
        # }, follow=True)
        # form = response.context['form']
        # data = form.cleaned_data
        # self.assertTrue(response.status_code == 200)
        # self.assertTrue(data['client_id']  == self.oauth_client_id)

        # response = self.client.post(reverse('oauth2:token'), {
        #     'grant_type': 'password',
        #     'username': 'test',
        #     'password': 'password',
        #     'scope': 'read write',
        # })

        response = client.post(
            reverse("oauth2:token"), {"grant_type": "client_credentials", "scope": "read write", "client_id": self.oauth_client_id}
        )

        # print response
        # {"access_token": "ZzVGlb8SLLeCOaogtyhRpBoFbKcuqI", "token_type": "Bearer", "expires_in": 36000, "scope": "read write"}
        self.assertTrue(response.status_code == 200)
        self.assertTrue(response.json()["token_type"] == "Bearer") 
开发者ID:archesproject,项目名称:arches,代码行数:33,代码来源:auth_tests.py

示例8: setUp

# 需要导入模块: from django.test import client [as 别名]
# 或者: from django.test.client import Client [as 别名]
def setUp(self):
        self.expected_resource_count = 2
        self.client = Client()
        self.data_type_graphid = "330802c5-95bd-11e8-b7ac-acde48001122"
        self.resource_instance_id = "f562c2fa-48d3-4798-a723-10209806c068"
        user = User.objects.get(username="ben")
        edit_records = EditLog.objects.filter(resourceinstanceid=self.resource_instance_id).filter(edittype="created")
        if len(edit_records) == 0:
            edit = EditLog(userid=user.id, edittype="create", resourceinstanceid=self.resource_instance_id)
            edit.save() 
开发者ID:archesproject,项目名称:arches,代码行数:12,代码来源:resource_tests.py

示例9: setUp

# 需要导入模块: from django.test import client [as 别名]
# 或者: from django.test.client import Client [as 别名]
def setUp(self):
        self.survey_id = "d309d38e-29b9-45c0-b0f5-542f34a4576a"
        self.expected_resource_count = 2
        self.data_type_graphid = "330802c5-95bd-11e8-b7ac-acde48001122"
        self.c = Client() 
开发者ID:archesproject,项目名称:arches,代码行数:7,代码来源:command_line_tests.py

示例10: setUp

# 需要导入模块: from django.test import client [as 别名]
# 或者: from django.test.client import Client [as 别名]
def setUp(self):
    self.client = Client() 
开发者ID:elsigh,项目名称:browserscope,代码行数:4,代码来源:test_user_tests.py

示例11: setUp

# 需要导入模块: from django.test import client [as 别名]
# 或者: from django.test.client import Client [as 别名]
def setUp(self):
    self.test_set = mock_data.MockTestSet()
    all_test_sets.AddTestSet(self.test_set)
    self.client = Client() 
开发者ID:elsigh,项目名称:browserscope,代码行数:6,代码来源:test_util.py

示例12: setUp

# 需要导入模块: from django.test import client [as 别名]
# 或者: from django.test.client import Client [as 别名]
def setUp(self):
    self.test_set = mock_data.MockTestSet()
    all_test_sets.AddTestSet(self.test_set)

    self.mox = mox.Mox()
    self.mox.StubOutWithMock(time, 'clock')
    self.mox.StubOutWithMock(result_ranker, 'GetOrCreateRankers')
    self.apple_test = self.test_set.GetTest('apple')
    self.coconut_test = self.test_set.GetTest('coconut')
    self.apple_ranker = self.mox.CreateMock(result_ranker.CountRanker)
    self.apple_ranker_key = self.mox.CreateMock(datastore_types.Key)
    self.coconut_ranker = self.mox.CreateMock(result_ranker.LastNRanker)
    self.coconut_ranker_key = self.mox.CreateMock(datastore_types.Key)

    self.client = Client() 
开发者ID:elsigh,项目名称:browserscope,代码行数:17,代码来源:test_admin_rankers.py

示例13: setUp

# 需要导入模块: from django.test import client [as 别名]
# 或者: from django.test.client import Client [as 别名]
def setUp(self):
    self.client = Client()
    self.test_set = mock_data.MockTestSet(self.CATEGORY)
    all_test_sets.AddTestSet(self.test_set)
    self.mox = mox.Mox() 
开发者ID:elsigh,项目名称:browserscope,代码行数:7,代码来源:test_manage_dirty.py

示例14: testAboutPageWorks

# 需要导入模块: from django.test import client [as 别名]
# 或者: from django.test.client import Client [as 别名]
def testAboutPageWorks(self):
    client = Client()
    for test_set in all_test_sets.GetAllTestSets():
      category = test_set.category
      logging.info('category: %s' % category)
      response = self.client.get('/%s/about' % category, {},
          **mock_data.UNIT_TEST_UA)
      self.assertEqual(200, response.status_code, 'No about for %s' % category) 
开发者ID:elsigh,项目名称:browserscope,代码行数:10,代码来源:test_categories.py

示例15: setUp

# 需要导入模块: from django.test import client [as 别名]
# 或者: from django.test.client import Client [as 别名]
def setUp(self):
    self.client = Client()
    ua_string = ('Mozilla/5.0 (X11 U Linux armv6l de-DE rv:1.9a6pre) '
                 'Gecko/20080606 '
                 'Firefox/3.0a1 Tablet browser 0.3.7 '
                 'RX-34+RX-44+RX-48_DIABLO_4.2008.23-14')
    self.ua = UserAgent.factory(ua_string) 
开发者ID:elsigh,项目名称:browserscope,代码行数:9,代码来源:test_admin.py


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