本文整理汇总了Python中edx_oauth2_provider.tests.factories.ClientFactory.create方法的典型用法代码示例。如果您正苦于以下问题:Python ClientFactory.create方法的具体用法?Python ClientFactory.create怎么用?Python ClientFactory.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edx_oauth2_provider.tests.factories.ClientFactory
的用法示例。
在下文中一共展示了ClientFactory.create方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: from edx_oauth2_provider.tests.factories import ClientFactory [as 别名]
# 或者: from edx_oauth2_provider.tests.factories.ClientFactory import create [as 别名]
def setUp(self):
super(AwardProgramCertificatesTestCase, self).setUp()
self.create_credentials_config()
self.student = UserFactory.create(username='test-student')
self.catalog_integration = self.create_catalog_integration()
ClientFactory.create(name='credentials')
UserFactory.create(username=settings.CREDENTIALS_SERVICE_USERNAME) # pylint: disable=no-member
示例2: setUp
# 需要导入模块: from edx_oauth2_provider.tests.factories import ClientFactory [as 别名]
# 或者: from edx_oauth2_provider.tests.factories.ClientFactory import create [as 别名]
def setUp(self):
super(AwardProgramCertificatesTestCase, self).setUp()
self.create_programs_config()
self.create_credentials_config()
self.student = UserFactory.create(username="test-student")
ClientFactory.create(name="programs")
ClientFactory.create(name="credentials")
UserFactory.create(username=settings.CREDENTIALS_SERVICE_USERNAME) # pylint: disable=no-member
示例3: test_get_api_client
# 需要导入模块: from edx_oauth2_provider.tests.factories import ClientFactory [as 别名]
# 或者: from edx_oauth2_provider.tests.factories.ClientFactory import create [as 别名]
def test_get_api_client(self, mock_build_token):
"""
Ensure the function is making the right API calls based on inputs
"""
student = UserFactory()
ClientFactory.create(name='credentials')
api_config = self.create_credentials_config()
mock_build_token.return_value = 'test-token'
api_client = tasks.get_api_client(api_config, student)
expected = CREDENTIALS_INTERNAL_SERVICE_URL.strip('/') + '/api/v2/'
self.assertEqual(api_client._store['base_url'], expected) # pylint: disable=protected-access
self.assertEqual(api_client._store['session'].auth.token, 'test-token') # pylint: disable=protected-access
示例4: test_get_api_client
# 需要导入模块: from edx_oauth2_provider.tests.factories import ClientFactory [as 别名]
# 或者: from edx_oauth2_provider.tests.factories.ClientFactory import create [as 别名]
def test_get_api_client(self, mock_get_id_token):
"""
Ensure the function is making the right API calls based on inputs
"""
student = UserFactory()
ClientFactory.create(name="programs")
api_config = self.create_programs_config(internal_service_url="http://foo", api_version_number=99)
mock_get_id_token.return_value = "test-token"
api_client = tasks.get_api_client(api_config, student)
self.assertEqual(mock_get_id_token.call_args[0], (student, "programs"))
self.assertEqual(api_client._store["base_url"], "http://foo/api/v99/") # pylint: disable=protected-access
self.assertEqual(api_client._store["session"].auth.token, "test-token") # pylint: disable=protected-access
示例5: test_get_api_client
# 需要导入模块: from edx_oauth2_provider.tests.factories import ClientFactory [as 别名]
# 或者: from edx_oauth2_provider.tests.factories.ClientFactory import create [as 别名]
def test_get_api_client(self, mock_get_id_token):
"""
Ensure the function is making the right API calls based on inputs
"""
student = UserFactory()
ClientFactory.create(name='programs')
api_config = self.create_programs_config(
internal_service_url='http://foo',
api_version_number=99,
)
mock_get_id_token.return_value = 'test-token'
api_client = tasks.get_api_client(api_config, student)
self.assertEqual(mock_get_id_token.call_args[0], (student, 'programs'))
self.assertEqual(api_client._store['base_url'], 'http://foo/api/v99/') # pylint: disable=protected-access
self.assertEqual(api_client._store['session'].auth.token, 'test-token') # pylint: disable=protected-access
示例6: setUp
# 需要导入模块: from edx_oauth2_provider.tests.factories import ClientFactory [as 别名]
# 或者: from edx_oauth2_provider.tests.factories.ClientFactory import create [as 别名]
def setUp(self):
super(AwardCourseCertificatesTestCase, self).setUp()
self.course = CourseOverviewFactory.create(
self_paced=True # Any option to allow the certificate to be viewable for the course
)
self.student = UserFactory.create(username='test-student')
# Instantiate the Certificate first so that the config doesn't execute issuance
self.certificate = GeneratedCertificateFactory.create(
user=self.student,
mode='verified',
course_id=self.course.id,
status='downloadable'
)
self.create_credentials_config()
self.site = SiteFactory()
ClientFactory.create(name='credentials')
UserFactory.create(username=settings.CREDENTIALS_SERVICE_USERNAME)
示例7: test_oauth
# 需要导入模块: from edx_oauth2_provider.tests.factories import ClientFactory [as 别名]
# 或者: from edx_oauth2_provider.tests.factories.ClientFactory import create [as 别名]
def test_oauth(self):
""" Verify the endpoint supports OAuth, and only allows authorization for staff users. """
user = UserFactory(is_staff=False)
oauth_client = ClientFactory.create()
access_token = AccessTokenFactory.create(user=user, client=oauth_client).token
headers = {
'HTTP_AUTHORIZATION': 'Bearer ' + access_token
}
# Non-staff users should not have access to the API
response = self.client.get(self.path, **headers)
self.assertEqual(response.status_code, 403)
# Staff users should have access to the API
user.is_staff = True
user.save()
response = self.client.get(self.path, **headers)
self.assertEqual(response.status_code, 200)
示例8: test_oauth_csv
# 需要导入模块: from edx_oauth2_provider.tests.factories import ClientFactory [as 别名]
# 或者: from edx_oauth2_provider.tests.factories.ClientFactory import create [as 别名]
def test_oauth_csv(self):
""" Verify the endpoint supports OAuth, and only allows authorization for staff users. """
cohorts.add_cohort(self.course_key, "DEFAULT", "random")
path = reverse('api_cohorts:cohort_users_csv', kwargs={'course_key_string': self.course_str})
user = UserFactory(is_staff=False)
oauth_client = ClientFactory.create()
access_token = AccessTokenFactory.create(user=user, client=oauth_client).token
headers = {
'HTTP_AUTHORIZATION': 'Bearer ' + access_token
}
# Non-staff users should not have access to the API
response = self.client.post(path=path, **headers)
self.assertEqual(response.status_code, 403)
# Staff users should have access to the API
user.is_staff = True
user.save()
response = self.client.post(path=path, **headers)
self.assertEqual(response.status_code, 400)
示例9: create_user_and_access_token
# 需要导入模块: from edx_oauth2_provider.tests.factories import ClientFactory [as 别名]
# 或者: from edx_oauth2_provider.tests.factories.ClientFactory import create [as 别名]
def create_user_and_access_token(self):
# pylint: disable=missing-docstring
self.user = GlobalStaffFactory.create()
self.oauth_client = ClientFactory.create()
self.access_token = AccessTokenFactory.create(user=self.user, client=self.oauth_client).token
示例10: create_user_and_access_token
# 需要导入模块: from edx_oauth2_provider.tests.factories import ClientFactory [as 别名]
# 或者: from edx_oauth2_provider.tests.factories.ClientFactory import create [as 别名]
def create_user_and_access_token(self):
self.create_user()
self.oauth_client = ClientFactory.create()
self.access_token = AccessTokenFactory.create(user=self.user, client=self.oauth_client).token