当前位置: 首页>>代码示例>>Python>>正文


Python UserFactory.create方法代码示例

本文整理汇总了Python中oneanddone.users.tests.UserFactory.create方法的典型用法代码示例。如果您正苦于以下问题:Python UserFactory.create方法的具体用法?Python UserFactory.create怎么用?Python UserFactory.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在oneanddone.users.tests.UserFactory的用法示例。


在下文中一共展示了UserFactory.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_users_with_valid_completed_attempt_counts

# 需要导入模块: from oneanddone.users.tests import UserFactory [as 别名]
# 或者: from oneanddone.users.tests.UserFactory import create [as 别名]
 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)
开发者ID:Anmol2307,项目名称:oneanddone,代码行数:34,代码来源:test_models.py

示例2: test_isnt_available_to_user_other_user_non_abandoned_attempt

# 需要导入模块: from oneanddone.users.tests import UserFactory [as 别名]
# 或者: from oneanddone.users.tests.UserFactory import create [as 别名]
 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)
开发者ID:akatsoulas,项目名称:oneanddone,代码行数:12,代码来源:test_models.py

示例3: test_attempt_with_feedback_raises_404

# 需要导入模块: from oneanddone.users.tests import UserFactory [as 别名]
# 或者: from oneanddone.users.tests.UserFactory import create [as 别名]
    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)
开发者ID:VarnaSuresh,项目名称:oneanddone,代码行数:14,代码来源:test_mixins.py

示例4: test_forbidden_client

# 需要导入模块: from oneanddone.users.tests import UserFactory [as 别名]
# 或者: from oneanddone.users.tests.UserFactory import create [as 别名]
    def test_forbidden_client(self):
        """
        Test user deletion by an authenticated but forbidden client
        """
        forbidden_user = UserFactory.create()
        forbidden_token = Token.objects.create(user=forbidden_user)

        self.client.credentials(HTTP_AUTHORIZATION='Token ' + forbidden_token.key)

        test_user = UserFactory.create()
        user_uri = self.uri + test_user.email + '/'

        #Make a DELETE request
        delete_response = self.client.delete(user_uri)
        self.assert_response_status(delete_response, status.HTTP_403_FORBIDDEN)
开发者ID:myrobeandwizardhat,项目名称:oneanddone,代码行数:17,代码来源:test_api.py

示例5: test_get_task_details

# 需要导入模块: from oneanddone.users.tests import UserFactory [as 别名]
# 或者: from oneanddone.users.tests.UserFactory import create [as 别名]
    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)
开发者ID:Anmol2307,项目名称:oneanddone,代码行数:28,代码来源:test_api.py

示例6: test_missing_attempt_raises_404

# 需要导入模块: from oneanddone.users.tests import UserFactory [as 别名]
# 或者: from oneanddone.users.tests.UserFactory import create [as 别名]
 def test_missing_attempt_raises_404(self):
     """
     If there is no task attempt with the given ID, return a 404.
     """
     request = Mock(user=UserFactory.create())
     with self.assertRaises(Http404):
         self.view.dispatch(request, pk=9999)
开发者ID:Anmol2307,项目名称:oneanddone,代码行数:9,代码来源:test_mixins.py

示例7: setUp

# 需要导入模块: from oneanddone.users.tests import UserFactory [as 别名]
# 或者: from oneanddone.users.tests.UserFactory import create [as 别名]
 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))
开发者ID:akatsoulas,项目名称:oneanddone,代码行数:29,代码来源:test_models.py

示例8: test_success_url_no_profile

# 需要导入模块: from oneanddone.users.tests import UserFactory [as 别名]
# 或者: from oneanddone.users.tests.UserFactory import create [as 别名]
 def test_success_url_no_profile(self):
     """
     If the user has no profile, return the url to create user profile.
     """
     user = UserFactory.create()
     self.view.user = user
     eq_(self.view.success_url, reverse_lazy('users.profile.create'))
开发者ID:VarnaSuresh,项目名称:oneanddone,代码行数:9,代码来源:test_views.py

