本文整理汇总了Python中oneanddone.tasks.tests.TaskAttemptFactory类的典型用法代码示例。如果您正苦于以下问题:Python TaskAttemptFactory类的具体用法?Python TaskAttemptFactory怎么用?Python TaskAttemptFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TaskAttemptFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_users_with_valid_completed_attempt_counts
def test_users_with_valid_completed_attempt_counts(self):
"""
users_with_valid_completed_attempt_counts should return counts of all attempts completed
within the time threshold, sorted by highest number of attempts
"""
task = TaskFactory.create()
user1 = UserFactory.create()
user2 = UserFactory.create()
# Invalid attempt
TaskAttemptFactory.create(user=user1,
state=TaskAttempt.FINISHED,
task=task)
# Valid attempts
ValidTaskAttemptFactory.create_batch(2,
user=user1,
state=TaskAttempt.FINISHED,
task=task)
ValidTaskAttemptFactory.create(user=user2,
state=TaskAttempt.FINISHED,
task=task)
ValidTaskAttemptFactory.create(user=user1,
state=TaskAttempt.STARTED,
task=task)
eq_(user1.taskattempt_set.filter(state=TaskAttempt.STARTED).count(), 1)
eq_(user1.taskattempt_set.filter(state=TaskAttempt.FINISHED).count(), 3)
eq_(user2.taskattempt_set.filter(state=TaskAttempt.FINISHED).count(), 1)
qs = User.users_with_valid_completed_attempt_counts()
eq_(len(qs), 2)
eq_(qs[0], user1)
eq_(qs[0].valid_completed_attempts_count, 2)
eq_(qs[1], user2)
eq_(qs[1].valid_completed_attempts_count, 1)
示例2: test_has_completed_task_true
def test_has_completed_task_true(self):
"""
has_completed_task should return true if the user has completed the task.
"""
user = UserFactory.create()
task = TaskFactory.create()
TaskAttemptFactory.create(user=user, task=task, state=TaskAttempt.FINISHED)
ok_(user.has_completed_task(task))
示例3: test_has_completed_task_false_task_started
def test_has_completed_task_false_task_started(self):
"""
has_completed_task should return false if the user has just started the task.
"""
user = UserFactory.create()
task = TaskFactory.create()
TaskAttemptFactory.create(user=user, task=task, state=TaskAttempt.STARTED)
ok_(not user.has_completed_task(task))
示例4: test_is_available_to_user_user_attempt
def test_is_available_to_user_user_attempt(self):
"""
If there is an attempt by the current user,
the task should be available.
"""
user = UserFactory.create()
task = TaskFactory.create(repeatable=False)
TaskAttemptFactory.create(user=user, state=TaskAttempt.STARTED, task=task)
eq_(task.is_available_to_user(user), True)
示例5: test_attempts_finished_count
def test_attempts_finished_count(self):
"""
attempts_finished_count should return the number of attempts
the user has finished.
"""
user = UserFactory.create()
TaskAttemptFactory.create_batch(4, user=user, state=TaskAttempt.FINISHED)
TaskAttemptFactory.create(user=user, state=TaskAttempt.STARTED)
eq_(user.attempts_finished_count, 4)
示例6: test_isnt_available_to_user_other_user_non_abandoned_attempt
def test_isnt_available_to_user_other_user_non_abandoned_attempt(self):
"""
If there is a non-abandoned attempt by a different user,
the task should not be available.
"""
user = UserFactory.create()
other_user = UserFactory.create()
task = TaskFactory.create(repeatable=False)
TaskAttemptFactory.create(user=other_user, state=TaskAttempt.STARTED, task=task)
eq_(task.is_available_to_user(user), False)
示例7: assigned_task
def assigned_task(base_url, is_local):
if is_local:
from oneanddone.tasks.tests import TaskFactory, TaskAttemptFactory
from oneanddone.users.tests import UserFactory
from oneanddone.tasks.models import TaskAttempt
task = TaskFactory.create(repeatable=False)
user = UserFactory.create()
TaskAttemptFactory.create(
user=user,
state=TaskAttempt.STARTED,
task=task)
return task
示例8: test_get_task_details
def test_get_task_details(self):
"""
Test GET details of a task with particular id for authenticated user
"""
self.client.credentials(HTTP_AUTHORIZATION='Token ' + self.token.key)
user = UserFactory.create()
test_task = self.create_task(user)
task_attempt = TaskAttemptFactory.create(user=user, task=test_task)
task_uri = self.uri + str(test_task.id) + '/'
task_data = {"id": test_task.id, "name": test_task.name, "short_description": test_task.short_description,
"instructions": test_task.instructions, "prerequisites": test_task.prerequisites,
"execution_time": test_task.execution_time, "is_draft": test_task.is_draft,
"is_invalid": test_task.is_invalid, "project": test_task.project.name,
"team": test_task.team.name, "type": test_task.type.name, "repeatable": test_task.repeatable,
"start_date": test_task.start_date, "end_date": test_task.end_date, "difficulty": test_task.difficulty,
"why_this_matters": test_task.why_this_matters,
"keyword_set": [{"name": keyword.name} for keyword in test_task.keyword_set.all()],
"taskattempt_set": [{"user": user.email, "state": task_attempt.state}],
"owner": user.email}
response = self.client.get(task_uri)
self.assert_response_status(response, status.HTTP_200_OK)
response_data = json.loads(response.content)
eq_(response_data, task_data)
示例9: test_get_task_list
def test_get_task_list(self):
"""
Test GET task list for authenticated user
"""
header = {'HTTP_AUTHORIZATION': 'Token {}'.format(self.token)}
user = UserFactory.create()
test_task = self.create_task(user)
task_attempt = TaskAttemptFactory.create(user=user, task=test_task)
task_data = {"id": test_task.id,
"name": test_task.name,
"short_description": test_task.short_description,
"instructions": test_task.instructions,
"prerequisites": test_task.prerequisites,
"execution_time": test_task.execution_time,
"is_draft": test_task.is_draft,
"is_invalid": test_task.is_invalid,
"project": test_task.project.name,
"team": test_task.team.name,
"type": test_task.type.name,
"repeatable": test_task.repeatable,
"start_date": test_task.start_date,
"end_date": test_task.end_date,
"difficulty": test_task.difficulty,
"why_this_matters": test_task.why_this_matters,
"keyword_set": [
{"name": keyword.name} for keyword in test_task.keyword_set.all()],
"taskattempt_set": [{"user": user.email, "state": task_attempt.state}],
"owner": user.email}
response = self.client.get(reverse('api-task'), {}, **header)
self.assert_response_status(response, status.HTTP_200_OK)
response_data = json.loads(response.content)
assert_true(task_data in response_data)
示例10: test_attempts_in_progress
def test_attempts_in_progress(self):
"""
attempts_in_progress should return the number of attempts in progress.
"""
user = UserFactory.create()
tasks = TaskAttemptFactory.create_batch(4, user=user, state=TaskAttempt.STARTED)
eq_(set(user.attempts_in_progress), set(tasks))
示例11: test_close_stale_onetime_attempts
def test_close_stale_onetime_attempts(self):
"""
The close_stale_onetime_attempts routine should close all
expired one-time attempts, set them as requiring notification,
and return the number that were closed.
"""
task = TaskFactory.create(repeatable=False)
user = UserFactory.create()
recent_attempt, expired_attempt_1, expired_attempt_2 = TaskAttemptFactory.create_batch(
3,
user=user,
state=TaskAttempt.STARTED,
task=task)
recent_attempt.created = aware_datetime(2014, 1, 29)
recent_attempt.save()
expired_attempt_1.created = aware_datetime(2014, 1, 1)
expired_attempt_1.save()
expired_attempt_2.created = aware_datetime(2014, 1, 1)
expired_attempt_2.save()
eq_(task.taskattempt_set.filter(state=TaskAttempt.STARTED).count(), 3)
with patch('oneanddone.tasks.models.timezone.now') as now:
now.return_value = aware_datetime(2014, 1, 31)
eq_(TaskAttempt.close_stale_onetime_attempts(), 2)
eq_(TaskAttempt.objects.filter(task=task,
state=TaskAttempt.STARTED).count(), 1)
eq_(TaskAttempt.objects.filter(task=task,
state=TaskAttempt.CLOSED,
requires_notification=True).count(), 2)
示例12: test_not_your_attempt_raises_404
def test_not_your_attempt_raises_404(self):
"""
If the current user doesn't match the user for the requested
task attempt, return a 404.
"""
attempt = TaskAttemptFactory.create()
request = Mock(user=UserFactory.create())
with self.assertRaises(Http404):
self.view.dispatch(request, pk=attempt.pk)
示例13: test_found_attempt_stores_attempt
def test_found_attempt_stores_attempt(self):
"""
If the current user has a matching attempt, it should
be stored in the view.
"""
user = UserFactory.create()
attempt = TaskAttemptFactory.create(user=user, state=TaskAttempt.FINISHED)
request = Mock(user=user)
self.view.dispatch(request, pk=attempt.pk)
eq_(self.view.attempt, attempt)
示例14: test_attempt_with_feedback_raises_404
def test_attempt_with_feedback_raises_404(self):
"""
If the current user has an attempt but feedback has already been
provided, return a 404.
"""
user = UserFactory.create()
attempt = TaskAttemptFactory.create(user=user, state=TaskAttempt.FINISHED)
FeedbackFactory.create(attempt=attempt)
request = Mock(user=UserFactory.create())
with self.assertRaises(Http404):
self.view.dispatch(request, pk=attempt.pk)
示例15: test_post_existing_attempts
def test_post_existing_attempts(self):
"""
If the user has an existing task attempt, redirect them to the
profile detail page.
"""
attempt = TaskAttemptFactory.create()
self.view.request = Mock(user=attempt.user)
with patch('oneanddone.tasks.views.redirect') as redirect:
eq_(self.view.post(), redirect.return_value)
redirect.assert_called_with('base.home')
ok_(not TaskAttempt.objects.filter(user=attempt.user, task=self.task).exists())