本文整理汇总了Python中student.tests.factories.UserFactory.create方法的典型用法代码示例。如果您正苦于以下问题:Python UserFactory.create方法的具体用法?Python UserFactory.create怎么用?Python UserFactory.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类student.tests.factories.UserFactory
的用法示例。
在下文中一共展示了UserFactory.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_same_user_key_in_multiple_organizations
# 需要导入模块: from student.tests.factories import UserFactory [as 别名]
# 或者: from student.tests.factories.UserFactory import create [as 别名]
def test_same_user_key_in_multiple_organizations(self):
uox_program_enrollment = self._create_waiting_program_enrollment()
second_organization = OrganizationFactory.create()
SAMLProviderConfigFactory.create(organization=second_organization, slug='aiu')
catalog_org = CatalogOrganizationFactory.create(key=second_organization.short_name)
program_uuid = self._create_catalog_program(catalog_org)['uuid']
# aiu enrollment with the same student key as our uox user
aiu_program_enrollment = ProgramEnrollmentFactory.create(
user=None,
external_user_key=self.external_id,
program_uuid=program_uuid
)
UserSocialAuth.objects.create(
user=UserFactory.create(),
uid='{0}:{1}'.format('not_used', self.external_id),
)
UserSocialAuth.objects.create(
user=self.user,
uid='{0}:{1}'.format(self.provider_slug, self.external_id),
)
self._assert_program_enrollment_user(uox_program_enrollment, self.user)
aiu_user = UserFactory.create()
UserSocialAuth.objects.create(
user=aiu_user,
uid='{0}:{1}'.format('aiu', self.external_id),
)
self._assert_program_enrollment_user(aiu_program_enrollment, aiu_user)
示例2: setUp
# 需要导入模块: from student.tests.factories import UserFactory [as 别名]
# 或者: from student.tests.factories.UserFactory import create [as 别名]
def setUp(self):
super(CohortedContentTestCase, self).setUp()
self.course = CourseFactory.create(
discussion_topics={
"cohorted topic": {"id": "cohorted_topic"},
"non-cohorted topic": {"id": "non_cohorted_topic"},
},
cohort_config={
"cohorted": True,
"cohorted_discussions": ["cohorted_topic"]
}
)
self.student_cohort = CourseUserGroup.objects.create(
name="student_cohort",
course_id=self.course.id,
group_type=CourseUserGroup.COHORT
)
self.moderator_cohort = CourseUserGroup.objects.create(
name="moderator_cohort",
course_id=self.course.id,
group_type=CourseUserGroup.COHORT
)
seed_permissions_roles(self.course.id)
self.student = UserFactory.create()
self.moderator = UserFactory.create()
CourseEnrollmentFactory(user=self.student, course_id=self.course.id)
CourseEnrollmentFactory(user=self.moderator, course_id=self.course.id)
self.moderator.roles.add(Role.objects.get(name="Moderator", course_id=self.course.id))
self.student_cohort.users.add(self.student)
self.moderator_cohort.users.add(self.moderator)
示例3: setUp
# 需要导入模块: from student.tests.factories import UserFactory [as 别名]
# 或者: from student.tests.factories.UserFactory import create [as 别名]
def setUp(self):
self.course = CourseFactory.create()
seed_permissions_roles(self.course.id)
self.student = UserFactory.create()
self.enrollment = CourseEnrollmentFactory(user=self.student, course_id=self.course.id)
self.other_user = UserFactory.create(username="other")
CourseEnrollmentFactory(user=self.other_user, course_id=self.course.id)
示例4: setUp
# 需要导入模块: from student.tests.factories import UserFactory [as 别名]
# 或者: from student.tests.factories.UserFactory import create [as 别名]
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,
}
示例5: setUp
# 需要导入模块: from student.tests.factories import UserFactory [as 别名]
# 或者: from student.tests.factories.UserFactory import create [as 别名]
def setUp(self):
"""Create a user with a team to test signals."""
super(TeamSignalsTest, self).setUp("teams.utils.tracker")
self.user = UserFactory.create(username="user")
self.moderator = UserFactory.create(username="moderator")
self.team = CourseTeamFactory(discussion_topic_id=self.DISCUSSION_TOPIC_ID)
self.team_membership = CourseTeamMembershipFactory(user=self.user, team=self.team)
示例6: test_enrollment_email_on
# 需要导入模块: from student.tests.factories import UserFactory [as 别名]
# 或者: from student.tests.factories.UserFactory import create [as 别名]
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]")
示例7: setUp
# 需要导入模块: from student.tests.factories import UserFactory [as 别名]
# 或者: from student.tests.factories.UserFactory import create [as 别名]
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 = "/"
示例8: setUp
# 需要导入模块: from student.tests.factories import UserFactory [as 别名]
# 或者: from student.tests.factories.UserFactory import create [as 别名]
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'
)
示例9: setUp
# 需要导入模块: from student.tests.factories import UserFactory [as 别名]
# 或者: from student.tests.factories.UserFactory import create [as 别名]
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)
示例10: setUpTestData
# 需要导入模块: from student.tests.factories import UserFactory [as 别名]
# 或者: from student.tests.factories.UserFactory import create [as 别名]
def setUpTestData(cls):
UserFactory.create(
username='enterprise_worker',
email='[email protected]',
password='password123',
)
super(TestEnterpriseApi, cls).setUpTestData()
示例11: test_course_bulk_notification_tests
# 需要导入模块: from student.tests.factories import UserFactory [as 别名]
# 或者: from student.tests.factories.UserFactory import create [as 别名]
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)
示例12: setUp
# 需要导入模块: from student.tests.factories import UserFactory [as 别名]
# 或者: from student.tests.factories.UserFactory import create [as 别名]
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",
)
示例13: test_user_details_force_sync_username_conflict
# 需要导入模块: from student.tests.factories import UserFactory [as 别名]
# 或者: from student.tests.factories.UserFactory import create [as 别名]
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
示例14: setUp
# 需要导入模块: from student.tests.factories import UserFactory [as 别名]
# 或者: from student.tests.factories.UserFactory import create [as 别名]
def setUp(self):
"""
Fixtures.
"""
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)
week3 = ItemFactory.create(due=due, parent=course)
homework = ItemFactory.create(parent=week1, due=due)
user1 = UserFactory.create()
StudentModule(state="{}", student_id=user1.id, course_id=course.id, module_state_key=week1.location).save()
StudentModule(state="{}", student_id=user1.id, course_id=course.id, module_state_key=week2.location).save()
StudentModule(state="{}", student_id=user1.id, course_id=course.id, module_state_key=week3.location).save()
StudentModule(state="{}", student_id=user1.id, course_id=course.id, module_state_key=homework.location).save()
user2 = UserFactory.create()
StudentModule(state="{}", student_id=user2.id, course_id=course.id, module_state_key=week1.location).save()
StudentModule(state="{}", student_id=user2.id, course_id=course.id, module_state_key=homework.location).save()
user3 = UserFactory.create()
StudentModule(state="{}", student_id=user3.id, course_id=course.id, module_state_key=week1.location).save()
StudentModule(state="{}", student_id=user3.id, course_id=course.id, module_state_key=homework.location).save()
self.course = course
self.week1 = week1
self.homework = homework
self.week2 = week2
self.user1 = user1
self.user2 = user2
示例15: setUp
# 需要导入模块: from student.tests.factories import UserFactory [as 别名]
# 或者: from student.tests.factories.UserFactory import create [as 别名]
def setUp(self):
super(ExternalAuthShibTest, self).setUp()
self.course = CourseFactory.create(
org='Stanford',
number='456',
display_name='NO SHIB',
user_id=self.user.id,
)
self.shib_course = CourseFactory.create(
org='Stanford',
number='123',
display_name='Shib Only',
enrollment_domain='shib:https://idp.stanford.edu/',
user_id=self.user.id,
)
self.user_w_map = UserFactory.create(email='[email protected]')
self.extauth = ExternalAuthMap(external_id='[email protected]',
external_email='[email protected]',
external_domain='shib:https://idp.stanford.edu/',
external_credentials="",
user=self.user_w_map)
self.user_w_map.save()
self.extauth.save()
self.user_wo_map = UserFactory.create(email='[email protected]')
self.user_wo_map.save()