本文整理汇总了Python中student.tests.factories.UserFactory.create_batch方法的典型用法代码示例。如果您正苦于以下问题:Python UserFactory.create_batch方法的具体用法?Python UserFactory.create_batch怎么用?Python UserFactory.create_batch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类student.tests.factories.UserFactory
的用法示例。
在下文中一共展示了UserFactory.create_batch方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_page_size_parameter
# 需要导入模块: from student.tests.factories import UserFactory [as 别名]
# 或者: from student.tests.factories.UserFactory import create_batch [as 别名]
def test_page_size_parameter(self, page_size):
user_size = 60
with patch(
'lms.djangoapps.grades.course_grade_factory.CourseGradeFactory.read'
) as mock_grade:
users = UserFactory.create_batch(user_size)
mocked_course_grades = []
for user in users:
self._create_user_enrollments(user)
mocked_course_grades.append(self.mock_course_grade(user, passed=True, letter_grade='A', percent=0.85))
mock_grade.side_effect = mocked_course_grades
with override_waffle_flag(self.waffle_flag, active=True):
self.login_staff()
query = ''
if page_size:
query = '?page_size={}'.format(page_size)
resp = self.client.get(
self.get_url(course_key=self.course.id) + query
)
self.assertEqual(status.HTTP_200_OK, resp.status_code)
actual_data = dict(resp.data)
expected_page_size = page_size or CourseEnrollmentPagination.page_size
if expected_page_size > user_size:
expected_page_size = user_size
self.assertEqual(len(actual_data['results']), expected_page_size)
示例2: test_register_all_students
# 需要导入模块: from student.tests.factories import UserFactory [as 别名]
# 或者: from student.tests.factories.UserFactory import create_batch [as 别名]
def test_register_all_students(self):
users = UserFactory.create_batch(size=10)
for user in users:
self.assertFalse(self.is_enrolled(self.course.id, user))
call_command('register_all_students',
course=self.get_course_id(self.course))
for user in users:
self.assertTrue(self.is_enrolled(self.course.id, user))
示例3: setUp
# 需要导入模块: from student.tests.factories import UserFactory [as 别名]
# 或者: from student.tests.factories.UserFactory import create_batch [as 别名]
def setUp(self):
self.user = "testusername"
self.course_id = CourseLocator.from_string("org/num/run")
self.debug = False
self.noop = False
self.file_prefix = ""
self.exclude = None
self.mail = "[email protected]"
self.students = UserFactory.create_batch(3)
示例4: test_handle_assessment_file
# 需要导入模块: from student.tests.factories import UserFactory [as 别名]
# 或者: from student.tests.factories.UserFactory import create_batch [as 别名]
def test_handle_assessment_file(self):
users = UserFactory.create_batch(2)
file = self.create_csv([users[0], '5', u"Well done."],
[users[1], '1', u"Very bad."])
self.gea_xblock.usernames[users[0].username] = users[0]
self.gea_xblock.usernames[users[1].username] = users[1]
self.gea_xblock.handle_assessment_file(file)
results = self.edx_grade_students(users)
self.assertEqual(results.next()[1]['percent'], 0.5)
self.assertEqual(results.next()[1]['percent'], 0.1)
示例5: test_unregister_students
# 需要导入模块: from student.tests.factories import UserFactory [as 别名]
# 或者: from student.tests.factories.UserFactory import create_batch [as 别名]
def test_unregister_students(self):
users = UserFactory.create_batch(size=20)
self.enroll_students(self.course, *users)
for user in users:
self.assertTrue(CourseEnrollment.is_enrolled(user, self.course.id))
input_file = self.create_input_file(*[user.email for user in users])
self.unregister_student(input_file)
for user in users:
self.assertFalse(CourseEnrollment.is_enrolled(user, self.course.id))
示例6: setUp
# 需要导入模块: from student.tests.factories import UserFactory [as 别名]
# 或者: from student.tests.factories.UserFactory import create_batch [as 别名]
def setUp(self):
start_date = datetime.datetime(2000, 1, 1, tzinfo=UTC())
end_date = datetime.datetime(2010, 12, 31, tzinfo=UTC())
#self.course = CourseFactory.create(
# org='org', number='num', run='run', display_name='test_course',
# start=start_date, end=end_date)
for i in xrange(1, 10):
random = i * randint(1, 100)
try:
self.course = CourseFactory.create(
org='org_' + str(random), number='num', run="run", display_name='test_course',
start=start_date, end=end_date)
break
except DuplicateCourseError:
print "wow"
UserFactory.reset_sequence()
self.students = UserFactory.create_batch(3)
for student in self.students:
CourseEnrollmentFactory.create(
user=student, course_id=self.course.id)
self.course.save()
self.prog_name = "create_certs"
self.args_create = ["create", self.course.id.to_deprecated_string()]
self.args_delete = ["delete", self.course.id.to_deprecated_string()]
self.args_report = ["report", self.course.id.to_deprecated_string()]
self.args_publish = ["publish", self.course.id.to_deprecated_string()]
self.kwargs = {
"noop": False, "username": False,
"debug": False, "prefix": "", "exclude": None}
patcher0 = patch('pdfgen.views.logging')
self.log_mock = patcher0.start()
self.addCleanup(patcher0.stop)
patcher1 = patch('pdfgen.views.S3Connection')
self.s3conn_mock = patcher1.start()
self.addCleanup(patcher1.stop)
patcher2 = patch('pdfgen.views.Key')
self.s3key_mock = patcher2.start()
self.addCleanup(patcher2.stop)
self.s3key_mock().generate_url.return_value = "http://example.com"
self.pdf_path = settings.PDFGEN_BASE_PDF_DIR + "/" + self.kwargs['prefix'] + "-".join(
self.course.id.to_deprecated_string().split('/')) + ".pdf"
self.base_pdf = canvas.Canvas(self.pdf_path, pagesize=landscape(A4))
self.base_pdf.showPage()
self.base_pdf.save()
示例7: test_clear_expired_tokens
# 需要导入模块: from student.tests.factories import UserFactory [as 别名]
# 或者: from student.tests.factories.UserFactory import create_batch [as 别名]
def test_clear_expired_tokens(self):
settings.OAUTH2_PROVIDER['REFRESH_TOKEN_EXPIRE_SECONDS'] = 3600
initial_count = 5
now = timezone.now()
expires = now - timedelta(days=1)
users = UserFactory.create_batch(initial_count)
for user in users:
application = factories.ApplicationFactory(user=user)
factories.AccessTokenFactory(user=user, application=application, expires=expires)
self.assertEqual(
AccessToken.objects.filter(refresh_token__isnull=True, expires__lt=now).count(),
initial_count
)
QuerySet.delete = counter(QuerySet.delete)
call_command('edx_clear_expired_tokens', batch_size=1, sleep_time=0)
self.assertEqual(QuerySet.delete.invocations, initial_count)
self.assertEqual(AccessToken.objects.filter(refresh_token__isnull=True, expires__lt=now).count(), 0)
示例8: setUp
# 需要导入模块: from student.tests.factories import UserFactory [as 别名]
# 或者: from student.tests.factories.UserFactory import create_batch [as 别名]
def setUp(self):
super(BulkChangeEnrollmentTests, self).setUp()
self.org = 'testX'
self.course = CourseFactory.create(org=self.org)
self.users = UserFactory.create_batch(5)
CourseOverview.load_from_module_store(self.course.id)
示例9: setUp
# 需要导入模块: from student.tests.factories import UserFactory [as 别名]
# 或者: from student.tests.factories.UserFactory import create_batch [as 别名]
def setUp(self):
super(BulkChangeEnrollmentTests, self).setUp()
self.course = CourseFactory.create()
self.users = UserFactory.create_batch(5)