本文整理汇总了Python中student.tests.factories.UserFactory类的典型用法代码示例。如果您正苦于以下问题:Python UserFactory类的具体用法?Python UserFactory怎么用?Python UserFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UserFactory类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_user_details_force_sync_username_conflict
def test_user_details_force_sync_username_conflict(self):
"""
The user details were attempted to be synced but the incoming username already exists for another account.
An email should still be sent in this case.
"""
# Create a user with an email that conflicts with the incoming value.
UserFactory.create(username='new_{}'.format(self.old_username))
# Begin the pipeline.
pipeline.user_details_force_sync(
auth_entry=pipeline.AUTH_ENTRY_LOGIN,
strategy=self.strategy,
details=self.details,
user=self.user,
)
# The username is not changed, but everything else is.
user = User.objects.get(pk=self.user.pk)
assert user.email == 'new+{}'.format(self.old_email)
assert user.username == self.old_username
assert user.profile.name == 'Grown Up {}'.format(self.old_fullname)
assert user.profile.country == 'PK'
# An email should still be sent because the email changed.
assert len(mail.outbox) == 1
开发者ID:eduNEXT,项目名称:edunext-platform,代码行数:26,代码来源:test_pipeline_integration.py
示例2: test_enrolled_students_features_keys_cohorted
def test_enrolled_students_features_keys_cohorted(self):
course = CourseFactory.create(org="test", course="course1", display_name="run1")
course.cohort_config = {'cohorted': True, 'auto_cohort': True, 'auto_cohort_groups': ['cohort']}
self.store.update_item(course, self.instructor.id)
cohorted_students = [UserFactory.create() for _ in xrange(10)]
cohort = CohortFactory.create(name='cohort', course_id=course.id, users=cohorted_students)
cohorted_usernames = [student.username for student in cohorted_students]
non_cohorted_student = UserFactory.create()
for student in cohorted_students:
cohort.users.add(student)
CourseEnrollment.enroll(student, course.id)
CourseEnrollment.enroll(non_cohorted_student, course.id)
instructor = InstructorFactory(course_key=course.id)
self.client.login(username=instructor.username, password='test')
query_features = ('username', 'cohort')
# There should be a constant of 2 SQL queries when calling
# enrolled_students_features. The first query comes from the call to
# User.objects.filter(...), and the second comes from
# prefetch_related('course_groups').
with self.assertNumQueries(2):
userreports = enrolled_students_features(course.id, query_features)
self.assertEqual(len([r for r in userreports if r['username'] in cohorted_usernames]), len(cohorted_students))
self.assertEqual(len([r for r in userreports if r['username'] == non_cohorted_student.username]), 1)
for report in userreports:
self.assertEqual(set(report.keys()), set(query_features))
if report['username'] in cohorted_usernames:
self.assertEqual(report['cohort'], cohort.name)
else:
self.assertEqual(report['cohort'], '[unassigned]')
开发者ID:luisvasq,项目名称:edx-platform,代码行数:30,代码来源:test_basic.py
示例3: test_transfer_students
def test_transfer_students(self):
student = UserFactory()
student.set_password(self.PASSWORD) # pylint: disable=E1101
student.save() # pylint: disable=E1101
# Original Course
original_course_location = locator.CourseLocator('Org0', 'Course0', 'Run0')
course = self._create_course(original_course_location)
# Enroll the student in 'verified'
CourseEnrollment.enroll(student, course.id, mode="verified")
# New Course 1
course_location_one = locator.CourseLocator('Org1', 'Course1', 'Run1')
new_course_one = self._create_course(course_location_one)
# New Course 2
course_location_two = locator.CourseLocator('Org2', 'Course2', 'Run2')
new_course_two = self._create_course(course_location_two)
original_key = unicode(course.id)
new_key_one = unicode(new_course_one.id)
new_key_two = unicode(new_course_two.id)
# Run the actual management command
transfer_students.Command().handle(
source_course=original_key, dest_course_list=new_key_one + "," + new_key_two
)
# Confirm the enrollment mode is verified on the new courses, and enrollment is enabled as appropriate.
self.assertEquals(('verified', False), CourseEnrollment.enrollment_mode_for_user(student, course.id))
self.assertEquals(('verified', True), CourseEnrollment.enrollment_mode_for_user(student, new_course_one.id))
self.assertEquals(('verified', True), CourseEnrollment.enrollment_mode_for_user(student, new_course_two.id))
开发者ID:CDOT-EDX,项目名称:edx-platform,代码行数:31,代码来源:test_transfer_students.py
示例4: setup_students_and_grades
def setup_students_and_grades(context):
"""
Create students and set their grades.
:param context: class reference
"""
if context.course:
context.student = student = UserFactory.create()
CourseEnrollmentFactory.create(user=student, course_id=context.course.id)
context.student2 = student2 = UserFactory.create()
CourseEnrollmentFactory.create(user=student2, course_id=context.course.id)
# create grades for self.student as if they'd submitted the ccx
for chapter in context.course.get_children():
for i, section in enumerate(chapter.get_children()):
for j, problem in enumerate(section.get_children()):
# if not problem.visible_to_staff_only:
StudentModuleFactory.create(
grade=1 if i < j else 0,
max_grade=1,
student=context.student,
course_id=context.course.id,
module_state_key=problem.location
)
StudentModuleFactory.create(
grade=1 if i > j else 0,
max_grade=1,
student=context.student2,
course_id=context.course.id,
module_state_key=problem.location
)
开发者ID:Akif-Vohra,项目名称:edx-platform,代码行数:32,代码来源:test_views.py
示例5: test_resolve_course_enrollments
def test_resolve_course_enrollments(self):
"""
Test that the CourseEnrollmentsScopeResolver actually returns all enrollments
"""
test_user_1 = UserFactory.create(password='test_pass')
CourseEnrollmentFactory(user=test_user_1, course_id=self.course.id)
test_user_2 = UserFactory.create(password='test_pass')
CourseEnrollmentFactory(user=test_user_2, course_id=self.course.id)
test_user_3 = UserFactory.create(password='test_pass')
enrollment = CourseEnrollmentFactory(user=test_user_3, course_id=self.course.id)
# unenroll #3
enrollment.is_active = False
enrollment.save()
resolver = CourseEnrollmentsScopeResolver()
user_ids = resolver.resolve('course_enrollments', {'course_id': self.course.id}, None)
# should have first two, but the third should not be present
self.assertTrue(test_user_1.id in user_ids)
self.assertTrue(test_user_2.id in user_ids)
self.assertFalse(test_user_3.id in user_ids)
开发者ID:edx-solutions,项目名称:edx-platform,代码行数:27,代码来源:test_scope_resolver.py
示例6: test_duplicate_email
def test_duplicate_email(self):
"""
Assert the expected error message from the email validation method for an email address
that is already in use by another account.
"""
UserFactory.create(email=self.new_email)
self.assertEqual(self.do_email_validation(self.new_email), 'An account with this e-mail already exists.')
开发者ID:TeachAtTUM,项目名称:edx-platform,代码行数:7,代码来源:test_email.py
示例7: setUp
def setUp(self):
""" Create a course and user, then log in. """
super(EnrollmentTest, self).setUp()
self.course = CourseFactory.create()
self.user = UserFactory.create(username=self.USERNAME, email=self.EMAIL, password=self.PASSWORD)
self.other_user = UserFactory.create()
self.client.login(username=self.USERNAME, password=self.PASSWORD)
开发者ID:mrgnr,项目名称:edx-platform,代码行数:7,代码来源:test_views.py
示例8: setUp
def setUp(self):
super(BookmarksTestsBase, self).setUp()
self.admin = AdminFactory()
self.user = UserFactory.create(password=self.TEST_PASSWORD)
self.other_user = UserFactory.create(password=self.TEST_PASSWORD)
self.setup_data(self.STORE_TYPE)
开发者ID:chaitanyakale,项目名称:edx-platform,代码行数:7,代码来源:test_models.py
示例9: setUp
def setUp(self):
# create users
self.bad_user = UserFactory.create(username="bad_user")
self.good_user = UserFactory.create(username="good_user")
self.non_staff = UserFactory.create(username="non_staff")
self.admin = UserFactory.create(username="admin", is_staff=True)
# create clients
self.bad_user_client = Client()
self.good_user_client = Client()
self.non_staff_client = Client()
self.admin_client = Client()
for user, client in [
(self.bad_user, self.bad_user_client),
(self.good_user, self.good_user_client),
(self.non_staff, self.non_staff_client),
(self.admin, self.admin_client),
]:
client.login(username=user.username, password="test")
UserStandingFactory.create(
user=self.bad_user, account_status=UserStanding.ACCOUNT_DISABLED, changed_by=self.admin
)
# set different stock urls for lms and cms
# to test disabled accounts' access to site
try:
self.some_url = reverse("dashboard")
except NoReverseMatch:
self.some_url = "/course"
开发者ID:nttks-famao,项目名称:edx-platform,代码行数:31,代码来源:test_userstanding.py
示例10: create_mock_user
def create_mock_user(self, is_staff=True, is_enrolled=True):
"""
Creates a mock user with the specified properties.
"""
user = UserFactory(is_staff=is_staff)
user.is_enrolled = is_enrolled
return user
开发者ID:mreyk,项目名称:edx-platform,代码行数:7,代码来源:test_tabs.py
示例11: setUp
def setUp(self):
super(CertificatesRestApiTest, self).setUp()
self.student = UserFactory.create(password=USER_PASSWORD)
self.student_no_cert = UserFactory.create(password=USER_PASSWORD)
self.staff_user = UserFactory.create(password=USER_PASSWORD, is_staff=True)
GeneratedCertificateFactory.create(
user=self.student,
course_id=self.course.id,
status=CertificateStatuses.downloadable,
mode='verified',
download_url='www.google.com',
grade="0.88"
)
self.namespaced_url = 'certificates_api:v0:certificates:detail'
# create a configuration for django-oauth-toolkit (DOT)
dot_app_user = UserFactory.create(password=USER_PASSWORD)
dot_app = dot_models.Application.objects.create(
name='test app',
user=dot_app_user,
client_type='confidential',
authorization_grant_type='authorization-code',
redirect_uris='http://localhost:8079/complete/edxorg/'
)
self.dot_access_token = dot_models.AccessToken.objects.create(
user=self.student,
application=dot_app,
expires=datetime.utcnow() + timedelta(weeks=1),
scope='read write',
token='16MGyP3OaQYHmpT1lK7Q6MMNAZsjwF'
)
开发者ID:AndreySonetico,项目名称:edx-platform,代码行数:34,代码来源:test_views.py
示例12: test_course_bulk_notification_tests
def test_course_bulk_notification_tests(self):
# create new users and enroll them in the course.
startup.startup_notification_subsystem()
test_user_1 = UserFactory.create(password='test_pass')
CourseEnrollmentFactory(user=test_user_1, course_id=self.course.id)
test_user_2 = UserFactory.create(password='test_pass')
CourseEnrollmentFactory(user=test_user_2, course_id=self.course.id)
notification_type = get_notification_type(u'open-edx.studio.announcements.new-announcement')
course = modulestore().get_course(self.course.id, depth=0)
notification_msg = NotificationMessage(
msg_type=notification_type,
namespace=unicode(self.course.id),
payload={
'_schema_version': '1',
'course_name': course.display_name,
}
)
# Send the notification_msg to the Celery task
publish_course_notifications_task.delay(self.course.id, notification_msg)
# now the enrolled users should get notification about the
# course update where they are enrolled as student.
self.assertTrue(get_notifications_count_for_user(test_user_1.id), 1)
self.assertTrue(get_notifications_count_for_user(test_user_2.id), 1)
开发者ID:kotky,项目名称:edx-platform,代码行数:27,代码来源:test_tasks.py
示例13: setUpTestData
def setUpTestData(cls):
UserFactory.create(
username='enterprise_worker',
email='[email protected]',
password='password123',
)
super(TestEnterpriseApi, cls).setUpTestData()
开发者ID:Lektorium-LLC,项目名称:edx-platform,代码行数:7,代码来源:test_api.py
示例14: setUp
def setUp(self):
"""Set up data for the test case"""
super(SubmitFeedbackTest, self).setUp()
self._request_factory = RequestFactory()
self._anon_user = AnonymousUser()
self._auth_user = UserFactory.create(
email="[email protected]",
username="test",
profile__name="Test User"
)
self._anon_fields = {
"email": "[email protected]",
"name": "Test User",
"subject": "a subject",
"details": "some details",
"issue_type": "test_issue"
}
# This does not contain issue_type nor course_id to ensure that they are optional
self._auth_fields = {"subject": "a subject", "details": "some details"}
# Create a service user, because the track selection page depends on it
UserFactory.create(
username='enterprise_worker',
email="[email protected]",
password="edx",
)
开发者ID:Lektorium-LLC,项目名称:edx-platform,代码行数:26,代码来源:test_submit_feedback.py
示例15: setUp
def setUp(self):
super(RefundTests, self).setUp()
self.course = CourseFactory.create(
org='testorg', number='run1', display_name='refundable course'
)
self.course_id = self.course.location.course_key
self.client = Client()
self.admin = UserFactory.create(
username='test_admin',
email='[email protected]',
password='foo'
)
SupportStaffRole().add_users(self.admin)
self.client.login(username=self.admin.username, password='foo')
self.student = UserFactory.create(
username='student',
email='[email protected]'
)
self.course_mode = CourseMode.objects.get_or_create(
course_id=self.course_id,
mode_slug='verified',
min_price=1
)[0]
self.order = None
self.form_pars = {'course_id': str(self.course_id), 'user': self.student.email}
开发者ID:edx,项目名称:edx-platform,代码行数:28,代码来源:test_refund.py
示例16: test_enrollment_email_on
def test_enrollment_email_on(self):
"""
Do email on enroll test
"""
course = self.course
#Create activated, but not enrolled, user
UserFactory.create(username="student3_0", email="[email protected]")
url = reverse('instructor_dashboard', kwargs={'course_id': course.id})
response = self.client.post(url, {'action': 'Enroll multiple students', 'multiple_students': '[email protected], [email protected], [email protected]', 'auto_enroll': 'on', 'email_students': 'on'})
#Check the page output
self.assertContains(response, '<td>[email protected]</td>')
self.assertContains(response, '<td>[email protected]</td>')
self.assertContains(response, '<td>[email protected]</td>')
self.assertContains(response, '<td>added, email sent</td>')
self.assertContains(response, '<td>user does not exist, enrollment allowed, pending with auto enrollment on, email sent</td>')
#Check the outbox
self.assertEqual(len(mail.outbox), 3)
self.assertEqual(mail.outbox[0].subject, 'You have been enrolled in MITx/999/Robot_Super_Course')
self.assertEqual(mail.outbox[1].subject, 'You have been invited to register for MITx/999/Robot_Super_Course')
self.assertEqual(mail.outbox[1].body, "Dear student,\n\nYou have been invited to join MITx/999/Robot_Super_Course at edx.org by a member of the course staff.\n\n" +
"To finish your registration, please visit https://edx.org/register and fill out the registration form.\n" +
"Once you have registered and activated your account, you will see MITx/999/Robot_Super_Course listed on your dashboard.\n\n" +
"----\nThis email was automatically sent from edx.org to [email protected]")
开发者ID:Fyre91,项目名称:edx-platform,代码行数:29,代码来源:test_enrollment.py
示例17: setUp
def setUp(self):
"""
Fixtures.
"""
super(TestDataDumps, self).setUp()
due = datetime.datetime(2010, 5, 12, 2, 42, tzinfo=UTC)
course = CourseFactory.create()
week1 = ItemFactory.create(due=due, parent=course)
week2 = ItemFactory.create(due=due, parent=course)
homework = ItemFactory.create(
parent=week1,
due=due
)
user1 = UserFactory.create()
user2 = UserFactory.create()
self.course = course
self.week1 = week1
self.homework = homework
self.week2 = week2
self.user1 = user1
self.user2 = user2
signals.extract_dates(None, course.id)
开发者ID:edx,项目名称:edx-platform,代码行数:25,代码来源:test_tools.py
示例18: setUp
def setUp(self):
super(UserStandingTest, self).setUp()
# create users
self.bad_user = UserFactory.create(username="bad_user")
self.good_user = UserFactory.create(username="good_user")
self.non_staff = UserFactory.create(username="non_staff")
self.admin = UserFactory.create(username="admin", is_staff=True)
# create clients
self.bad_user_client = Client()
self.good_user_client = Client()
self.non_staff_client = Client()
self.admin_client = Client()
for user, client in [
(self.bad_user, self.bad_user_client),
(self.good_user, self.good_user_client),
(self.non_staff, self.non_staff_client),
(self.admin, self.admin_client),
]:
client.login(username=user.username, password="test")
UserStandingFactory.create(
user=self.bad_user, account_status=UserStanding.ACCOUNT_DISABLED, changed_by=self.admin
)
# set stock url to test disabled accounts' access to site
self.some_url = "/"
开发者ID:ahmadiga,项目名称:min_edx,代码行数:28,代码来源:test_userstanding.py
示例19: setUp
def setUp(self):
super(TeamAPITestCase, self).setUp()
self.topics_count = 4
self.users = {
"student_unenrolled": UserFactory.create(password=self.test_password),
"student_enrolled": UserFactory.create(password=self.test_password),
"student_enrolled_not_on_team": UserFactory.create(password=self.test_password),
# This student is enrolled in both test courses and is a member of a team in each course, but is not on the
# same team as student_enrolled.
"student_enrolled_both_courses_other_team": UserFactory.create(password=self.test_password),
"staff": AdminFactory.create(password=self.test_password),
"course_staff": StaffFactory.create(course_key=self.test_course_1.id, password=self.test_password),
}
# 'solar team' is intentionally lower case to test case insensitivity in name ordering
self.test_team_1 = CourseTeamFactory.create(
name=u"sólar team", course_id=self.test_course_1.id, topic_id="topic_0"
)
self.test_team_2 = CourseTeamFactory.create(name="Wind Team", course_id=self.test_course_1.id)
self.test_team_3 = CourseTeamFactory.create(name="Nuclear Team", course_id=self.test_course_1.id)
self.test_team_4 = CourseTeamFactory.create(name="Coal Team", course_id=self.test_course_1.id, is_active=False)
self.test_team_5 = CourseTeamFactory.create(name="Another Team", course_id=self.test_course_2.id)
for user, course in [
("student_enrolled", self.test_course_1),
("student_enrolled_not_on_team", self.test_course_1),
("student_enrolled_both_courses_other_team", self.test_course_1),
("student_enrolled_both_courses_other_team", self.test_course_2),
]:
CourseEnrollment.enroll(self.users[user], course.id, check_access=True)
self.test_team_1.add_user(self.users["student_enrolled"])
self.test_team_3.add_user(self.users["student_enrolled_both_courses_other_team"])
self.test_team_5.add_user(self.users["student_enrolled_both_courses_other_team"])
开发者ID:rimolive,项目名称:edx-platform,代码行数:33,代码来源:test_views.py
示例20: setUp
def setUp(self):
super(TestBlockListGetForm, self).setUp()
self.student = UserFactory.create()
self.student2 = UserFactory.create()
self.staff = UserFactory.create(is_staff=True)
CourseEnrollmentFactory.create(user=self.student, course_id=self.course.id)
CourseEnrollmentFactory.create(user=self.student2, course_id=self.course.id)
usage_key = self.course.location
self.initial = {'requesting_user': self.student}
self.form_data = QueryDict(
urlencode({
'username': self.student.username,
'usage_key': unicode(usage_key),
}),
mutable=True,
)
self.cleaned_data = {
'all_blocks': None,
'block_counts': set(),
'depth': 0,
'nav_depth': None,
'return_type': 'dict',
'requested_fields': {'display_name', 'type'},
'student_view_data': set(),
'usage_key': usage_key,
'username': self.student.username,
'user': self.student,
}
开发者ID:28554010,项目名称:edx-platform,代码行数:31,代码来源:test_forms.py
注:本文中的student.tests.factories.UserFactory类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论