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