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


Python factories.CommentFactory类代码示例

本文整理汇总了Python中tests.factories.CommentFactory的典型用法代码示例。如果您正苦于以下问题:Python CommentFactory类的具体用法?Python CommentFactory怎么用?Python CommentFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: test_private_node_logged_out_user_cannot_see_deleted_comment

 def test_private_node_logged_out_user_cannot_see_deleted_comment(self):
     self._set_up_private_project_with_comment()
     comment = CommentFactory(node=self.private_project, target=self.private_project, user=self.user)
     comment.is_deleted = True
     comment.save()
     url = '/{}comments/{}/'.format(API_BASE, comment._id)
     res = self.app.get(url, expect_errors=True)
     assert_equal(res.status_code, 401)
开发者ID:mchelen,项目名称:osf.io,代码行数:8,代码来源:test_comment_detail.py

示例2: TestSpamDetail

class TestSpamDetail(AdminTestCase):
    def setUp(self):
        super(TestSpamDetail, self).setUp()
        self.comment = CommentFactory()
        self.comment.report_abuse(user=AuthUserFactory(), save=True,
                                  category='spam')
        self.request = RequestFactory().post('/fake_path')
        self.request.user = UserFactory()

    def test_confirm_spam(self):
        form_data = {'confirm': str(SpamStatus.SPAM)}
        form = ConfirmForm(data=form_data)
        nt.assert_true(form.is_valid())
        view = SpamDetail()
        view = setup_form_view(
            view, self.request, form, spam_id=self.comment._id)
        with transaction.atomic():
            view.form_valid(form)
        obj = OSFLogEntry.objects.latest(field_name='action_time')
        nt.assert_equal(obj.object_id, self.comment._id)
        nt.assert_in('Confirmed SPAM:', obj.message())

    def test_confirm_ham(self):
        form_data = {'confirm': str(SpamStatus.HAM)}
        form = ConfirmForm(data=form_data)
        nt.assert_true(form.is_valid())
        view = SpamDetail()
        view = setup_form_view(
            view, self.request, form, spam_id=self.comment._id)
        with transaction.atomic():
            view.form_valid(form)
        obj = OSFLogEntry.objects.latest(field_name='action_time')
        nt.assert_equal(obj.object_id, self.comment._id)
        nt.assert_in('Confirmed HAM:', obj.message())

    def test_form_valid_bad_id(self):
        form = ConfirmForm()
        view = SpamDetail()
        view = setup_form_view(view, self.request, form, spam_id='a1')
        with nt.assert_raises(Http404):
            view.form_valid(form)

    def test_get_context_data(self):
        view = SpamDetail()
        view = setup_view(view, self.request, spam_id=self.comment._id)
        res = view.get_context_data()
        nt.assert_equal(res['status'], '1')
        nt.assert_equal(res['page_number'], '1')
        nt.assert_is_instance(res['comment'], dict)
        nt.assert_equal(res['SPAM_STATUS'].UNKNOWN, SpamStatus.UNKNOWN)
        nt.assert_equal(res['SPAM_STATUS'].SPAM, SpamStatus.SPAM)
        nt.assert_equal(res['SPAM_STATUS'].HAM, SpamStatus.HAM)
        nt.assert_equal(res['SPAM_STATUS'].FLAGGED, SpamStatus.FLAGGED)

    def test_get_context_data_bad_id(self):
        view = setup_view(SpamDetail(), self.request, spam_id='a1')
        with nt.assert_raises(Http404):
            view.get_context_data()
开发者ID:alexschiller,项目名称:osf.io,代码行数:58,代码来源:test_views.py

示例3: test_private_node_logged_out_user_cannot_see_deleted_file_comment

 def test_private_node_logged_out_user_cannot_see_deleted_file_comment(self):
     self._set_up_private_project_with_file_comment()
     comment = CommentFactory(node=self.private_project, target=self.file, user=self.user)
     comment.is_deleted = True
     comment.save()
     url = '/{}comments/{}/'.format(API_BASE, comment._id)
     res = self.app.get(url, expect_errors=True)
     assert_equal(res.status_code, 401)
     assert_equal(res.json['errors'][0]['detail'], 'Authentication credentials were not provided.')
开发者ID:mchelen,项目名称:osf.io,代码行数:9,代码来源:test_comment_detail.py

