本文整理汇总了Python中courses.factories.CourseFactory.create_batch方法的典型用法代码示例。如果您正苦于以下问题:Python CourseFactory.create_batch方法的具体用法?Python CourseFactory.create_batch怎么用?Python CourseFactory.create_batch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类courses.factories.CourseFactory
的用法示例。
在下文中一共展示了CourseFactory.create_batch方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_program_courses
# 需要导入模块: from courses.factories import CourseFactory [as 别名]
# 或者: from courses.factories.CourseFactory import create_batch [as 别名]
def test_program_courses(self):
"""
Test ProgramSerializer with multiple courses
"""
CourseFactory.create_batch(5, program=self.program)
data = ProgramSerializer(self.program, context=self.context).data
assert data == {
'id': self.program.id,
'title': self.program.title,
'programpage_url': None,
'enrolled': False,
'total_courses': 5,
}
示例2: test_program_page
# 需要导入模块: from courses.factories import CourseFactory [as 别名]
# 或者: from courses.factories.CourseFactory import create_batch [as 别名]
def test_program_page(browser, base_test_data, logged_in_student):
"""
Test viewing the program page
"""
courses = list(base_test_data.program.course_set.all()) + \
CourseFactory.create_batch(2, program=base_test_data.program)
page = ProgramPageFactory.create(program=base_test_data.program, title="A Program Title")
faculty = FacultyFactory.create_batch(3, program_page=page)
info_links = InfoLinksFactory.create_batch(3, program_page=page)
semester_dates = SemesterDateFactory.create_batch(3, program_page=page)
program_courses = ProgramCourseFactory.create_batch(
len(courses),
program_page=page,
course=Iterator(courses)
)
browser.get("/a-program-title/")
faculty_elements = browser.driver.find_elements_by_css_selector(".faculty-tile")
assert len(faculty) == len(faculty_elements)
info_elements = browser.driver.find_elements_by_css_selector(".program-contact-link")
assert len(info_links) == len(info_elements)
semester_elements = browser.driver.find_elements_by_css_selector(".semester-date")
assert len(semester_dates) == len(semester_elements)
program_course_elements = browser.driver.find_elements_by_css_selector(".program-course .title")
assert len(program_courses) == len(program_course_elements)
示例3: test_program_page_serializer
# 需要导入模块: from courses.factories import CourseFactory [as 别名]
# 或者: from courses.factories.CourseFactory import create_batch [as 别名]
def test_program_page_serializer(self):
"""
Test program page serializer
"""
page = ProgramPageFactory.create()
courses = CourseFactory.create_batch(3, program=page.program)
faculty = FacultyFactory.create_batch(3, program_page=page)
data = ProgramPageSerializer(page).data
data['faculty'] = sorted(data['faculty'], key=lambda member: member['name'])
assert data == {
"id": page.program.id,
"title": page.title,
"slug": ProgramPageSerializer().get_slug(page),
"faculty": FacultySerializer(sorted(faculty, key=lambda member: member.name), many=True).data,
"courses": CourseSerializer(courses, many=True).data,
}
示例4: test_semester_serialization
# 需要导入模块: from courses.factories import CourseFactory [as 别名]
# 或者: from courses.factories.CourseFactory import create_batch [as 别名]
def test_semester_serialization(self):
"""
Tests that each course run has a string semester value as part of its serialization
"""
num_courses = 5
courses = CourseFactory.create_batch(num_courses, program=self.program)
course_runs = [CourseRunFactory.create(course=course) for course in courses]
for course_run in course_runs:
CachedEnrollmentFactory.create(user=self.user, course_run=course_run, verified=True)
with patch(
'dashboard.serializers.get_year_season_from_course_run', autospec=True, return_value=(2017, 'Spring')
) as get_year_season_patch:
serialized_program_user = UserProgramSearchSerializer.serialize(self.program_enrollment)
assert len(serialized_program_user['courses']) == num_courses
assert all(
semester_enrollment['semester'] == '2017 - Spring'
for semester_enrollment in serialized_program_user['course_runs']
)
# multiply by two while serialize_enrollments has semester
assert get_year_season_patch.call_count == num_courses*2