本文整理汇总了Python中courses.factories.CourseFactory.create方法的典型用法代码示例。如果您正苦于以下问题:Python CourseFactory.create方法的具体用法?Python CourseFactory.create怎么用?Python CourseFactory.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类courses.factories.CourseFactory
的用法示例。
在下文中一共展示了CourseFactory.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_returns_model_if_string_provided
# 需要导入模块: from courses.factories import CourseFactory [as 别名]
# 或者: from courses.factories.CourseFactory import create [as 别名]
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
# 需要导入模块: from courses.factories import CourseFactory [as 别名]
# 或者: from courses.factories.CourseFactory import create [as 别名]
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: test_complete
# 需要导入模块: from courses.factories import CourseFactory [as 别名]
# 或者: from courses.factories.CourseFactory import create [as 别名]
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
示例4: setUpTestData
# 需要导入模块: from courses.factories import CourseFactory [as 别名]
# 或者: from courses.factories.CourseFactory import create [as 别名]
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
)
示例5: test_count_courses_passed_normal
# 需要导入模块: from courses.factories import CourseFactory [as 别名]
# 或者: from courses.factories.CourseFactory import create [as 别名]
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
示例6: test_count_courses_mixed_fa
# 需要导入模块: from courses.factories import CourseFactory [as 别名]
# 或者: from courses.factories.CourseFactory import create [as 别名]
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
示例7: generate_course_with_runs
# 需要导入模块: from courses.factories import CourseFactory [as 别名]
# 或者: from courses.factories.CourseFactory import create [as 别名]
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
示例8: test_user_exists
# 需要导入模块: from courses.factories import CourseFactory [as 别名]
# 或者: from courses.factories.CourseFactory import create [as 别名]
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})
示例9: test_course_team_email_with_no_enrollment
# 需要导入模块: from courses.factories import CourseFactory [as 别名]
# 或者: from courses.factories.CourseFactory import create [as 别名]
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
示例10: handle
# 需要导入模块: from courses.factories import CourseFactory [as 别名]
# 或者: from courses.factories.CourseFactory import create [as 别名]
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')
示例11: test_lookup_by_nonexistent_field
# 需要导入模块: from courses.factories import CourseFactory [as 别名]
# 或者: from courses.factories.CourseFactory import create [as 别名]
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
# 需要导入模块: from courses.factories import CourseFactory [as 别名]
# 或者: from courses.factories.CourseFactory import create [as 别名]
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_returns_string_for_all_objects
# 需要导入模块: from courses.factories import CourseFactory [as 别名]
# 或者: from courses.factories.CourseFactory import create [as 别名]
def test_returns_string_for_all_objects(self): # pylint: disable=no-self-use
"""model-to-string returns correct strings"""
e1 = EdxAuthorFactory.create()
e2 = EdxAuthorFactory.create()
co = CourseFactory.create()
co.instructors.add(e1)
co.instructors.add(e2)
f = SMMF(model=EdxAuthor, lookup="edx_uid")
assert sorted([str(e1), str(e2)]) == sorted(f.to_representation(co.instructors))
示例14: test_course_team_email_unpaid
# 需要导入模块: from courses.factories import CourseFactory [as 别名]
# 或者: from courses.factories.CourseFactory import create [as 别名]
def test_course_team_email_unpaid(self):
"""
Test that an attempt to send an email to the course team of an unpaid course will fail
"""
self.client.force_login(self.staff_user)
new_course = CourseFactory.create(contact_email='[email protected]')
ProgramEnrollmentFactory.create(user=self.staff_user, program=new_course.program)
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
示例15: test_create_course_certificate
# 需要导入模块: from courses.factories import CourseFactory [as 别名]
# 或者: from courses.factories.CourseFactory import create [as 别名]
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)