示例4: test_private_node_contributor_cannot_see_other_users_deleted_file_comment

 def test_private_node_contributor_cannot_see_other_users_deleted_file_comment(self):
     self._set_up_private_project_with_file_comment()
     comment = CommentFactory(node=self.private_project, target=self.file, user=self.user)
     comment.is_deleted = True
     comment.save()
     url = '/{}comments/{}/'.format(API_BASE, comment._id)
     res = self.app.get(url, auth=self.contributor.auth)
     assert_equal(res.status_code, 200)
     assert_is_none(res.json['data']['attributes']['content'])
开发者ID:mchelen,项目名称:osf.io,代码行数:9,代码来源:test_comment_detail.py

示例5: test_public_node_non_contributor_cannot_view_other_users_deleted_comment

 def test_public_node_non_contributor_cannot_view_other_users_deleted_comment(self):
     public_project = ProjectFactory(is_public=True, creator=self.user)
     comment = CommentFactory(node=public_project, target=public_project, user=self.user)
     comment.is_deleted = True
     comment.save()
     url = '/{}comments/{}/'.format(API_BASE, comment._id)
     res = self.app.get(url, auth=self.non_contributor.auth)
     assert_equal(res.status_code, 200)
     assert_is_none(res.json['data']['attributes']['content'])
开发者ID:mchelen,项目名称:osf.io,代码行数:9,代码来源:test_comment_detail.py

示例6: test_private_node_only_logged_in_commenter_can_view_deleted_comment

 def test_private_node_only_logged_in_commenter_can_view_deleted_comment(self):
     self._set_up_private_project_with_comment()
     comment = CommentFactory(node=self.private_project, target=self.private_project, user=self.user)
     comment.is_deleted = True
     comment.save()
     url = '/{}comments/{}/'.format(API_BASE, comment._id)
     res = self.app.get(url, auth=self.user.auth)
     assert_equal(res.status_code, 200)
     assert_equal(res.json['data']['attributes']['content'], comment.content)
开发者ID:mchelen,项目名称:osf.io,代码行数:9,代码来源:test_comment_detail.py

示例7: test_public_node_logged_out_user_cannot_view_deleted_file_comments

 def test_public_node_logged_out_user_cannot_view_deleted_file_comments(self):
     self._set_up_public_project_with_file_comment()
     comment = CommentFactory(node=self.public_project, target=self.public_file, user=self.user)
     comment.is_deleted = True
     comment.save()
     url = '/{}comments/{}/'.format(API_BASE, comment._id)
     res = self.app.get(url)
     assert_equal(res.status_code, 200)
     assert_is_none(res.json['data']['attributes']['content'])
开发者ID:mchelen,项目名称:osf.io,代码行数:9,代码来源:test_comment_detail.py

示例8: test_private_node_only_logged_in_contributor_commenter_can_undelete_own_reply

 def test_private_node_only_logged_in_contributor_commenter_can_undelete_own_reply(self):
     self._set_up_private_project_with_comment()
     reply_target = Guid.load(self.comment._id)
     reply = CommentFactory(node=self.private_project, target=reply_target, user=self.user)
     reply_url = '/{}comments/{}/'.format(API_BASE, reply)
     reply.is_deleted = True
     reply.save()
     payload = self._set_up_payload(reply._id, has_content=False)
     res = self.app.patch_json_api(reply_url, payload, auth=self.user.auth)
     assert_equal(res.status_code, 200)
     assert_false(res.json['data']['attributes']['deleted'])
     assert_equal(res.json['data']['attributes']['content'], reply.content)
开发者ID:baylee-d,项目名称:osf.io,代码行数:12,代码来源:test_comment_detail.py

示例9: TestEmailView

class TestEmailView(AdminTestCase):
    def setUp(self):
        super(TestEmailView, self).setUp()
        self.comment = CommentFactory()
        self.comment.report_abuse(user=AuthUserFactory(), save=True,
                                  category='spam')
        self.request = RequestFactory().post('/fake_path')
        self.request.user = UserFactory()

    def test_get_object_bad_id(self):
        view = setup_view(EmailView(), self.request, spam_id='a1')
        with nt.assert_raises(Http404):
            view.get_object()
开发者ID:baylee-d,项目名称:osf.io,代码行数:13,代码来源:test_views.py

