コード例 #1
0
 def test_attempts_finished_count(self):
     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)
コード例 #2
0
ファイル: test_models.py プロジェクト: Anmol2307/oneanddone
 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)
コード例 #3
0
 def test_save_closes_task_attempts(self):
     """
     When a saved task is unavailable,
     close any open attempts, and set the attempts
     to require a notification.
     """
     user1 = UserFactory.create()
     user2 = UserFactory.create()
     TaskAttemptFactory.create(user=user1,
                               state=TaskAttempt.STARTED,
                               task=self.task_no_draft)
     TaskAttemptFactory.create(user=user2,
                               state=TaskAttempt.STARTED,
                               task=self.task_no_draft)
     eq_(
         self.task_no_draft.taskattempt_set.filter(
             state=TaskAttempt.STARTED).count(), 2)
     self.task_no_draft.is_draft = True
     self.task_no_draft.save()
     eq_(
         TaskAttempt.objects.filter(task=self.task_no_draft,
                                    state=TaskAttempt.STARTED).count(), 0)
     eq_(
         TaskAttempt.objects.filter(task=self.task_no_draft,
                                    state=TaskAttempt.CLOSED,
                                    requires_notification=True).count(), 2)
コード例 #4
0
 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))
コード例 #5
0
 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))
コード例 #6
0
ファイル: test_models.py プロジェクト: adini121/oneanddone
 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)
コード例 #7
0
 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)
コード例 #8
0
ファイル: test_models.py プロジェクト: akatsoulas/oneanddone
 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)
コード例 #9
0
ファイル: test_models.py プロジェクト: adini121/oneanddone
 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)
コード例 #10
0
ファイル: test_models.py プロジェクト: akatsoulas/oneanddone
 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)
コード例 #11
0
ファイル: conftest.py プロジェクト: VarnaSuresh/oneanddone
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
コード例 #12
0
ファイル: test_api.py プロジェクト: Anmol2307/oneanddone
    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)
コード例 #13
0
    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)
コード例 #14
0
ファイル: test_api.py プロジェクト: skjindal93/oneanddone
    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)
コード例 #15
0
ファイル: test_mixins.py プロジェクト: Anmol2307/oneanddone
    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)
コード例 #16
0
    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)
コード例 #17
0
ファイル: test_mixins.py プロジェクト: Anmol2307/oneanddone
    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)
コード例 #18
0
ファイル: test_views.py プロジェクト: bitgeeky/oneanddone
    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())
コード例 #19
0
    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)
コード例 #20
0
ファイル: test_mixins.py プロジェクト: VarnaSuresh/oneanddone
    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)
コード例 #21
0
ファイル: test_models.py プロジェクト: adini121/oneanddone
 def test_close_expired_task_attempts(self):
     """
     The close_expired_task_attempts routine should close all
     attempts for tasks that are no longer available,
     set them as requiring notification,
     and return the number that were closed.
     """
     task_no_expire = TaskFactory.create()
     task = TaskFactory.create(end_date=timezone.now() + timedelta(days=1))
     future_date = timezone.now() + timedelta(days=2)
     user1, user2, user3 = UserFactory.create_batch(3)
     TaskAttemptFactory.create(
         user=user1,
         state=TaskAttempt.STARTED,
         task=task)
     TaskAttemptFactory.create(
         user=user2,
         state=TaskAttempt.STARTED,
         task=task)
     TaskAttemptFactory.create(
         user=user3,
         state=TaskAttempt.STARTED,
         task=task_no_expire)
     eq_(task.taskattempt_set.filter(state=TaskAttempt.STARTED).count(), 2)
     eq_(task_no_expire.taskattempt_set.filter(state=TaskAttempt.STARTED).count(), 1)
     with patch('oneanddone.tasks.models.timezone.now') as now:
         now.return_value = future_date
         eq_(TaskAttempt.close_expired_task_attempts(), 2)
     eq_(TaskAttempt.objects.filter(task=task,
                                    state=TaskAttempt.STARTED).count(), 0)
     eq_(TaskAttempt.objects.filter(task=task,
                                    state=TaskAttempt.CLOSED,
                                    requires_notification=True).count(), 2)
     eq_(TaskAttempt.objects.filter(task=task_no_expire,
                                    state=TaskAttempt.STARTED).count(), 1)
