本文整理汇总了Python中tests.factories.CommentFactory.edit方法的典型用法代码示例。如果您正苦于以下问题:Python CommentFactory.edit方法的具体用法?Python CommentFactory.edit怎么用?Python CommentFactory.edit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tests.factories.CommentFactory
的用法示例。
在下文中一共展示了CommentFactory.edit方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_find_unread_includes_edited_comments
# 需要导入模块: from tests.factories import CommentFactory [as 别名]
# 或者: from tests.factories.CommentFactory import edit [as 别名]
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)
示例2: TestCommentFiltering
# 需要导入模块: from tests.factories import CommentFactory [as 别名]
# 或者: from tests.factories.CommentFactory import edit [as 别名]
class TestCommentFiltering(ApiTestCase):
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")
def test_node_comments_with_no_filter_returns_all_comments(self):
res = self.app.get(self.base_url, auth=self.user.auth)
assert_equal(len(res.json["data"]), 2)
def test_filtering_for_deleted_comments(self):
url = self.base_url + "?filter[deleted]=True"
res = self.app.get(url, auth=self.user.auth)
assert_equal(len(res.json["data"]), 1)
assert_true(res.json["data"][0]["attributes"]["deleted"])
def test_filtering_for_non_deleted_comments(self):
url = self.base_url + "?filter[deleted]=False"
res = self.app.get(url, auth=self.user.auth)
assert_equal(len(res.json["data"]), 1)
assert_false(res.json["data"][0]["attributes"]["deleted"])
def test_filtering_comments_created_before_date(self):
url = self.base_url + "?filter[date_created][lt]={}".format(self.formatted_date_created)
res = self.app.get(url, auth=self.user.auth)
assert_equal(len(res.json["data"]), 0)
def test_filtering_comments_created_on_date(self):
url = self.base_url + "?filter[date_created][eq]={}".format(self.formatted_date_created)
res = self.app.get(url, auth=self.user.auth)
assert_equal(len(res.json["data"]), 1)
def test_filtering_comments_created_on_or_before_date(self):
url = self.base_url + "?filter[date_created][lte]={}".format(self.formatted_date_created)
res = self.app.get(url, auth=self.user.auth)
assert_equal(len(res.json["data"]), 1)
def test_filtering_comments_created_after_date(self):
url = self.base_url + "?filter[date_created][gt]={}".format(self.formatted_date_created)
res = self.app.get(url, auth=self.user.auth)
assert_equal(len(res.json["data"]), 1)
def test_filtering_comments_created_on_or_after_date(self):
url = self.base_url + "?filter[date_created][gte]={}".format(self.formatted_date_created)
res = self.app.get(url, auth=self.user.auth)
assert_equal(len(res.json["data"]), 2)
def test_filtering_comments_modified_before_date(self):
url = self.base_url + "?filter[date_modified][lt]={}".format(self.formatted_date_modified)
res = self.app.get(url, auth=self.user.auth)
assert_equal(len(res.json["data"]), 1)
def test_filtering_comments_modified_on_date(self):
url = self.base_url + "?filter[date_modified][eq]={}".format(self.formatted_date_modified)
res = self.app.get(url, auth=self.user.auth)
assert_equal(len(res.json["data"]), 1)
def test_filtering_comments_modified_after_date(self):
url = self.base_url + "?filter[date_modified][gt]={}".format(self.formatted_date_modified)
res = self.app.get(url, auth=self.user.auth)
assert_equal(len(res.json["data"]), 0)
示例3: TestCommentModel
# 需要导入模块: from tests.factories import CommentFactory [as 别名]
# 或者: from tests.factories.CommentFactory import edit [as 别名]
class TestCommentModel(OsfTestCase):
def setUp(self):
super(TestCommentModel, self).setUp()
self.comment = CommentFactory()
self.auth = Auth(user=self.comment.user)
def test_create(self):
comment = Comment.create(
auth=self.auth,
user=self.comment.user,
node=self.comment.node,
target=self.comment.target,
page='node',
is_public=True,
content='This is a comment.'
)
assert_equal(comment.user, self.comment.user)
assert_equal(comment.node, self.comment.node)
assert_equal(comment.target, self.comment.target)
assert_equal(len(comment.node.logs), 2)
assert_equal(comment.node.logs[-1].action, NodeLog.COMMENT_ADDED)
def test_create_comment_content_cannot_exceed_max_length(self):
with assert_raises(ValidationValueError):
comment = Comment.create(
auth=self.auth,
user=self.comment.user,
node=self.comment.node,
target=self.comment.target,
is_public=True,
content=''.join(['c' for c in range(settings.COMMENT_MAXLENGTH + 1)])
)
def test_create_comment_content_cannot_be_none(self):
with assert_raises(ValidationError) as error:
comment = Comment.create(
auth=self.auth,
user=self.comment.user,
node=self.comment.node,
target=self.comment.target,
is_public=True,
content=None
)
assert_equal(error.exception.message, 'Value <content> is required.')
def test_create_comment_content_cannot_be_empty(self):
with assert_raises(ValidationValueError) as error:
comment = Comment.create(
auth=self.auth,
user=self.comment.user,
node=self.comment.node,
target=self.comment.target,
is_public=True,
content=''
)
assert_equal(error.exception.message, 'Value must not be empty.')
def test_create_comment_content_cannot_be_whitespace(self):
with assert_raises(ValidationValueError) as error:
comment = Comment.create(
auth=self.auth,
user=self.comment.user,
node=self.comment.node,
target=self.comment.target,
is_public=True,
content=' '
)
assert_equal(error.exception.message, 'Value must not be empty.')
def test_create_sends_comment_added_signal(self):
with capture_signals() as mock_signals:
comment = Comment.create(
auth=self.auth,
user=self.comment.user,
node=self.comment.node,
target=self.comment.target,
is_public=True,
content='This is a comment.'
)
assert_equal(mock_signals.signals_sent(), set([comment_added]))
def test_edit(self):
self.comment.edit(
auth=self.auth,
content='edited',
save=True
)
assert_equal(self.comment.content, 'edited')
assert_true(self.comment.modified)
assert_equal(len(self.comment.node.logs), 2)
assert_equal(self.comment.node.logs[-1].action, NodeLog.COMMENT_UPDATED)
def test_delete(self):
self.comment.delete(auth=self.auth, save=True)
assert_equal(self.comment.is_deleted, True)
assert_equal(len(self.comment.node.logs), 2)
assert_equal(self.comment.node.logs[-1].action, NodeLog.COMMENT_REMOVED)
def test_undelete(self):
#.........这里部分代码省略.........
示例4: TestCommentFiltering
# 需要导入模块: from tests.factories import CommentFactory [as 别名]
# 或者: from tests.factories.CommentFactory import edit [as 别名]
class TestCommentFiltering(ApiTestCase):
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')
def test_node_comments_with_no_filter_returns_all_comments(self):
res = self.app.get(self.base_url, auth=self.user.auth)
assert_equal(len(res.json['data']), 2)
def test_filtering_for_deleted_comments(self):
url = self.base_url + '?filter[deleted]=True'
res = self.app.get(url, auth=self.user.auth)
assert_equal(len(res.json['data']), 1)
assert_true(res.json['data'][0]['attributes']['deleted'])
def test_filtering_for_non_deleted_comments(self):
url = self.base_url + '?filter[deleted]=False'
res = self.app.get(url, auth=self.user.auth)
assert_equal(len(res.json['data']), 1)
assert_false(res.json['data'][0]['attributes']['deleted'])
def test_filtering_comments_created_before_date(self):
url = self.base_url + '?filter[date_created][lt]={}'.format(self.formatted_date_created)
res = self.app.get(url, auth=self.user.auth)
assert_equal(len(res.json['data']), 0)
def test_filtering_comments_created_on_date(self):
url = self.base_url + '?filter[date_created][eq]={}'.format(self.formatted_date_created)
res = self.app.get(url, auth=self.user.auth)
assert_equal(len(res.json['data']), 1)
def test_filtering_comments_created_on_or_before_date(self):
url = self.base_url + '?filter[date_created][lte]={}'.format(self.formatted_date_created)
res = self.app.get(url, auth=self.user.auth)
assert_equal(len(res.json['data']), 1)
def test_filtering_comments_created_after_date(self):
url = self.base_url + '?filter[date_created][gt]={}'.format(self.formatted_date_created)
res = self.app.get(url, auth=self.user.auth)
assert_equal(len(res.json['data']), 1)
def test_filtering_comments_created_on_or_after_date(self):
url = self.base_url + '?filter[date_created][gte]={}'.format(self.formatted_date_created)
res = self.app.get(url, auth=self.user.auth)
assert_equal(len(res.json['data']), 2)
def test_filtering_comments_modified_before_date(self):
url = self.base_url + '?filter[date_modified][lt]={}'.format(self.formatted_date_modified)
res = self.app.get(url, auth=self.user.auth)
assert_equal(len(res.json['data']), 1)
def test_filtering_comments_modified_on_date(self):
url = self.base_url + '?filter[date_modified][eq]={}'.format(self.formatted_date_modified)
res = self.app.get(url, auth=self.user.auth)
assert_equal(len(res.json['data']), 1)
def test_filtering_comments_modified_after_date(self):
url = self.base_url + '?filter[date_modified][gt]={}'.format(self.formatted_date_modified)
res = self.app.get(url, auth=self.user.auth)
assert_equal(len(res.json['data']), 0)
def test_filtering_by_target(self):
url = self.base_url + '?filter[target]=' + str(self.project._id)
res = self.app.get(url, auth=self.user.auth)
assert_equal(len(res.json['data']), 2)
assert_in(self.project._id, res.json['data'][0]['relationships']['target']['links']['related']['href'])
def test_filtering_by_target_no_results(self):
url = self.base_url + '?filter[target]=' + 'fakeid'
res = self.app.get(url, auth=self.user.auth)
assert_equal(len(res.json['data']), 0)
示例5: TestCommentModel
# 需要导入模块: from tests.factories import CommentFactory [as 别名]
# 或者: from tests.factories.CommentFactory import edit [as 别名]
#.........这里部分代码省略.........
assert_equal(error.exception.message, "User does not exist or is not active.")
def test_create_does_not_send_mention_added_signal_if_noncontributor_mentioned(self):
with assert_raises(ValidationValueError) as error:
with capture_signals() as mock_signals:
user = UserFactory()
comment = Comment.create(
auth=self.auth,
user=self.comment.user,
node=self.comment.node,
target=self.comment.target,
is_public=True,
content="This is a comment with a bad mention [@Non-contributor User](http://localhost:5000/"
+ user._id
+ "/).",
)
assert_equal(mock_signals.signals_sent(), set([]))
assert_equal(error.exception.message, "Mentioned user is not a contributor.")
def test_create_does_not_send_mention_added_signal_if_nonuser_mentioned(self):
with assert_raises(ValidationValueError) as error:
with capture_signals() as mock_signals:
comment = Comment.create(
auth=self.auth,
user=self.comment.user,
node=self.comment.node,
target=self.comment.target,
is_public=True,
content="This is a comment with a bad mention [@Not a User](http://localhost:5000/qwert/).",
)
assert_equal(mock_signals.signals_sent(), set([]))
assert_equal(error.exception.message, "User does not exist or is not active.")
def test_edit(self):
self.comment.edit(auth=self.auth, content="edited", save=True)
assert_equal(self.comment.content, "edited")
assert_true(self.comment.modified)
assert_equal(len(self.comment.node.logs), 2)
assert_equal(self.comment.node.logs[-1].action, NodeLog.COMMENT_UPDATED)
def test_edit_sends_mention_added_signal_if_mentions(self):
with capture_signals() as mock_signals:
self.comment.edit(
auth=self.auth,
content="This is a comment with a bad mention [@Mentioned User](http://localhost:5000/"
+ self.comment.user._id
+ "/).",
save=True,
)
assert_equal(mock_signals.signals_sent(), set([mention_added]))
def test_edit_does_not_send_mention_added_signal_if_nonuser_mentioned(self):
with assert_raises(ValidationValueError) as error:
with capture_signals() as mock_signals:
self.comment.edit(
auth=self.auth,
content="This is a comment with a bad mention [@Not a User](http://localhost:5000/qwert/).",
save=True,
)
assert_equal(mock_signals.signals_sent(), set([]))
assert_equal(error.exception.message, "User does not exist or is not active.")
def test_edit_does_not_send_mention_added_signal_if_noncontributor_mentioned(self):
with assert_raises(ValidationValueError) as error:
with capture_signals() as mock_signals:
user = UserFactory()
示例6: TestCommentRepliesFiltering
# 需要导入模块: from tests.factories import CommentFactory [as 别名]
# 或者: from tests.factories.CommentFactory import edit [as 别名]
class TestCommentRepliesFiltering(ApiTestCase):
def setUp(self):
super(TestCommentRepliesFiltering, self).setUp()
self.user = AuthUserFactory()
self.project = ProjectFactory(creator=self.user)
self.comment = CommentFactory(node=self.project, user=self.user)
self.reply = CommentFactory(node=self.project, target=self.comment, user=self.user)
self.deleted_reply = CommentFactory(node=self.project, target=self.comment, user=self.user, is_deleted=True)
self.base_url = '/{}comments/{}/replies/'.format(API_BASE, self.comment._id)
self.formatted_date_created = self.reply.date_created.strftime('%Y-%m-%dT%H:%M:%S.%f')
self.reply.edit('Edited comment', auth=core.Auth(self.user), save=True)
self.formatted_date_modified = self.reply.date_modified.strftime('%Y-%m-%dT%H:%M:%S.%f')
def test_node_comments_replies_with_no_filter_returns_all(self):
res = self.app.get(self.base_url, auth=self.user.auth)
assert_equal(len(res.json['data']), 2)
def test_filtering_for_deleted_comment_replies(self):
url = self.base_url + '?filter[deleted]=True'
res = self.app.get(url, auth=self.user.auth)
assert_equal(len(res.json['data']), 1)
assert_true(res.json['data'][0]['attributes']['deleted'])
def test_filtering_for_non_deleted_comment_replies(self):
url = self.base_url + '?filter[deleted]=False'
res = self.app.get(url, auth=self.user.auth)
assert_equal(len(res.json['data']), 1)
assert_false(res.json['data'][0]['attributes']['deleted'])
def test_filtering_comments_replies_created_before_date(self):
url = self.base_url + '?filter[date_created][lt]={}'.format(self.formatted_date_created)
res = self.app.get(url, auth=self.user.auth)
assert_equal(len(res.json['data']), 0)
def test_filtering_comment_replies_created_on_datetime(self):
url = self.base_url + '?filter[date_created][eq]={}'.format(self.formatted_date_created)
res = self.app.get(url, auth=self.user.auth)
assert_equal(len(res.json['data']), 1)
def test_filtering_comment_replies_created_on_date(self):
url = self.base_url + '?filter[date_created][eq]={}'.format(self.reply.date_created.strftime('%Y-%m-%d'))
res = self.app.get(url, auth=self.user.auth)
assert_equal(len(res.json['data']), 2)
def test_filtering_comment_replies_created_after_date(self):
url = self.base_url + '?filter[date_created][gt]={}'.format(self.formatted_date_created)
res = self.app.get(url, auth=self.user.auth)
assert_equal(len(res.json['data']), 1)
def test_filtering_comment_replies_modified_before_date(self):
url = self.base_url + '?filter[date_modified][lt]={}'.format(self.formatted_date_modified)
res = self.app.get(url, auth=self.user.auth)
assert_equal(len(res.json['data']), 1)
def test_filtering_comment_replies_modified_on_date(self):
url = self.base_url + '?filter[date_modified][eq]={}'.format(self.formatted_date_modified)
res = self.app.get(url, auth=self.user.auth)
assert_equal(len(res.json['data']), 1)
def test_filtering_comment_replies_modified_after_date(self):
url = self.base_url + '?filter[date_modified][gt]={}'.format(self.formatted_date_modified)
res = self.app.get(url, auth=self.user.auth)
assert_equal(len(res.json['data']), 0)