本文整理汇总了Python中tests.factories.CommentFactory.build方法的典型用法代码示例。如果您正苦于以下问题:Python CommentFactory.build方法的具体用法?Python CommentFactory.build怎么用?Python CommentFactory.build使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tests.factories.CommentFactory
的用法示例。
在下文中一共展示了CommentFactory.build方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _set_up_public_project_comment_reports
# 需要导入模块: from tests.factories import CommentFactory [as 别名]
# 或者: from tests.factories.CommentFactory import build [as 别名]
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)
示例2: test_public_node_logged_in_non_contributor_reporter_can_view_report_detail
# 需要导入模块: from tests.factories import CommentFactory [as 别名]
# 或者: from tests.factories.CommentFactory import build [as 别名]
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)
示例3: test_public_node_reporting_contributor_can_delete_detail
# 需要导入模块: from tests.factories import CommentFactory [as 别名]
# 或者: from tests.factories.CommentFactory import build [as 别名]
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)
示例4: _set_up_private_project_file_comment_reports
# 需要导入模块: from tests.factories import CommentFactory [as 别名]
# 或者: from tests.factories.CommentFactory import build [as 别名]
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)
示例5: _set_up_private_project_comment_reports
# 需要导入模块: from tests.factories import CommentFactory [as 别名]
# 或者: from tests.factories.CommentFactory import build [as 别名]
def _set_up_private_project_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.comment = CommentFactory.build(node=self.private_project, target=self.private_project, user=self.contributor)
self.comment.reports = {self.user._id: {
'category': 'spam',
'text': 'This is spam',
'date': datetime.utcnow(),
'retracted': False,
}}
self.comment.save()
self.private_url = '/{}comments/{}/reports/{}/'.format(API_BASE, self.comment._id, self.user._id)
示例6: test_private_node_reporting_contributor_can_delete_report_detail
# 需要导入模块: from tests.factories import CommentFactory [as 别名]
# 或者: from tests.factories.CommentFactory import build [as 别名]
def test_private_node_reporting_contributor_can_delete_report_detail(self):
self._set_up_private_project_comment_reports()
comment = CommentFactory.build(node=self.private_project, target=self.private_project, user=self.contributor)
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, self.user._id)
res = self.app.delete_json_api(url, auth=self.user.auth)
assert_equal(res.status_code, 204)
示例7: _set_up_public_project_comment_reports
# 需要导入模块: from tests.factories import CommentFactory [as 别名]
# 或者: from tests.factories.CommentFactory import build [as 别名]
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': datetime.utcnow(),
'retracted': False,
}
self.public_comment.save()
self.public_url = '/{}comments/{}/reports/'.format(API_BASE, self.public_comment._id)
示例8: test_public_node_non_contributor_reporter_can_view_report
# 需要导入模块: from tests.factories import CommentFactory [as 别名]
# 或者: from tests.factories.CommentFactory import build [as 别名]
def test_public_node_non_contributor_reporter_can_view_report(self):
project = ProjectFactory(is_public=True, comment_level='public')
comment = CommentFactory.build(node=project, user=project.creator)
comment.reports = comment.reports or {}
comment.reports[self.non_contributor._id] = {'category': 'spam', 'text': 'This is spam.'}
comment.save()
url = '/{}comments/{}/reports/'.format(API_BASE, comment._id)
res = self.app.get(url, auth=self.non_contributor.auth)
assert_equal(res.status_code, 200)
report_json = res.json['data']
report_ids = [report['id'] for report in report_json]
assert_equal(len(report_json), 1)
assert_in(self.non_contributor._id, report_ids)
示例9: _set_up_private_project_file_comment_reports
# 需要导入模块: from tests.factories import CommentFactory [as 别名]
# 或者: from tests.factories.CommentFactory import build [as 别名]
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",
"date": datetime.utcnow(),
"retracted": False,
}
self.comment.save()
self.private_url = "/{}comments/{}/reports/".format(API_BASE, self.comment._id)
示例10: _set_up_public_project_comment_reports
# 需要导入模块: from tests.factories import CommentFactory [as 别名]
# 或者: from tests.factories.CommentFactory import build [as 别名]
def _set_up_public_project_comment_reports(self, comment_level="public"):
self.public_project = ProjectFactory.build(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, target=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": datetime.utcnow(),
"retracted": False,
}
self.public_comment.save()
self.public_url = "/{}comments/{}/reports/".format(API_BASE, self.public_comment._id)
示例11: test_private_node_logged_out_user_cannot_undelete_comment
# 需要导入模块: from tests.factories import CommentFactory [as 别名]
# 或者: from tests.factories.CommentFactory import build [as 别名]
def test_private_node_logged_out_user_cannot_undelete_comment(self):
self._set_up_private_project_with_comment()
comment = CommentFactory.build(node=self.private_project, target=self.private_project, user=self.user)
comment.is_deleted = True
comment.save()
url = '/{}comments/{}/'.format(API_BASE, comment._id)
payload = {
'data': {
'id': comment._id,
'type': 'comments',
'attributes': {
'deleted': False
}
}
}
res = self.app.patch_json_api(url, payload, expect_errors=True)
assert_equal(res.status_code, 401)
示例12: test_private_node_non_contributor_cannot_undelete_file_comment
# 需要导入模块: from tests.factories import CommentFactory [as 别名]
# 或者: from tests.factories.CommentFactory import build [as 别名]
def test_private_node_non_contributor_cannot_undelete_file_comment(self):
self._set_up_private_project_with_file_comment()
comment = CommentFactory.build(node=self.private_project, target=self.file, user=self.user)
comment.is_deleted = True
comment.save()
url = '/{}comments/{}/'.format(API_BASE, comment._id)
payload = {
'data': {
'id': comment._id,
'type': 'comments',
'attributes': {
'deleted': False
}
}
}
res = self.app.patch_json_api(url, payload, 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.')
示例13: test_private_node_logged_out_user_cannot_undelete_file_comment
# 需要导入模块: from tests.factories import CommentFactory [as 别名]
# 或者: from tests.factories.CommentFactory import build [as 别名]
def test_private_node_logged_out_user_cannot_undelete_file_comment(self):
self._set_up_private_project_with_file_comment()
comment = CommentFactory.build(node=self.private_project, target=self.file.get_guid(), user=self.user)
comment.is_deleted = True
comment.save()
url = '/{}comments/{}/'.format(API_BASE, comment._id)
payload = {
'data': {
'id': comment._id,
'type': 'comments',
'attributes': {
'deleted': False
}
}
}
res = self.app.patch_json_api(url, payload, expect_errors=True)
assert_equal(res.status_code, 401)
assert_equal(res.json['errors'][0]['detail'], 'Authentication credentials were not provided.')
示例14: test_private_node_only_logged_in_contributor_commenter_can_undelete_file_comment
# 需要导入模块: from tests.factories import CommentFactory [as 别名]
# 或者: from tests.factories.CommentFactory import build [as 别名]
def test_private_node_only_logged_in_contributor_commenter_can_undelete_file_comment(self):
self._set_up_private_project_with_file_comment()
comment = CommentFactory.build(node=self.private_project, target=self.file, user=self.user)
comment.is_deleted = True
comment.save()
url = '/{}comments/{}/'.format(API_BASE, comment._id)
payload = {
'data': {
'id': comment._id,
'type': 'comments',
'attributes': {
'deleted': False
}
}
}
res = self.app.patch_json_api(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'], comment.content)
示例15: test_public_node_logged_in_non_contributor_reporter_can_update_report_detail
# 需要导入模块: from tests.factories import CommentFactory [as 别名]
# 或者: from tests.factories.CommentFactory import build [as 别名]
def test_public_node_logged_in_non_contributor_reporter_can_update_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)
payload = {
'data': {
'id': self.non_contributor._id,
'type': 'comment_reports',
'attributes': {
'category': 'spam',
'message': 'Spam is delicious.'
}
}
}
res = self.app.put_json_api(url, payload, auth=self.non_contributor.auth)
assert_equal(res.status_code, 200)
assert_equal(res.json['data']['attributes']['message'], payload['data']['attributes']['message'])