本文整理汇总了Python中osf_tests.factories.CommentFactory类的典型用法代码示例。如果您正苦于以下问题:Python CommentFactory类的具体用法?Python CommentFactory怎么用?Python CommentFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CommentFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_update_wiki_updates_contributor_comments_viewed_timestamp
def test_update_wiki_updates_contributor_comments_viewed_timestamp(self):
contributor = AuthUserFactory()
project = ProjectFactory(creator=self.user, is_public=True)
project.add_contributor(contributor)
project.save()
wiki_page = WikiFactory(node=project, page_name='test')
wiki = WikiVersionFactory(wiki_page=wiki_page)
comment = CommentFactory(node=project, target=Guid.load(wiki_page._id), user=self.user)
# user views comments -- sets user.comments_viewed_timestamp
url = project.api_url_for('update_comments_timestamp')
res = self.app.put_json(url, {
'page': 'wiki',
'rootId': wiki_page._id
}, auth=self.user.auth)
assert res.status_code == 200
self.user.reload()
assert wiki_page._id in self.user.comments_viewed_timestamp
# contributor views comments -- sets contributor.comments_viewed_timestamp
res = self.app.put_json(url, {
'page': 'wiki',
'rootId': wiki_page._id
}, auth=contributor.auth)
contributor.reload()
assert wiki_page._id in contributor.comments_viewed_timestamp
# user updates the wiki
project.update_node_wiki('test', 'Updating wiki', self.auth)
comment.reload()
contributor.reload()
new_version_id = project.get_wiki_version('test')._id
assert wiki_page._id in contributor.comments_viewed_timestamp
assert comment.target.referent._id == wiki_page._id
示例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 = AdminLogEntry.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 = AdminLogEntry.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()
示例3: public_comment
def public_comment(self, user, contributor, public_project):
public_comment = CommentFactory(node=public_project, user=contributor)
public_comment.reports = {user._id: {
'category': 'spam',
'text': 'This is spam',
'date': timezone.now(),
'retracted': False,
}}
public_comment.save()
return public_comment
示例4: 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()
示例5: comment
def comment(self, user, contributor, private_project, file):
comment = CommentFactory(
node=private_project,
target=file.get_guid(),
user=contributor)
comment.reports = {user._id: {
'category': 'spam',
'text': 'This is spam',
'date': timezone.now(),
'retracted': False,
}}
comment.save()
return comment
示例6: 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, app, user, private_project, comment, set_up_payload):
reply_target = Guid.load(comment._id)
reply = CommentFactory(
node=private_project,
target=reply_target, user=user
)
reply_url = '/{}comments/{}/'.format(API_BASE, reply._id)
reply.is_deleted = True
reply.save()
payload = set_up_payload(reply._id, has_content=False)
res = app.patch_json_api(reply_url, payload, auth=user.auth)
assert res.status_code == 200
assert not res.json['data']['attributes']['deleted']
assert res.json['data']['attributes']['content'] == reply.content
示例7: setUp
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()
示例8: _set_up_public_project_comment_reports
def _set_up_public_project_comment_reports(self, comment_level='public'):
self.public_project = ProjectFactory.create(is_public=True, creator=self.user, comment_level=comment_level)
self.public_project.add_contributor(contributor=self.contributor, save=True)
self.public_comment = CommentFactory.build(node=self.public_project, user=self.contributor)
self.public_comment.reports = self.public_comment.reports or {}
self.public_comment.reports[self.user._id] = {
'category': 'spam',
'text': 'This is spam',
'date': timezone.now(),
'retracted': False,
}
self.public_comment.save()
self.public_url = '/{}comments/{}/reports/'.format(API_BASE, self.public_comment._id)
示例9: test_update_wiki_updates_comments_and_user_comments_viewed_timestamp
def test_update_wiki_updates_comments_and_user_comments_viewed_timestamp(self):
project = ProjectFactory(creator=self.user, is_public=True)
wiki_page = WikiFactory(node=project, page_name='test')
wiki = WikiVersionFactory(wiki_page=wiki_page)
comment = CommentFactory(node=project, target=Guid.load(wiki_page._id), user=UserFactory())
# user views comments -- sets user.comments_viewed_timestamp
url = project.api_url_for('update_comments_timestamp')
res = self.app.put_json(url, {
'page': 'wiki',
'rootId': wiki_page._id
}, auth=self.user.auth)
assert res.status_code == 200
self.user.reload()
assert wiki_page._id in self.user.comments_viewed_timestamp
# user updates the wiki
wiki_page.update(self.user, 'Updating wiki')
comment.reload()
self.user.reload()
assert wiki_page._id in self.user.comments_viewed_timestamp
assert comment.target.referent._id == wiki_page._id
示例10: _set_up_private_project_comment_reports
def _set_up_private_project_comment_reports(self):
self.private_project = ProjectFactory.create(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.get_guid(), user=self.contributor)
self.comment.reports = self.comment.reports or {}
self.comment.reports[self.user._id] = {
'category': 'spam',
'text': 'This is spam',
'date': timezone.now(),
'retracted': False,
}
self.comment.save()
self.private_url = '/{}comments/{}/reports/'.format(API_BASE, self.comment._id)
示例11: test_private_node_delete_report_detail_auth_misc
def test_private_node_delete_report_detail_auth_misc(
self, app, user, contributor, non_contrib,
private_project, private_url, comment
):
# test_private_node_reported_contributor_cannot_delete_report_detail
res = app.delete_json_api(
private_url, auth=contributor.auth,
expect_errors=True
)
assert res.status_code == 403
# test_private_node_logged_in_non_contrib_cannot_delete_report_detail
res = app.delete_json_api(
private_url, auth=non_contrib.auth,
expect_errors=True
)
assert res.status_code == 403
# test_private_node_logged_out_contributor_cannot_delete_detail
res = app.delete_json_api(private_url, expect_errors=True)
assert res.status_code == 401
# test_private_node_reporting_contributor_can_delete_report_detail
comment_new = CommentFactory.build(
node=private_project,
user=contributor,
target=comment.target
)
comment_new.reports = {user._id: {
'category': 'spam',
'text': 'This is spam',
'date': timezone.now(),
'retracted': False,
}}
comment_new.save()
url = '/{}comments/{}/reports/{}/'.format(
API_BASE, comment_new._id, user._id)
res = app.delete_json_api(url, auth=user.auth)
assert res.status_code == 204
示例12: setUp
def setUp(self):
super(TestSpamMixin, self).setUp()
self.comment = CommentFactory()
self.auth = Auth(user=self.comment.user)
示例13: TestSpamListView
class TestSpamListView(AdminTestCase):
def setUp(self):
super(TestSpamListView, self).setUp()
Comment.objects.all().delete()
self.project = ProjectFactory(is_public=True)
self.user_1 = AuthUserFactory()
self.user_2 = AuthUserFactory()
self.project.add_contributor(self.user_1)
self.project.add_contributor(self.user_2)
self.project.save()
self.user_1.save()
self.user_2.save()
date = timezone.now()
self.comment_1 = CommentFactory(node=self.project, user=self.user_1)
self.comment_2 = CommentFactory(node=self.project, user=self.user_1)
self.comment_3 = CommentFactory(node=self.project, user=self.user_1)
self.comment_4 = CommentFactory(node=self.project, user=self.user_1)
self.comment_5 = CommentFactory(node=self.project, user=self.user_2)
self.comment_6 = CommentFactory(node=self.project, user=self.user_2)
self.comment_1.report_abuse(
user=self.user_2,
save=True,
category='spam',
date=date - timedelta(seconds=5)
)
self.comment_2.report_abuse(
user=self.user_2,
save=True,
category='spam',
date=date - timedelta(seconds=4)
)
self.comment_3.report_abuse(
user=self.user_2,
save=True,
category='spam',
date=date - timedelta(seconds=3)
)
self.comment_4.report_abuse(
user=self.user_2,
save=True,
category='spam',
date=date - timedelta(seconds=2)
)
self.comment_5.report_abuse(
user=self.user_1,
save=True,
category='spam',
date=date - timedelta(seconds=1)
)
self.comment_6.report_abuse(user=self.user_1, save=True,
category='spam')
self.request = RequestFactory().get('/fake_path')
self.view = SpamList()
self.view = setup_view(self.view, self.request, user_id=self.user_1._id)
def test_get_spam(self):
res = list(self.view.get_queryset())
nt.assert_equal(len(res), 6)
response_list = [r._id for r in res]
should_be = [
self.comment_6._id,
self.comment_5._id,
self.comment_4._id,
self.comment_3._id,
self.comment_2._id,
self.comment_1._id
]
nt.assert_list_equal(should_be, response_list)
def test_get_context_data(self):
self.view.object_list = self.view.get_queryset()
res = self.view.get_context_data()
nt.assert_is_instance(res['spam'], list)
nt.assert_is_instance(res['spam'][0], dict)
nt.assert_equal(res['status'], '1')
nt.assert_equal(res['page_number'], 1)
示例14: TestUserSpamListView
class TestUserSpamListView(AdminTestCase):
def setUp(self):
super(TestUserSpamListView, self).setUp()
self.project = ProjectFactory(is_public=True)
self.user_1 = AuthUserFactory()
self.user_2 = AuthUserFactory()
self.project.add_contributor(self.user_1)
self.project.add_contributor(self.user_2)
self.project.save()
self.user_1.save()
self.user_2.save()
self.comment_1 = CommentFactory(node=self.project, user=self.user_1)
self.comment_2 = CommentFactory(node=self.project, user=self.user_1)
self.comment_3 = CommentFactory(node=self.project, user=self.user_1)
self.comment_4 = CommentFactory(node=self.project, user=self.user_1)
self.comment_5 = CommentFactory(node=self.project, user=self.user_2)
self.comment_6 = CommentFactory(node=self.project, user=self.user_2)
self.comment_1.report_abuse(user=self.user_2, save=True,
category='spam')
self.comment_2.report_abuse(user=self.user_2, save=True,
category='spam')
self.comment_3.report_abuse(user=self.user_2, save=True,
category='spam')
self.comment_4.report_abuse(user=self.user_2, save=True,
category='spam')
self.comment_5.report_abuse(user=self.user_1, save=True,
category='spam')
self.comment_6.report_abuse(user=self.user_1, save=True,
category='spam')
self.request = RequestFactory().get('/fake_path')
self.view = UserSpamList()
self.view = setup_view(self.view, self.request, user_id=self.user_1._id)
def test_get_user_spam(self):
res = list(self.view.get_queryset())
nt.assert_equal(len(res), 4)
def test_get_context_data(self):
self.view.object_list = self.view.get_queryset()
res = self.view.get_context_data()
nt.assert_is_instance(res['spam'], list)
nt.assert_is_instance(res['spam'][0], dict)
nt.assert_equal(res['status'], '1')
nt.assert_equal(res['page_number'], 1)
nt.assert_equal(res['user_id'], self.user_1._id)
示例15: TestSpamMixin
class TestSpamMixin(OsfTestCase):
def setUp(self):
super(TestSpamMixin, self).setUp()
self.comment = CommentFactory()
self.auth = Auth(user=self.comment.user)
def test_report_abuse(self):
user = UserFactory()
time = timezone.now()
self.comment.report_abuse(
user, date=time, category='spam', text='ads', save=True)
assert_equal(self.comment.spam_status, SpamStatus.FLAGGED)
equivalent = dict(
date=time,
category='spam',
text='ads',
retracted=False
)
assert_in(user._id, self.comment.reports)
assert_equal(self.comment.reports[user._id], equivalent)
def test_report_abuse_own_comment(self):
with assert_raises(ValueError):
self.comment.report_abuse(
self.comment.user,
category='spam', text='ads',
save=True
)
assert_equal(self.comment.spam_status, SpamStatus.UNKNOWN)
def test_retract_report(self):
user = UserFactory()
time = timezone.now()
self.comment.report_abuse(
user, date=time, category='spam', text='ads', save=True
)
assert_equal(self.comment.spam_status, SpamStatus.FLAGGED)
self.comment.retract_report(user, save=True)
assert_equal(self.comment.spam_status, SpamStatus.UNKNOWN)
equivalent = {
'date': time,
'category': 'spam',
'text': 'ads',
'retracted': True
}
assert_in(user._id, self.comment.reports)
assert_equal(self.comment.reports[user._id], equivalent)
def test_retract_report_not_reporter(self):
reporter = UserFactory()
non_reporter = UserFactory()
self.comment.report_abuse(
reporter, category='spam', text='ads', save=True
)
with assert_raises(ValueError):
self.comment.retract_report(non_reporter, save=True)
assert_equal(self.comment.spam_status, SpamStatus.FLAGGED)
def test_retract_one_report_of_many(self):
user_1 = UserFactory()
user_2 = UserFactory()
time = timezone.now()
self.comment.report_abuse(
user_1, date=time, category='spam', text='ads', save=True
)
assert_equal(self.comment.spam_status, SpamStatus.FLAGGED)
self.comment.report_abuse(
user_2, date=time, category='spam', text='all', save=True
)
self.comment.retract_report(user_1, save=True)
equivalent = {
'date': time,
'category': 'spam',
'text': 'ads',
'retracted': True
}
assert_in(user_1._id, self.comment.reports)
assert_equal(self.comment.reports[user_1._id], equivalent)
assert_equal(self.comment.spam_status, SpamStatus.FLAGGED)
def test_flag_spam(self):
self.comment.flag_spam()
self.comment.save()
assert_equal(self.comment.spam_status, SpamStatus.FLAGGED)
def test_cannot_remove_flag_not_retracted(self):
user = UserFactory()
self.comment.report_abuse(
user, category='spam', text='ads', save=True
)
self.comment.remove_flag(save=True)
assert_equal(self.comment.spam_status, SpamStatus.FLAGGED)
def test_remove_flag(self):
self.comment.flag_spam()
self.comment.save()
assert_equal(self.comment.spam_status, SpamStatus.FLAGGED)
self.comment.remove_flag(save=True)
assert_equal(self.comment.spam_status, SpamStatus.UNKNOWN)
#.........这里部分代码省略.........