コード例 #22
0
 def setUp(self):
     user = UserFactory.create()
     self.task_not_repeatable_no_attempts = TaskFactory.create(
         repeatable=False)
     self.task_not_repeatable_abandoned_attempt = TaskFactory.create(
         repeatable=False)
     TaskAttemptFactory.create(
         user=user,
         state=TaskAttempt.ABANDONED,
         task=self.task_not_repeatable_abandoned_attempt)
     self.task_not_repeatable_started_attempt = TaskFactory.create(
         repeatable=False)
     TaskAttemptFactory.create(
         user=user,
         state=TaskAttempt.STARTED,
         task=self.task_not_repeatable_started_attempt)
     self.task_not_repeatable_finished_attempt = TaskFactory.create(
         repeatable=False)
     TaskAttemptFactory.create(
         user=user,
         state=TaskAttempt.FINISHED,
         task=self.task_not_repeatable_finished_attempt)
     self.task_draft = TaskFactory.create(is_draft=True)
     self.task_invalid = TaskFactory.create(is_invalid=True)
     self.task_no_draft = TaskFactory.create(is_draft=False)
     self.task_start_jan = TaskFactory.create(is_draft=False,
                                              start_date=aware_datetime(
                                                  2014, 1, 1))
     self.task_end_jan = TaskFactory.create(is_draft=False,
                                            end_date=aware_datetime(
                                                2014, 1, 1))
     self.task_range_jan_feb = TaskFactory.create(
         is_draft=False,
         start_date=aware_datetime(2014, 1, 1),
         end_date=aware_datetime(2014, 2, 1))
コード例 #23
0
ファイル: test_models.py プロジェクト: akatsoulas/oneanddone
 def setUp(self):
     user = UserFactory.create()
     self.task_not_repeatable_no_attempts = TaskFactory.create(repeatable=False)
     self.task_not_repeatable_abandoned_attempt = TaskFactory.create(repeatable=False)
     TaskAttemptFactory.create(
         user=user,
         state=TaskAttempt.ABANDONED,
         task=self.task_not_repeatable_abandoned_attempt)
     self.task_not_repeatable_started_attempt = TaskFactory.create(repeatable=False)
     TaskAttemptFactory.create(
         user=user,
         state=TaskAttempt.STARTED,
         task=self.task_not_repeatable_started_attempt)
     self.task_not_repeatable_finished_attempt = TaskFactory.create(repeatable=False)
     TaskAttemptFactory.create(
         user=user,
         state=TaskAttempt.FINISHED,
         task=self.task_not_repeatable_finished_attempt)
     self.task_draft = TaskFactory.create(is_draft=True)
     self.task_invalid = TaskFactory.create(is_invalid=True)
     self.task_no_draft = TaskFactory.create(is_draft=False)
     self.task_start_jan = TaskFactory.create(
         is_draft=False, start_date=aware_datetime(2014, 1, 1))
     self.task_end_jan = TaskFactory.create(is_draft=False, end_date=aware_datetime(2014, 1, 1))
     self.task_range_jan_feb = TaskFactory.create(
         is_draft=False, start_date=aware_datetime(2014, 1, 1),
         end_date=aware_datetime(2014, 2, 1))
コード例 #24
0
 def test_close_expired_task_attempts(self):
     """
     The close_expired_task_attempts routine should close all
     attempts for tasks that are no longer available,
     set them as requiring notification,
     and return the number that were closed.
     """
     user1, user2, user3 = UserFactory.create_batch(3)
     TaskAttemptFactory.create(user=user1,
                               state=TaskAttempt.STARTED,
                               task=self.task_end_jan)
     TaskAttemptFactory.create(user=user2,
                               state=TaskAttempt.STARTED,
                               task=self.task_end_jan)
     TaskAttemptFactory.create(user=user3,
                               state=TaskAttempt.STARTED,
                               task=self.task_no_draft)
     eq_(
         self.task_end_jan.taskattempt_set.filter(
             state=TaskAttempt.STARTED).count(), 2)
     eq_(
         self.task_no_draft.taskattempt_set.filter(
             state=TaskAttempt.STARTED).count(), 1)
     eq_(TaskAttempt.close_expired_task_attempts(), 2)
     eq_(
         TaskAttempt.objects.filter(task=self.task_end_jan,
                                    state=TaskAttempt.STARTED).count(), 0)
     eq_(
         TaskAttempt.objects.filter(task=self.task_end_jan,
                                    state=TaskAttempt.CLOSED,
                                    requires_notification=True).count(), 2)
     eq_(
         TaskAttempt.objects.filter(task=self.task_no_draft,
                                    state=TaskAttempt.STARTED).count(), 1)
