本文整理汇总了Python中edx_oauth2_provider.tests.factories.ClientFactory类的典型用法代码示例。如果您正苦于以下问题:Python ClientFactory类的具体用法?Python ClientFactory怎么用?Python ClientFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ClientFactory类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
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
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
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
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
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
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: setUp
def setUp(self):
super(BackpopulateProgramCredentialsTests, self).setUp()
self.alice = UserFactory()
self.bob = UserFactory()
self.oauth2_user = UserFactory()
self.oauth2_client = ClientFactory(name=ProgramsApiConfig.OAUTH2_CLIENT_NAME, client_type=CONFIDENTIAL)
# Disable certification to prevent the task from being triggered when
# setting up test data (i.e., certificates with a passing status), thereby
# skewing mock call counts.
self.create_programs_config(enable_certification=False)
示例8: test_oauth
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)
示例9: test_oauth_csv
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)
示例10: create_user_and_access_token
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
示例11: create_user_and_access_token
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
示例12: BackpopulateProgramCredentialsTests
class BackpopulateProgramCredentialsTests(ProgramsApiConfigMixin, TestCase):
"""Tests for the backpopulate_program_credentials management command."""
course_id, alternate_course_id = 'org/course/run', 'org/alternate/run'
def setUp(self):
super(BackpopulateProgramCredentialsTests, self).setUp()
self.alice = UserFactory()
self.bob = UserFactory()
self.oauth2_user = UserFactory()
self.oauth2_client = ClientFactory(name=ProgramsApiConfig.OAUTH2_CLIENT_NAME, client_type=CONFIDENTIAL)
# Disable certification to prevent the task from being triggered when
# setting up test data (i.e., certificates with a passing status), thereby
# skewing mock call counts.
self.create_programs_config(enable_certification=False)
def _link_oauth2_user(self):
"""Helper to link user and OAuth2 client."""
self.oauth2_client.user = self.oauth2_user
self.oauth2_client.save() # pylint: disable=no-member
def _mock_programs_api(self, data):
"""Helper for mocking out Programs API URLs."""
self.assertTrue(httpretty.is_enabled(), msg='httpretty must be enabled to mock Programs API calls.')
url = ProgramsApiConfig.current().internal_api_url.strip('/') + '/programs/'
body = json.dumps({'results': data})
httpretty.register_uri(httpretty.GET, url, body=body, content_type='application/json')
@ddt.data(True, False)
def test_handle(self, commit, mock_task):
"""Verify that relevant tasks are only enqueued when the commit option is passed."""
data = [
factories.Program(
organizations=[factories.Organization()],
course_codes=[
factories.CourseCode(run_modes=[
factories.RunMode(course_key=self.course_id),
]),
]
),
]
self._mock_programs_api(data)
self._link_oauth2_user()
GeneratedCertificateFactory(
user=self.alice,
course_id=self.course_id,
mode=MODES.verified,
status=CertificateStatuses.downloadable,
)
GeneratedCertificateFactory(
user=self.bob,
course_id=self.alternate_course_id,
mode=MODES.verified,
status=CertificateStatuses.downloadable,
)
call_command('backpopulate_program_credentials', commit=commit)
if commit:
mock_task.assert_called_once_with(self.alice.username)
else:
mock_task.assert_not_called()
@ddt.data(
[
factories.Program(
organizations=[factories.Organization()],
course_codes=[
factories.CourseCode(run_modes=[
factories.RunMode(course_key=course_id),
]),
]
),
factories.Program(
organizations=[factories.Organization()],
course_codes=[
factories.CourseCode(run_modes=[
factories.RunMode(course_key=alternate_course_id),
]),
]
),
],
[
factories.Program(
organizations=[factories.Organization()],
course_codes=[
factories.CourseCode(run_modes=[
factories.RunMode(course_key=course_id),
]),
factories.CourseCode(run_modes=[
factories.RunMode(course_key=alternate_course_id),
]),
]
),
],
#.........这里部分代码省略.........