本文整理汇总了Python中edx_oauth2_provider.tests.factories.ClientFactory.save方法的典型用法代码示例。如果您正苦于以下问题:Python ClientFactory.save方法的具体用法?Python ClientFactory.save怎么用?Python ClientFactory.save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edx_oauth2_provider.tests.factories.ClientFactory
的用法示例。
在下文中一共展示了ClientFactory.save方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BackpopulateProgramCredentialsTests
# 需要导入模块: from edx_oauth2_provider.tests.factories import ClientFactory [as 别名]
# 或者: from edx_oauth2_provider.tests.factories.ClientFactory import save [as 别名]
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),
]),
]
),
],
#.........这里部分代码省略.........