コード例 #25
0
ファイル: test_models.py プロジェクト: akatsoulas/oneanddone
 def test_close_expired_task_attempts(self):
     """
     The close_expired_task_attempts routine should close all
     attempts for tasks that are no longer available,
     set them as requiring notification,
     and return the number that were closed.
     """
     task_no_expire = TaskFactory.create()
     task = TaskFactory.create(end_date=timezone.now() + timedelta(days=1))
     future_date = timezone.now() + timedelta(days=2)
     user1, user2, user3 = UserFactory.create_batch(3)
     TaskAttemptFactory.create(
         user=user1,
         state=TaskAttempt.STARTED,
         task=task)
     TaskAttemptFactory.create(
         user=user2,
         state=TaskAttempt.STARTED,
         task=task)
     TaskAttemptFactory.create(
         user=user3,
         state=TaskAttempt.STARTED,
         task=task_no_expire)
     eq_(task.taskattempt_set.filter(state=TaskAttempt.STARTED).count(), 2)
     eq_(task_no_expire.taskattempt_set.filter(state=TaskAttempt.STARTED).count(), 1)
     with patch('oneanddone.tasks.models.timezone.now') as now:
         now.return_value = future_date
         eq_(TaskAttempt.close_expired_task_attempts(), 2)
     eq_(TaskAttempt.objects.filter(task=task,
                                    state=TaskAttempt.STARTED).count(), 0)
     eq_(TaskAttempt.objects.filter(task=task,
                                    state=TaskAttempt.CLOSED,
                                    requires_notification=True).count(), 2)
     eq_(TaskAttempt.objects.filter(task=task_no_expire,
                                    state=TaskAttempt.STARTED).count(), 1)
コード例 #26
0
    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)
コード例 #27
0
ファイル: test_views.py プロジェクト: lizzard/oneanddone
    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())
コード例 #28
0
ファイル: test_models.py プロジェクト: akatsoulas/oneanddone
 def test_save_closes_task_attempts(self):
     """
     When a saved task is unavailable,
     close any open attempts, and set the attempts
     to require a notification.
     """
     user1 = UserFactory.create()
     user2 = UserFactory.create()
     TaskAttemptFactory.create(
         user=user1,
         state=TaskAttempt.STARTED,
         task=self.task_no_draft)
     TaskAttemptFactory.create(
         user=user2,
         state=TaskAttempt.STARTED,
         task=self.task_no_draft)
     eq_(self.task_no_draft.taskattempt_set.filter(state=TaskAttempt.STARTED).count(), 2)
     self.task_no_draft.is_draft = True
     self.task_no_draft.save()
     eq_(TaskAttempt.objects.filter(task=self.task_no_draft,
                                    state=TaskAttempt.STARTED).count(), 0)
     eq_(TaskAttempt.objects.filter(task=self.task_no_draft,
                                    state=TaskAttempt.CLOSED,
                                    requires_notification=True).count(), 2)
コード例 #29
0
 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)
コード例 #30
0
 def setUp(self):
     user = UserFactory.create()
     task = TaskFactory.create()
     self.attempt = TaskAttemptFactory.create(user=user, task=task)
コード例 #31
0
ファイル: test_models.py プロジェクト: akatsoulas/oneanddone
 def setUp(self):
     TaskAttempt.objects.all().delete()
     user = UserFactory.create()
     task = TaskFactory.create()
     self.attempt = TaskAttemptFactory.create(user=user, task=task)
コード例 #32
0
 def test_recent_users(self):
     """
     recent_users should return users sorted by most recent task activity
     """
     task = TaskFactory.create()
     user1 = UserProfileFactory.create().user
     user2 = UserProfileFactory.create().user
     user3 = UserProfileFactory.create().user
     user4 = UserFactory.create()
     TaskAttemptFactory.create(user=user4,
                               state=TaskAttempt.STARTED,
                               task=task)
     TaskAttemptFactory.create(user=user3,
                               state=TaskAttempt.STARTED,
                               task=task)
     TaskAttemptFactory.create(user=user2,
                               state=TaskAttempt.STARTED,
                               task=task)
     TaskAttemptFactory.create(user=user2,
                               state=TaskAttempt.FINISHED,
                               task=task)
     TaskAttemptFactory.create(user=user1,
                               state=TaskAttempt.STARTED,
                               task=task)
     TaskAttemptFactory.create(user=user3,
                               state=TaskAttempt.ABANDONED,
                               task=task)
     eq_(user1.taskattempt_set.all().count(), 1)
     eq_(user2.taskattempt_set.all().count(), 2)
     eq_(user3.taskattempt_set.all().count(), 2)
     eq_(user4.taskattempt_set.all().count(), 1)
     qs = User.recent_users()
     eq_(len(qs), 3)
     eq_(qs[0], user1)
     eq_(qs[1], user2)
     eq_(qs[2], user3)
コード例 #33
0
ファイル: test_models.py プロジェクト: bitgeeky/oneanddone
 def test_attempts_finished_count(self):
     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)
コード例 #34
0
 def setUp(self):
     user = UserFactory.create()
     task = TaskFactory.create()
     self.attempt = TaskAttemptFactory.create(user=user, task=task)
コード例 #35
0
 def setUp(self):
     TaskAttempt.objects.all().delete()
     user = UserFactory.create()
     task = TaskFactory.create()
     self.attempt = TaskAttemptFactory.create(user=user, task=task)