本文整理汇总了Python中instructor_task.tests.factories.InstructorTaskFactory类的典型用法代码示例。如果您正苦于以下问题:Python InstructorTaskFactory类的具体用法?Python InstructorTaskFactory怎么用?Python InstructorTaskFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了InstructorTaskFactory类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _queue_subtasks
def _queue_subtasks(self, create_subtask_fcn, items_per_task, initial_count, extra_count):
"""Queue subtasks while enrolling more students into course in the middle of the process."""
task_id = str(uuid4())
instructor_task = InstructorTaskFactory.create(
course_id=self.course.id,
task_id=task_id,
task_key='dummy_task_key',
task_type='bulk_course_email',
)
self._enroll_students_in_course(self.course.id, initial_count)
task_querysets = [CourseEnrollment.objects.filter(course_id=self.course.id)]
def initialize_subtask_info(*args): # pylint: disable=unused-argument
"""Instead of initializing subtask info enroll some more students into course."""
self._enroll_students_in_course(self.course.id, extra_count)
return {}
with patch('instructor_task.subtasks.initialize_subtask_info') as mock_initialize_subtask_info:
mock_initialize_subtask_info.side_effect = initialize_subtask_info
queue_subtasks_for_query(
entry=instructor_task,
action_name='action_name',
create_subtask_fcn=create_subtask_fcn,
item_querysets=task_querysets,
item_fields=[],
items_per_task=items_per_task,
total_num_items=initial_count,
)
示例2: _create_input_entry
def _create_input_entry(self, student_ident=None):
"""Creates a InstructorTask entry for testing."""
task_id = str(uuid4())
task_input = {'problem_url': self.problem_url}
if student_ident is not None:
task_input['student'] = student_ident
instructor_task = InstructorTaskFactory.create(course_id=self.course.id,
requester=self.instructor,
task_input=json.dumps(task_input),
task_key='dummy value',
task_id=task_id)
return instructor_task
示例3: _create_entry
def _create_entry(self, task_state=QUEUING, task_output=None, student=None):
"""Creates a InstructorTask entry for testing."""
task_id = str(uuid4())
progress_json = json.dumps(task_output) if task_output is not None else None
task_input, task_key = encode_problem_and_student_input(self.problem_url, student)
instructor_task = InstructorTaskFactory.create(course_id=TEST_COURSE_KEY,
requester=self.instructor,
task_input=json.dumps(task_input),
task_key=task_key,
task_id=task_id,
task_state=task_state,
task_output=progress_json)
return instructor_task
示例4: _create_input_entry
def _create_input_entry(self, student_ident=None, use_problem_url=True, course_id=None):
"""Creates a InstructorTask entry for testing."""
task_id = str(uuid4())
task_input = {}
if use_problem_url:
task_input['problem_url'] = self.location
if student_ident is not None:
task_input['student'] = student_ident
course_id = course_id or self.course.id
instructor_task = InstructorTaskFactory.create(course_id=course_id,
requester=self.instructor,
task_input=json.dumps(task_input, cls=i4xEncoder),
task_key='dummy value',
task_id=task_id)
return instructor_task
示例5: test_get_task_name
def test_get_task_name(self, is_regeneration, expected):
staff = AdminFactory.create()
instructor_task = InstructorTaskFactory.create(
task_input=json.dumps({}),
requester=staff,
task_key=Mock(),
task_id=Mock(),
)
certificate_generation_history = CertificateGenerationHistory(
course_id=instructor_task.course_id,
generated_by=staff,
instructor_task=instructor_task,
is_regeneration=is_regeneration,
)
self.assertEqual(
certificate_generation_history.get_task_name(),
expected
)
示例6: _create_input_entry
def _create_input_entry(self, course_id=None):
"""
Creates a InstructorTask entry for testing.
Overrides the base class version in that this creates CourseEmail.
"""
to_option = SEND_TO_ALL
course_id = course_id or self.course.id
course_email = CourseEmail.create(course_id, self.instructor, to_option, "Test Subject", "<p>This is a test message</p>")
task_input = {'email_id': course_email.id} # pylint: disable=E1101
task_id = str(uuid4())
instructor_task = InstructorTaskFactory.create(
course_id=course_id,
requester=self.instructor,
task_input=json.dumps(task_input),
task_key='dummy value',
task_id=task_id,
)
return instructor_task
示例7: _create_input_entry
def _create_input_entry(self, course_id=None):
"""
Creates a InstructorTask entry for testing.
Overrides the base class version in that this creates CourseEmail.
"""
targets = [SEND_TO_MYSELF, SEND_TO_STAFF, SEND_TO_LEARNERS]
course_id = course_id or self.course.id
course_email = CourseEmail.create(
course_id, self.instructor, targets, "Test Subject", "<p>This is a test message</p>"
)
task_input = {'email_id': course_email.id}
task_id = str(uuid4())
instructor_task = InstructorTaskFactory.create(
course_id=course_id,
requester=self.instructor,
task_input=json.dumps(task_input),
task_key='dummy value',
task_id=task_id,
)
return instructor_task
示例8: test_task_queue
def test_task_queue(self):
"""Kill an InstructorTask"""
self._setstaff_login()
self.client.login(username=self.user.username, password='foo')
# Missing ID.
response = self.client.post(
reverse(
'sysadmin_task_queue'
),
{
'action': 'kill_task',
}
)
self.assertIn('Must provide an ID', response.content.decode('utf-8'))
# ID not an integer.
response = self.client.post(
reverse(
'sysadmin_task_queue'
),
{
'action': 'kill_task',
'row_id': 'abc',
}
)
self.assertIn('ID must be an integer', response.content.decode('utf-8'))
# InstructorTask with this ID doesn't exist.
response = self.client.post(
reverse(
'sysadmin_task_queue'
),
{
'action': 'kill_task',
'row_id': '123',
}
)
self.assertIn('Cannot find task with ID 123 and task_state QUEUING - InstructorTask matching query does not exist.', response.content.decode('utf-8'))
# Create InstructorTask with incorrect task_state.
instructor_task = InstructorTaskFactory.create(
task_key='dummy value',
task_id=str(uuid4()),
task_state='SUCCESS',
)
response = self.client.post(
reverse(
'sysadmin_task_queue'
),
{
'action': 'kill_task',
'row_id': instructor_task.id,
}
)
self.assertIn(
'Cannot find task with ID {instructor_task_id} and task_state QUEUING - InstructorTask matching query does not exist.'.format(
instructor_task_id=instructor_task.id,
),
response.content.decode(
'utf-8',
)
)
# Create InstructorTask with correct task_state
instructor_task = InstructorTaskFactory.create(
task_key='dummy value',
task_id=str(uuid4()),
task_state='QUEUING',
)
response = self.client.post(
reverse(
'sysadmin_task_queue'
),
{
'action': 'kill_task',
'row_id': instructor_task.id,
}
)
self.assertIn(
'Task with id {instructor_task_id} was successfully killed!'.format(
instructor_task_id=instructor_task.id,
),
response.content.decode(
'utf-8',
)
)