示例9: test_save_processes_keywords_correctly

# 需要导入模块: from oneanddone.users.tests import UserFactory [as 别名]
# 或者: from oneanddone.users.tests.UserFactory import create [as 别名]
    def test_save_processes_keywords_correctly(self):
        """
        Saving the form should update the keywords correctly.
        - Removed keywords should be removed
        - New keywords should be added
        - Remaining keywords should remain
        """
        user = UserFactory.create()
        task = TaskFactory.create()
        TaskKeywordFactory.create_batch(3, task=task)
        data = {
            'keywords': 'test3, new_keyword',
            'team': task.team.id,
        }
        for field in ('name', 'short_description', 'execution_time', 'difficulty',
                      'repeatable', 'instructions', 'is_draft'):
            data[field] = getattr(task, field)
        form = TaskForm(instance=task, data=data)
        form.save(user)

        removed_keyword = TaskKeyword.objects.filter(task=task, name='test1')
        eq_(len(removed_keyword), 0)

        added_keyword = TaskKeyword.objects.filter(task=task, name='new_keyword')
        eq_(len(added_keyword), 1)

        kept_keyword = TaskKeyword.objects.filter(task=task, name='test3')
        eq_(len(kept_keyword), 1)

        # double-check on the keywords_list property
        eq_(task.keywords_list, 'test3, new_keyword')
开发者ID:musicalchair,项目名称:oneanddone,代码行数:33,代码来源:test_forms.py

示例10: test_not_staff

# 需要导入模块: from oneanddone.users.tests import UserFactory [as 别名]
# 或者: from oneanddone.users.tests.UserFactory import create [as 别名]
 def test_not_staff(self):
     """
     If the user is not staff, raise a PermissionDenied exception.
     """
     request = Mock()
     request.user = UserFactory.create(is_staff=False)
     self.view.dispatch(request)
开发者ID:bitgeeky,项目名称:oneanddone,代码行数:9,代码来源:test_mixins.py

示例11: test_attempts_in_progress

# 需要导入模块: from oneanddone.users.tests import UserFactory [as 别名]
# 或者: from oneanddone.users.tests.UserFactory import create [as 别名]
 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))
开发者ID:VarnaSuresh,项目名称:oneanddone,代码行数:9,代码来源:test_models.py

示例12: test_get_task_list

# 需要导入模块: from oneanddone.users.tests import UserFactory [as 别名]
# 或者: from oneanddone.users.tests.UserFactory import create [as 别名]
    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)
开发者ID:VarnaSuresh,项目名称:oneanddone,代码行数:36,代码来源:test_api.py

示例13: test_is_available_to_user_no_attempts

# 需要导入模块: from oneanddone.users.tests import UserFactory [as 别名]
# 或者: from oneanddone.users.tests.UserFactory import create [as 别名]
 def test_is_available_to_user_no_attempts(self):
     """
     If there are no attempts,
     the task should be available.
     """
     user = UserFactory.create()
     eq_(self.task_not_repeatable_no_attempts.is_available_to_user(user), True)
开发者ID:akatsoulas,项目名称:oneanddone,代码行数:9,代码来源:test_models.py

示例14: test_has_completed_task_false

# 需要导入模块: from oneanddone.users.tests import UserFactory [as 别名]
# 或者: from oneanddone.users.tests.UserFactory import create [as 别名]
 def test_has_completed_task_false(self):
     """
     has_completed_task should return false if the user has not completed the task.
     """
     user = UserFactory.create()
     task = TaskFactory.create()
     ok_(not user.has_completed_task(task))
开发者ID:VarnaSuresh,项目名称:oneanddone,代码行数:9,代码来源:test_models.py

示例15: test_close_stale_onetime_attempts

# 需要导入模块: from oneanddone.users.tests import UserFactory [as 别名]
# 或者: from oneanddone.users.tests.UserFactory import create [as 别名]
 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)
开发者ID:akatsoulas,项目名称:oneanddone,代码行数:30,代码来源:test_models.py


注:本文中的oneanddone.users.tests.UserFactory.create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。