示例10: test_public_node_private_comment_level_non_contributor_cannot_see_reports

 def test_public_node_private_comment_level_non_contributor_cannot_see_reports(self):
     project = ProjectFactory(is_public=True, creator=self.user, comment_level="private")
     comment = CommentFactory(node=project, target=project, user=self.user)
     comment.reports = dict()
     comment.reports[self.user._id] = {
         "category": "spam",
         "text": "This is spam",
         "date": datetime.utcnow(),
         "retracted": False,
     }
     comment.save()
     url = "/{}comments/{}/reports/".format(API_BASE, comment._id)
     res = self.app.get(url, auth=self.non_contributor.auth, expect_errors=True)
     assert_equal(res.status_code, 403)
     assert_equal(res.json["errors"][0]["detail"], "You do not have permission to perform this action.")
开发者ID:KAsante95,项目名称:osf.io,代码行数:15,代码来源:test_comment_report_list.py

示例11: test_public_node_private_comment_level_non_contributor_cannot_see_reports

 def test_public_node_private_comment_level_non_contributor_cannot_see_reports(self):
     project = ProjectFactory(is_public=True, creator=self.user, comment_level='private')
     comment = CommentFactory(node=project, user=self.user)
     comment.reports = dict()
     comment.reports[self.user._id] = {
         'category': 'spam',
         'text': 'This is spam',
         'date': datetime.utcnow(),
         'retracted': False,
     }
     comment.save()
     url = '/{}comments/{}/reports/'.format(API_BASE, comment._id)
     res = self.app.get(url, auth=self.non_contributor.auth, expect_errors=True)
     assert_equal(res.status_code, 403)
     assert_equal(res.json['errors'][0]['detail'], 'You do not have permission to perform this action.')
开发者ID:DanielSBrown,项目名称:osf.io,代码行数:15,代码来源:test_comment_report_list.py

示例12: _set_up_public_project_with_file_comment

 def _set_up_public_project_with_file_comment(self):
     self.public_project = ProjectFactory.build(is_public=True, creator=self.user, comment_level='private')
     self.public_project.add_contributor(self.contributor, save=True)
     self.public_file = test_utils.create_test_file(self.public_project, self.user)
     self.public_comment = CommentFactory(node=self.public_project, target=self.public_file, user=self.user)
     self.public_url = '/{}comments/{}/'.format(API_BASE, self.public_comment._id)
     self.public_comment_payload = self._set_up_payload(self.public_comment._id)
开发者ID:mchelen,项目名称:osf.io,代码行数:7,代码来源:test_comment_detail.py

示例13: setUp

 def setUp(self):
     super(TestSpamDetail, self).setUp()
     self.comment = CommentFactory()
     self.comment.report_abuse(user=AuthUserFactory(), save=True,
                               category='spam')
     self.request = RequestFactory().post('/fake_path')
     self.request.user = UserFactory()
开发者ID:alexschiller,项目名称:osf.io,代码行数:7,代码来源:test_views.py

示例14: _set_up_public_project_comment_reports

 def _set_up_public_project_comment_reports(self):
     self.public_project = ProjectFactory.build(is_public=True, creator=self.user)
     self.public_project.add_contributor(contributor=self.contributor, save=True)
     self.public_comment = CommentFactory.build(node=self.public_project, target=self.public_project, user=self.contributor)
     self.public_comment.reports = {self.user._id: {'category': 'spam', 'text': 'This is spam'}}
     self.public_comment.save()
     self.public_url = '/{}comments/{}/reports/{}/'.format(API_BASE, self.public_comment._id, self.user._id)
开发者ID:mchelen,项目名称:osf.io,代码行数:7,代码来源:test_comment_report_detail.py

示例15: test_public_node_reporting_contributor_can_delete_detail

 def test_public_node_reporting_contributor_can_delete_detail(self):
     self._set_up_public_project_file_comment_reports()
     comment = CommentFactory.build(node=self.public_project, target=self.public_file, user=self.contributor)
     comment.reports = {self.user._id: {'category': 'spam', 'text': 'This is spam'}}
     comment.save()
     url = '/{}comments/{}/reports/{}/'.format(API_BASE, comment._id, self.user._id)
     res = self.app.delete_json_api(url, auth=self.user.auth)
     assert_equal(res.status_code, 204)
开发者ID:mchelen,项目名称:osf.io,代码行数:8,代码来源:test_comment_report_detail.py


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