本文整理汇总了Python中courses.factories.CourseFactory类的典型用法代码示例。如果您正苦于以下问题:Python CourseFactory类的具体用法?Python CourseFactory怎么用?Python CourseFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CourseFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_returns_model_if_string_provided
def test_returns_model_if_string_provided(self): # pylint: disable=no-self-use
"""string-to-model returns correct model for single string"""
uid = "2d133482b3214a119f55c3060d882ceb"
CourseFactory.create()
f = SMMF(model=EdxAuthor, lookup="edx_uid")
ms = f.to_internal_value(uid)
assert len(ms) == 1
assert ms[0].edx_uid == uid
示例2: test_returns_models_if_list_provided
def test_returns_models_if_list_provided(self): # pylint: disable=no-self-use
"""string-to-model returns correct model for list"""
uid = "2d133482b3214a119f55c3060d882ceb"
uid2 = "3d133482b3214a119f55c3060d882ceb"
CourseFactory.create()
f = SMMF(model=EdxAuthor, lookup="edx_uid")
ms = f.to_internal_value([uid, uid2])
assert len(ms) == 2
assert ms[0].edx_uid != ms[1].edx_uid
assert ms[0].edx_uid in [uid, uid2]
assert ms[1].edx_uid in [uid, uid2]
示例3: setUpTestData
def setUpTestData(cls):
super().setUpTestData()
# create an user
cls.user = UserFactory.create()
cls.cached_edx_user_data = MagicMock(
spec=CachedEdxUserData,
enrollments=CachedEnrollment.deserialize_edx_data(cls.enrollments_json),
certificates=CachedCertificate.deserialize_edx_data(cls.certificates_json),
current_grades=CachedCurrentGrade.deserialize_edx_data(cls.current_grades_json),
)
# create the programs
cls.program = ProgramFactory.create(live=True, financial_aid_availability=False, price=1000)
cls.program_financial_aid = ProgramFactory.create(live=True, financial_aid_availability=True, price=1000)
# create course runs for the normal program
cls.course = CourseFactory.create(program=cls.program)
expected_course_keys = [
"course-v1:edX+DemoX+Demo_Course",
"course-v1:MITx+8.MechCX+2014_T1",
'',
None,
'course-v1:odl+FOO102+CR-FALL16'
]
cls.cruns = []
for course_key in expected_course_keys:
course_run = CourseRunFactory.create(
course=cls.course,
edx_course_key=course_key
)
if course_key:
cls.cruns.append(course_run)
# and the program with financial aid
finaid_course = CourseFactory.create(program=cls.program_financial_aid)
cls.now = now_in_utc()
cls.end_date = cls.now - timedelta(weeks=45)
cls.crun_fa = CourseRunFactory.create(
course=finaid_course,
start_date=cls.now-timedelta(weeks=52),
end_date=cls.end_date,
enrollment_start=cls.now-timedelta(weeks=62),
enrollment_end=cls.now-timedelta(weeks=53),
edx_course_key="course-v1:odl+FOO101+CR-FALL15"
)
cls.crun_fa2 = CourseRunFactory.create(
course=finaid_course
)
CourseRunFactory.create(
course=finaid_course,
edx_course_key=None
)
示例4: test_complete
def test_complete(self, first_has_frozen, second_has_frozen, result):
"""
Test has_frozen_grades_for_all_courses
"""
course_1 = CourseFactory.create(title="Title")
course_2 = CourseFactory.create(title="Title", program=course_1.program)
if first_has_frozen:
self.create_frozen_run(course_1)
if second_has_frozen:
self.create_frozen_run(course_2)
assert course_1.program.has_frozen_grades_for_all_courses() is result
示例5: test_program_courses
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,
}
示例6: test_count_courses_passed_normal
def test_count_courses_passed_normal(self):
"""
Assert that count_courses_passed works in case of normal program.
"""
mmtrack = MMTrack(
user=self.user,
program=self.program,
edx_user_data=self.cached_edx_user_data
)
assert mmtrack.count_courses_passed() == 0
course_run = self.cruns[0]
FinalGradeFactory.create(
user=self.user,
course_run=course_run,
passed=True
)
assert mmtrack.count_courses_passed() == 1
course = CourseFactory.create(program=self.program)
final_grade = FinalGradeFactory.create(
user=self.user,
course_run__course=course,
passed=True
)
mmtrack.edx_course_keys.add(final_grade.course_run.edx_course_key)
assert mmtrack.count_courses_passed() == 2
示例7: test_count_courses_mixed_fa
def test_count_courses_mixed_fa(self):
"""
Test count_courses_passed with mixed course-exam configuration
"""
mmtrack = MMTrack(
user=self.user,
program=self.program_financial_aid,
edx_user_data=self.cached_edx_user_data
)
# this is course with exam run and the user has CombinedFinalGrade for it
course_with_exam_1 = CourseFactory.create(program=self.program_financial_aid)
ExamRunFactory.create(course=course_with_exam_1, date_grades_available=now_in_utc()-timedelta(weeks=1))
CombinedFinalGrade.objects.create(user=self.user, course=course_with_exam_1, grade=0.7)
# create course with exam run the user did not pass
ExamRunFactory.create(
course__program=self.program_financial_aid,
date_grades_available=now_in_utc() - timedelta(weeks=1)
)
# another course with no exam
FinalGradeFactory.create(
user=self.user,
course_run=self.crun_fa,
passed=True
)
assert mmtrack.count_courses_passed() == 2
示例8: test_program_page
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)
示例9: generate_course_with_runs
def generate_course_with_runs(program, course_params=None, course_run_count=1):
"""
Helper method to generate a Course with CourseRuns for a Program
"""
course_params = course_params or {}
course = CourseFactory.create(program=program, **course_params)
course_runs = CourseRunFactory.create_batch(course_run_count, course=course)
return course, course_runs
示例10: test_user_exists
def test_user_exists(self):
"""If no uid not set, 400"""
course = CourseFactory.create()
author = EdxAuthorFactory.create(edx_uid=str(uuid.uuid4().hex))
course.instructors.add(author)
resp = self.client.get(reverse('user-existence'), {'uid': author.edx_uid})
self.assertEqual(resp.status_code, 200)
self.assertEqual(json.loads(resp.content.decode('utf-8')), {'exists': True})
示例11: test_lookup_by_nonexistent_field
def test_lookup_by_nonexistent_field(self):
"""
Properly handles error if non-existent field provided.
"""
WebhookFactory.create(url="http://example.org")
course = CourseFactory.create()
with mock.patch('webhooks.tasks.requests', autospec=True):
with pytest.raises(FieldError):
publish_webhook('courses.Course', 'asdf', course.pk)
示例12: test_lookup_by_non_pk
def test_lookup_by_non_pk(self):
"""
Should be able to look things up by uuid too.
"""
WebhookFactory.create(url="http://example.org")
course = CourseFactory.create()
with mock.patch('webhooks.tasks.requests', autospec=True) as mock_requests:
publish_webhook('courses.Course', 'uuid', course.uuid)
assert mock_requests.post.call_count == 1
示例13: test_course_team_email_with_no_enrollment
def test_course_team_email_with_no_enrollment(self):
"""
Test that an attempt to send an email to a course in an un-enrolled program will fail
"""
self.client.force_login(self.staff_user)
new_course = CourseFactory.create(contact_email='[email protected]')
url = reverse(self.url_name, kwargs={'course_id': new_course.id})
resp = self.client.post(url, data=self.request_data, format='json')
assert resp.status_code == status.HTTP_403_FORBIDDEN
示例14: handle
def handle(self, *args, **options):
# Check if we have a semester
try:
semester = Semester.get_current()
course = CourseFactory.create(semester = semester)
except IndexError:
course = CourseFactory.create()
self.stdout.write('Created Course {}.\n'.format(course))
assignment = AssignmentFactory.create(course = course)
self.stdout.write('Created Assignment {}.\n'.format(assignment))
faculty = FacultyFactory.create()
course.faculty.add(faculty)
self.stdout.write('Created Faculty {} and assigned to course.\n'.format(faculty))
self.stdout.write('Successfully populated DB.\n')
示例15: test_create_course_certificate
def test_create_course_certificate(self, generate_program_cert_mock, mock_on_commit):
"""
Test that generate_program_certificate is called when a course
certificate is created
"""
course = CourseFactory.create()
cert = MicromastersCourseCertificateFactory.create(user=self.user, course=course)
generate_program_cert_mock.assert_called_once_with(self.user, course.program)
cert.save()
generate_program_cert_mock.assert_called_once_with(self.user, course.program)