本文整理汇总了Python中openedx.core.djangoapps.catalog.tests.factories.ProgramFactory类的典型用法代码示例。如果您正苦于以下问题:Python ProgramFactory类的具体用法?Python ProgramFactory怎么用?Python ProgramFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ProgramFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _create_catalog_program
def _create_catalog_program(self, catalog_org):
""" helper method to create a cached catalog program """
program = ProgramFactory.create(
authoring_organizations=[catalog_org]
)
cache.set(PROGRAM_CACHE_KEY_TPL.format(uuid=program['uuid']), program, None)
return program
示例2: test_get_many_with_missing
def test_get_many_with_missing(self, mock_cache, mock_warning, mock_info):
programs = ProgramFactory.create_batch(3)
all_programs = {
PROGRAM_CACHE_KEY_TPL.format(uuid=program['uuid']): program for program in programs
}
partial_programs = {
PROGRAM_CACHE_KEY_TPL.format(uuid=program['uuid']): program for program in programs[:2]
}
def fake_get_many(keys):
if len(keys) == 1:
return {PROGRAM_CACHE_KEY_TPL.format(uuid=programs[-1]['uuid']): programs[-1]}
else:
return partial_programs
mock_cache.get.return_value = [program['uuid'] for program in programs]
mock_cache.get_many.side_effect = fake_get_many
actual_programs = get_programs(self.site)
# All 3 cached programs should be returned. An info message should be
# logged about the one that was initially missing, but the code should
# be able to stitch together all the details.
self.assertEqual(
set(program['uuid'] for program in actual_programs),
set(program['uuid'] for program in all_programs.values())
)
self.assertFalse(mock_warning.called)
mock_info.assert_called_with('Failed to get details for 1 programs. Retrying.')
for program in actual_programs:
key = PROGRAM_CACHE_KEY_TPL.format(uuid=program['uuid'])
self.assertEqual(program, all_programs[key])
示例3: setUp
def setUp(self):
super(TestCachePrograms, self).setUp()
httpretty.httpretty.reset()
self.catalog_integration = self.create_catalog_integration()
self.site_domain = 'testsite.com'
self.set_up_site(
self.site_domain,
{
'COURSE_CATALOG_API_URL': self.catalog_integration.get_internal_api_url().rstrip('/')
}
)
self.list_url = self.catalog_integration.get_internal_api_url().rstrip('/') + '/programs/'
self.detail_tpl = self.list_url.rstrip('/') + '/{uuid}/'
self.pathway_url = self.catalog_integration.get_internal_api_url().rstrip('/') + '/pathways/'
self.programs = ProgramFactory.create_batch(3)
self.pathways = PathwayFactory.create_batch(3)
for pathway in self.pathways:
self.programs += pathway['programs']
self.uuids = [program['uuid'] for program in self.programs]
# add some of the previously created programs to some pathways
self.pathways[0]['programs'].extend([self.programs[0], self.programs[1]])
self.pathways[1]['programs'].append(self.programs[0])
示例4: setUp
def setUp(self):
super(ProgramPageBase, self).setUp()
self.set_programs_api_configuration(is_enabled=True)
self.programs = ProgramFactory.create_batch(3)
self.username = None
示例5: test_completed_programs
def test_completed_programs(self, mock_completed_course_runs, mock_get_programs):
"""Verify that completed programs are correctly identified."""
data = ProgramFactory.create_batch(3)
mock_get_programs.return_value = data
program_uuids = []
course_run_keys = []
for program in data:
program_uuids.append(program['uuid'])
for course in program['courses']:
for course_run in course['course_runs']:
course_run_keys.append(course_run['key'])
# Verify that no programs are complete.
meter = ProgramProgressMeter(self.site, self.user)
self.assertEqual(meter.completed_programs, [])
# Complete all programs.
self._create_enrollments(*course_run_keys)
mock_completed_course_runs.return_value = [
{'course_run_id': course_run_key, 'type': MODES.verified}
for course_run_key in course_run_keys
]
# Verify that all programs are complete.
meter = ProgramProgressMeter(self.site, self.user)
self.assertEqual(meter.completed_programs, program_uuids)
示例6: test_get_programs_by_types
def test_get_programs_by_types(self, mock_get_edx_api_data):
programs = ProgramFactory.create_batch(2)
mock_get_edx_api_data.return_value = programs
data = get_programs(types=self.types)
self.assert_contract(mock_get_edx_api_data.call_args, types=self.types)
self.assertEqual(data, programs)
示例7: setUp
def setUp(self):
super(TestProgramMarketingDataExtender, self).setUp()
self.course_price = 100
self.number_of_courses = 2
self.program = ProgramFactory(
courses=[self._create_course(self.course_price) for __ in range(self.number_of_courses)]
)
示例8: setup_catalog_cache
def setup_catalog_cache(self, program_uuid, organization_key):
"""
helper function to initialize a cached program with an single authoring_organization
"""
catalog_org = CatalogOrganizationFactory.create(key=organization_key)
program = ProgramFactory.create(
uuid=program_uuid,
authoring_organizations=[catalog_org]
)
cache.set(PROGRAM_CACHE_KEY_TPL.format(uuid=program_uuid), program, None)
示例9: setUp
def setUp(self):
super(TestProgramMarketingDataExtender, self).setUp()
# Ensure the E-Commerce service user exists
UserFactory(username=settings.ECOMMERCE_SERVICE_WORKER_USERNAME, is_staff=True)
self.course_price = 100
self.number_of_courses = 2
self.program = ProgramFactory(
courses=[self._create_course(self.course_price) for __ in range(self.number_of_courses)]
)
示例10: setUp
def setUp(self):
super(ProgramPageBase, self).setUp()
self.set_programs_api_configuration(is_enabled=True)
self.programs = ProgramFactory.create_batch(3)
self.pathways = PathwayFactory.create_batch(3)
for pathway in self.pathways:
self.programs += pathway['programs']
# add some of the previously created programs to some pathways
self.pathways[0]['programs'].extend([self.programs[0], self.programs[1]])
self.pathways[1]['programs'].append(self.programs[0])
self.username = None
示例11: test_catalog_program_missing_org
def test_catalog_program_missing_org(self):
"""
Test OrganizationDoesNotExistException is thrown if the cached program does not
have an authoring organization.
"""
program = ProgramFactory.create(
uuid=self.program_uuid,
authoring_organizations=[]
)
cache.set(PROGRAM_CACHE_KEY_TPL.format(uuid=self.program_uuid), program, None)
organization = OrganizationFactory.create(short_name=self.organization_key)
provider = SAMLProviderConfigFactory.create(organization=organization)
self.create_social_auth_entry(self.user, provider, self.external_user_id)
with pytest.raises(OrganizationDoesNotExistException):
get_user_by_program_id(self.external_user_id, self.program_uuid)
示例12: setUp
def setUp(self):
super(TestCachePrograms, self).setUp()
self.catalog_integration = self.create_catalog_integration()
self.site_domain = 'testsite.com'
self.set_up_site(
self.site_domain,
{
'COURSE_CATALOG_API_URL': self.catalog_integration.get_internal_api_url().rstrip('/')
}
)
self.list_url = self.catalog_integration.get_internal_api_url().rstrip('/') + '/programs/'
self.detail_tpl = self.list_url.rstrip('/') + '/{uuid}/'
self.programs = ProgramFactory.create_batch(3)
self.uuids = [program['uuid'] for program in self.programs]
示例13: test_get_programs_with_type
def test_get_programs_with_type(self, mock_get_program_types, mock_get_programs):
"""Verify get_programs_with_type returns the expected list of programs."""
programs_with_program_type = []
programs = ProgramFactory.create_batch(2)
program_types = []
for program in programs:
program_type = ProgramTypeFactory(name=program['type'])
program_types.append(program_type)
program_with_type = copy.deepcopy(program)
program_with_type['type'] = program_type
programs_with_program_type.append(program_with_type)
mock_get_programs.return_value = programs
mock_get_program_types.return_value = program_types
actual = get_programs_with_type(self.site)
self.assertEqual(actual, programs_with_program_type)
示例14: TestProgramMarketingDataExtender
class TestProgramMarketingDataExtender(ModuleStoreTestCase):
"""Tests of the program data extender utility class."""
ECOMMERCE_CALCULATE_DISCOUNT_ENDPOINT = '{root}/api/v2/baskets/calculate/'.format(root=ECOMMERCE_URL_ROOT)
instructors = {
'instructors': [
{
'name': 'test-instructor1',
'organization': 'TextX',
},
{
'name': 'test-instructor2',
'organization': 'TextX',
}
]
}
def setUp(self):
super(TestProgramMarketingDataExtender, self).setUp()
# Ensure the E-Commerce service user exists
UserFactory(username=settings.ECOMMERCE_SERVICE_WORKER_USERNAME, is_staff=True)
self.course_price = 100
self.number_of_courses = 2
self.program = ProgramFactory(
courses=[_create_course(self, self.course_price) for __ in range(self.number_of_courses)],
applicable_seat_types=['verified']
)
def _prepare_program_for_discounted_price_calculation_endpoint(self):
"""
Program's applicable seat types should match some or all seat types of the seats that are a part of the program.
Otherwise, ecommerce API endpoint for calculating the discounted price won't be called.
Returns:
seat: seat for which the discount is applicable
"""
self.ecommerce_service = EcommerceService()
seat = self.program['courses'][0]['course_runs'][0]['seats'][0]
self.program['applicable_seat_types'] = [seat['type']]
return seat
def _update_discount_data(self, mock_discount_data):
"""
Helper method that updates mocked discount data with
- a flag indicating whether the program price is discounted
- the amount of the discount (0 in case there's no discount)
"""
program_discounted_price = mock_discount_data['total_incl_tax']
program_full_price = mock_discount_data['total_incl_tax_excl_discounts']
mock_discount_data.update({
'is_discounted': program_discounted_price < program_full_price,
'discount_value': program_full_price - program_discounted_price
})
def test_instructors(self):
data = ProgramMarketingDataExtender(self.program, self.user).extend()
self.program.update(self.instructors['instructors'])
self.assertEqual(data, self.program)
def test_course_pricing(self):
data = ProgramMarketingDataExtender(self.program, self.user).extend()
program_full_price = self.course_price * self.number_of_courses
self.assertEqual(data['number_of_courses'], self.number_of_courses)
self.assertEqual(data['full_program_price'], program_full_price)
self.assertEqual(data['avg_price_per_course'], program_full_price / self.number_of_courses)
def test_course_pricing_when_all_course_runs_have_no_seats(self):
# Create three seatless course runs and add them to the program
course_runs = []
for __ in range(3):
course = ModuleStoreCourseFactory()
course = self.update_course(course, self.user.id)
course_runs.append(CourseRunFactory(key=unicode(course.id), seats=[]))
program = ProgramFactory(courses=[CourseFactory(course_runs=course_runs)])
data = ProgramMarketingDataExtender(program, self.user).extend()
self.assertEqual(data['number_of_courses'], len(program['courses']))
self.assertEqual(data['full_program_price'], 0.0)
self.assertEqual(data['avg_price_per_course'], 0.0)
@ddt.data(True, False)
@mock.patch(UTILS_MODULE + '.has_access')
def test_can_enroll(self, can_enroll, mock_has_access):
"""
Verify that the student's can_enroll status is included.
"""
mock_has_access.return_value = can_enroll
data = ProgramMarketingDataExtender(self.program, self.user).extend()
self.assertEqual(data['courses'][0]['course_runs'][0]['can_enroll'], can_enroll)
@httpretty.activate
def test_fetching_program_discounted_price(self):
"""
Authenticated users eligible for one click purchase should see the purchase button
#.........这里部分代码省略.........
示例15: TestProgramMarketingDataExtender
class TestProgramMarketingDataExtender(ModuleStoreTestCase):
"""Tests of the program data extender utility class."""
instructors = {
'instructors': [
{
'name': 'test-instructor1',
'organization': 'TextX',
},
{
'name': 'test-instructor2',
'organization': 'TextX',
}
]
}
def setUp(self):
super(TestProgramMarketingDataExtender, self).setUp()
self.course_price = 100
self.number_of_courses = 2
self.program = ProgramFactory(
courses=[self._create_course(self.course_price) for __ in range(self.number_of_courses)]
)
def _create_course(self, course_price):
"""
Creates the course in mongo and update it with the instructor data.
Also creates catalog course with respect to course run.
Returns:
Catalog course dict.
"""
course = ModuleStoreCourseFactory()
course.start = datetime.datetime.now(utc) - datetime.timedelta(days=1)
course.end = datetime.datetime.now(utc) + datetime.timedelta(days=1)
course.instructor_info = self.instructors
course = self.update_course(course, self.user.id)
course_run = CourseRunFactory(
key=unicode(course.id),
seats=[SeatFactory(price=course_price)]
)
return CourseFactory(course_runs=[course_run])
def test_instructors(self):
data = ProgramMarketingDataExtender(self.program, self.user).extend()
self.program.update(self.instructors['instructors'])
self.assertEqual(data, self.program)
def test_course_pricing(self):
data = ProgramMarketingDataExtender(self.program, self.user).extend()
program_full_price = self.course_price * self.number_of_courses
self.assertEqual(data['number_of_courses'], self.number_of_courses)
self.assertEqual(data['full_program_price'], program_full_price)
self.assertEqual(data['avg_price_per_course'], program_full_price / self.number_of_courses)
@ddt.data(True, False)
@mock.patch(UTILS_MODULE + '.has_access')
def test_can_enroll(self, can_enroll, mock_has_access):
"""
Verify that the student's can_enroll status is included.
"""
mock_has_access.return_value = can_enroll
data = ProgramMarketingDataExtender(self.program, self.user).extend()
self.assertEqual(data['courses'][0]['course_runs'][0]['can_enroll'], can_enroll)