本文整理汇总了Python中tests.factories.CommentFactory类的典型用法代码示例。如果您正苦于以下问题:Python CommentFactory类的具体用法?Python CommentFactory怎么用?Python CommentFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CommentFactory类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: test_public_node_logged_in_non_contributor_reporter_can_view_report_detail
def test_public_node_logged_in_non_contributor_reporter_can_view_report_detail(self):
project = ProjectFactory(is_public=True, comment_level='public')
comment = CommentFactory.build(node=project, user=project.creator)
comment.reports = {self.non_contributor._id: {'category': 'spam', 'text': 'This is spam'}}
comment.save()
url = '/{}comments/{}/reports/{}/'.format(API_BASE, comment._id, self.non_contributor._id)
res = self.app.get(url, auth=self.non_contributor.auth)
assert_equal(res.status_code, 200)
开发者ID:mchelen,项目名称:osf.io,代码行数:8,代码来源:test_comment_report_detail.py
示例17: test_find_unread_includes_edited_comments
def test_find_unread_includes_edited_comments(self):
project = ProjectFactory()
user = AuthUserFactory()
project.add_contributor(user)
project.save()
comment = CommentFactory(node=project, user=project.creator)
url = project.api_url_for("update_comments_timestamp")
payload = {"page": "node", "rootId": project._id}
res = self.app.put_json(url, payload, auth=user.auth)
user.reload()
n_unread = Comment.find_n_unread(user=user, node=project, page="node")
assert_equal(n_unread, 0)
# Edit previously read comment
comment.edit(auth=Auth(project.creator), content="edited", save=True)
n_unread = Comment.find_n_unread(user=user, node=project, page="node")
assert_equal(n_unread, 1)
开发者ID:ycchen1989,项目名称:osf.io,代码行数:18,代码来源:test_comments.py
示例18: _set_up_private_project_file_comment_reports
def _set_up_private_project_file_comment_reports(self):
self.private_project = ProjectFactory.build(is_public=False, creator=self.user)
self.private_project.add_contributor(contributor=self.contributor, save=True)
self.file = test_utils.create_test_file(self.private_project, self.user)
self.comment = CommentFactory.build(node=self.private_project, target=self.file, user=self.contributor)
self.comment.reports = self.comment.reports or {}
self.comment.reports[self.user._id] = {'category': 'spam', 'text': 'This is spam'}
self.comment.save()
self.private_url = '/{}comments/{}/reports/'.format(API_BASE, self.comment._id)
开发者ID:mchelen,项目名称:osf.io,代码行数:9,代码来源:test_comment_report_list.py
示例19: TestEmailFormView
class TestEmailFormView(AdminTestCase):
def setUp(self):
super(TestEmailFormView, 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()
self.view = EmailFormView()
self.form = EmailForm(data={
'author': 'Nemo',
'message': 'A message for spammers.',
'subject': 'stop spamming',
'email': ('[email protected]', '[email protected]')
})
self.view = setup_form_view(self.view, self.request, self.form,
spam_id=self.comment._id)
@mock.patch('admin.spam.views.render')
def test_get_context_data(self, mock_render):
res = self.view.get_context_data()
nt.assert_equal(res['status'], '1')
nt.assert_equal(res['page_number'], '1')
nt.assert_is_instance(res['comment'], dict)
def test_get_context_data_bad_id(self):
view = setup_view(EmailFormView(), self.request, spam_id='a1')
with nt.assert_raises(Http404):
view.get_context_data()
@mock.patch('admin.spam.views.render')
def test_get_initial(self, mock_render):
self.view.get_initial()
res = self.view.initial
nt.assert_is_instance(res, dict)
nt.assert_is_instance(res['email'], list)
nt.assert_is_instance(res['email'][0], tuple)
def test_get_initial_bad_id(self):
view = setup_view(EmailFormView(), self.request, spam_id='a1')
with nt.assert_raises(Http404):
view.get_initial()
开发者ID:alexschiller,项目名称:osf.io,代码行数:42,代码来源:test_views.py
示例20: setUp
def setUp(self):
super(TestCommentFiltering, self).setUp()
self.user = AuthUserFactory()
self.project = ProjectFactory(creator=self.user)
self.comment = CommentFactory(node=self.project, user=self.user)
self.deleted_comment = CommentFactory(node=self.project, user=self.user, is_deleted=True)
self.base_url = "/{}nodes/{}/comments/".format(API_BASE, self.project._id)
self.formatted_date_created = self.comment.date_created.strftime("%Y-%m-%dT%H:%M:%S.%f")
self.comment.edit("Edited comment", auth=core.Auth(self.user), save=True)
self.formatted_date_modified = self.comment.date_modified.strftime("%Y-%m-%dT%H:%M:%S.%f")
开发者ID:Alpani,项目名称:osf.io,代码行数:11,代码来源:test_node_comments_list.py
注:本文中的tests.factories.CommentFactory类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论