本文整理汇总了Python中dashboard.factories.ProgramEnrollmentFactory类的典型用法代码示例。如果您正苦于以下问题:Python ProgramEnrollmentFactory类的具体用法?Python ProgramEnrollmentFactory怎么用?Python ProgramEnrollmentFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ProgramEnrollmentFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUpTestData
def setUpTestData(cls):
super(SearchTests, cls).setUpTestData()
# create some students
with mute_signals(post_save):
cls.students = [(ProfileFactory.create(filled_out=True)).user for _ in range(30)]
# create the programs
cls.program1 = ProgramFactory.create(live=True)
cls.program2 = ProgramFactory.create(live=True)
cls.program3 = ProgramFactory.create(live=True)
# enroll the users in the programs
for num, student in enumerate(cls.students):
if num % 3 == 0:
program = cls.program1
elif num % 3 == 1:
program = cls.program2
else:
program = cls.program3
ProgramEnrollmentFactory.create(
user=student,
program=program
)
# create an user with a role for one program
cls.staff = UserFactory.create()
Role.objects.create(
user=cls.staff,
program=cls.program1,
role=Staff.ROLE_ID
)
# search URL
cls.search_url = reverse('search_api', kwargs={'elastic_url': ''})
示例2: test_learner_view_needs_paid_learner
def test_learner_view_needs_paid_learner(self, mock_mailgun_client):
"""
Test that a learner attempting to email another learner will only succeed if the sender
has paid for a course run in a program that the recipient is enrolled in
"""
mock_mailgun_client.send_individual_email.return_value = Mock(
spec=Response,
status_code=status.HTTP_200_OK,
json=mocked_json()
)
with mute_signals(post_save):
learner_profile = ProfileFactory.create(
user__email='[email protected]',
email_optin=True,
)
learner_user = learner_profile.user
ProgramEnrollmentFactory.create(user=learner_user, program=self.program)
CachedEnrollment.objects.filter(user=learner_user).delete()
self.client.force_login(learner_user)
url = reverse(self.url_name, kwargs={'student_id': self.recipient_user.profile.student_id})
resp_post = self.client.post(url, data=self.request_data, format='json')
assert resp_post.status_code == status.HTTP_403_FORBIDDEN
CachedEnrollmentFactory.create(user=learner_user, course_run__course__program=self.program, verified=True)
resp_post = self.client.post(url, data=self.request_data, format='json')
assert resp_post.status_code == status.HTTP_200_OK
示例3: test_multiple_success
def test_multiple_success(self):
"""test retire_users command success with more than one user"""
user_names = ["foo", "bar", "baz"]
for user_name in user_names:
user = UserFactory.create(username=user_name, is_active=True)
user.profile.email_optin = True
user.profile.save()
UserSocialAuthFactory.create(user=user, provider='not_edx')
for _ in range(TOTAL_PROGRAMS):
ProgramEnrollmentFactory.create(user=user)
assert user.is_active is True
assert user.profile.email_optin is True
assert UserSocialAuth.objects.filter(user=user).count() == 1
assert ProgramEnrollment.objects.filter(user=user).count() == TOTAL_PROGRAMS
self.command.handle("retire_users", users=user_names)
for user_name in user_names:
user = User.objects.get(username=user_name)
assert user.is_active is False
assert user.profile.email_optin is False
assert UserSocialAuth.objects.filter(user=user).count() == 0
assert ProgramEnrollment.objects.filter(user=user).count() == 0
示例4: test_add_moderators_to_channel
def test_add_moderators_to_channel(mocker, patched_users_api):
"""add_moderators_to_channel should add staff or instructors as moderators and subscribers"""
channel = ChannelFactory.create()
mods = []
for _ in range(3):
program = ChannelProgramFactory.create(channel=channel).program
with mute_signals(post_save):
mods += [
RoleFactory.create(
program=program,
user=ProfileFactory.create().user
).user for _ in range(5)
]
for __ in range(5):
# Add some users to the channel to show that being part of the channel is not enough to be added as a mod
ProgramEnrollmentFactory.create(program=program)
create_stub, _ = patched_users_api
create_stub.reset_mock()
add_subscriber_stub = mocker.patch('discussions.api.add_subscriber_to_channel', autospec=True)
add_moderator_stub = mocker.patch('discussions.api.add_moderator_to_channel', autospec=True)
api.add_moderators_to_channel(channel.name)
for mod in mods:
add_subscriber_stub.assert_any_call(channel.name, mod.discussion_user.username)
add_moderator_stub.assert_any_call(channel.name, mod.discussion_user.username)
create_stub.assert_any_call(mod.discussion_user)
assert add_subscriber_stub.call_count == len(mods)
assert add_moderator_stub.call_count == len(mods)
assert create_stub.call_count == len(mods)
示例5: test_financial_aid_with_application_with_full_profile
def test_financial_aid_with_application_with_full_profile(self):
"""
Test that financialAid request serializer works when profile is filled out.
"""
with mute_signals(post_save):
profile = ProfileFactory.create()
ProgramEnrollmentFactory.create(user=profile.user, program=self.program)
original_currency = 'USD'
original_income = 1000.0
serializer = FinancialAidRequestSerializer(
data={
'program_id': self.program.id,
'tier_program': self.min_tier_program,
'date_documents_sent': None,
'original_currency': original_currency,
'original_income': original_income
},
context={
'request': MagicMock(user=profile.user)
}
)
serializer.is_valid(raise_exception=True)
serializer.save()
assert serializer.data == {
'original_currency': original_currency,
'original_income': original_income,
'program_id': self.program.id
}
示例6: test_course_team_email_unpaid
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
示例7: test_bulk_authorize_for_exam_run_multiple
def test_bulk_authorize_for_exam_run_multiple(self):
"""Test that we check all program enrollments"""
ProgramEnrollmentFactory.create(program=self.program)
exam_run = ExamRunFactory.create(course=self.course_run.course)
assert ExamAuthorization.objects.filter(
course=exam_run.course,
).count() == 0
bulk_authorize_for_exam_run(exam_run)
assert ExamAuthorization.objects.filter(
course=exam_run.course,
user=self.user
).count() == 1
示例8: test_program_enrollment_add
def test_program_enrollment_add(self, index_type, mock_on_commit):
"""
Test that a newly created ProgramEnrollment is indexed properly
"""
assert es.search(index_type)['total'] == 0
program_enrollment = ProgramEnrollmentFactory.create()
assert_search(es.search(index_type), [program_enrollment], index_type=index_type)
示例9: test_role_delete
def test_role_delete(self, role, index_type, mock_on_commit):
"""
Test that `is_learner` status is restore once role is removed for a user.
"""
program_enrollment = ProgramEnrollmentFactory.create()
assert es.search(index_type)['total'] == DOC_TYPES_PER_ENROLLMENT
sources = get_sources(es.search(index_type))
# user is learner
assert sources[0]['program']['is_learner'] is True
Role.objects.create(
user=program_enrollment.user,
program=program_enrollment.program,
role=role
)
assert es.search(index_type)['total'] == DOC_TYPES_PER_ENROLLMENT
# user is not learner
sources = get_sources(es.search(index_type))
assert sources[0]['program']['is_learner'] is False
# when staff role is deleted
Role.objects.filter(
user=program_enrollment.user,
program=program_enrollment.program,
role=role
).delete()
assert es.search(index_type)['total'] == DOC_TYPES_PER_ENROLLMENT
sources = get_sources(es.search(index_type))
# user is learner
assert sources[0]['program']['is_learner'] is True
示例10: setUpTestData
def setUpTestData(cls):
cls.program, _ = create_program(past=True)
cls.course_run = cls.program.course_set.first().courserun_set.first()
cls.course = cls.course_run.course
cls.program_enrollment = ProgramEnrollmentFactory.create(program=cls.program)
cls.user = cls.program_enrollment.user
with mute_signals(post_save):
cls.final_grades = sorted([
FinalGradeFactory.create(
user=cls.user,
course_run=cls.course_run,
passed=False,
status=FinalGradeStatus.PENDING
),
FinalGradeFactory.create(
user=cls.user,
course_run__course=cls.course,
passed=True,
status=FinalGradeStatus.COMPLETE
),
FinalGradeFactory.create(
user=cls.user,
course_run__course=cls.course,
passed=True,
status=FinalGradeStatus.COMPLETE
),
], key=lambda final_grade: final_grade.course_run.end_date, reverse=True)
示例11: test_update_during_recreate_index
def test_update_during_recreate_index(self):
"""
If an indexing action happens during a recreate_index it should update all active indices
"""
conn = get_conn(verify=False)
recreate_index()
temp_aliases = {}
index_types = [PRIVATE_ENROLLMENT_INDEX_TYPE, PUBLIC_ENROLLMENT_INDEX_TYPE]
for index_type in index_types:
# create temporary index
temp_index = make_backing_index_name()
temp_alias = make_alias_name(index_type=index_type, is_reindexing=True)
clear_and_create_index(temp_index, index_type=index_type)
conn.indices.put_alias(index=temp_index, name=temp_alias)
temp_aliases[index_type] = temp_alias
with patch('search.signals.transaction.on_commit', side_effect=lambda callback: callback()):
program_enrollment = ProgramEnrollmentFactory.create()
for index_type in index_types:
assert_search(es.search(index_type), [program_enrollment], index_type=index_type)
# Temp alias should get updated
temp_alias = temp_aliases[index_type]
refresh_index(temp_alias)
temp_hits = conn.search(index=temp_alias)['hits']
assert_search(temp_hits, [program_enrollment], index_type=index_type)
示例12: test_update_percolate_memberships
def test_update_percolate_memberships(self, source_type, is_member, query_matches, mock_on_commit):
"""
Tests that existing memberships are updated where appropriate
"""
with mute_signals(post_save):
query = PercolateQueryFactory.create(source_type=source_type)
profile = ProfileFactory.create(filled_out=True)
program_enrollment = ProgramEnrollmentFactory.create(user=profile.user)
membership = PercolateQueryMembershipFactory.create(
user=profile.user,
query=query,
is_member=is_member,
needs_update=False
)
with patch(
'search.api._search_percolate_queries',
return_value=[query.id] if query_matches else []
) as search_percolate_queries_mock:
update_percolate_memberships(profile.user, source_type)
search_percolate_queries_mock.assert_called_once_with(program_enrollment)
membership.refresh_from_db()
assert membership.needs_update is (is_member is not query_matches)
示例13: test_document_needs_update_missing
def test_document_needs_update_missing(self):
"""
If a document doesn't exist on Elasticsearch, document_needs_update should return true
"""
with mute_signals(post_save):
enrollment = ProgramEnrollmentFactory.create()
assert document_needs_updating(enrollment) is True
示例14: test_program_enrollment_delete
def test_program_enrollment_delete(self, index_type, mock_on_commit):
"""
Test that ProgramEnrollment is removed from index after the user is removed
"""
program_enrollment = ProgramEnrollmentFactory.create()
assert es.search(index_type)['total'] == DOC_TYPES_PER_ENROLLMENT
program_enrollment.user.delete()
assert es.search(index_type)['total'] == 0
示例15: test_employment_add
def test_employment_add(self, index_type, mock_on_commit):
"""
Test that Employment is indexed after being added
"""
program_enrollment = ProgramEnrollmentFactory.create()
assert es.search(index_type)['total'] == DOC_TYPES_PER_ENROLLMENT
EmploymentFactory.create(profile=program_enrollment.user.profile, end_date=None)
assert_search(es.search(index_type), [program_enrollment], index_type=index_type)