本文整理汇总了Python中osf.models.Comment类的典型用法代码示例。如果您正苦于以下问题:Python Comment类的具体用法?Python Comment怎么用?Python Comment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Comment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_create_comment_content_does_not_exceed_max_length_complex
def test_create_comment_content_does_not_exceed_max_length_complex(self, node, user, auth):
Comment.create(
auth=auth,
user=user,
node=node,
target=node.guids.all()[0],
content=''.join(['c' for c in range(settings.COMMENT_MAXLENGTH - 12)]) + '[@George Ant](http://localhost:5000/' + user._id + '/)'
)
示例2: test_create_comment_content_cannot_exceed_max_length_simple
def test_create_comment_content_cannot_exceed_max_length_simple(self, node, user, auth):
with pytest.raises(ValidationError):
Comment.create(
auth=auth,
user=user,
node=node,
target=node.guids.all()[0],
content=''.join(['c' for c in range(settings.COMMENT_MAXLENGTH + 3)])
)
示例3: test_create_sends_comment_added_signal
def test_create_sends_comment_added_signal(self, node, user, auth):
with capture_signals() as mock_signals:
Comment.create(
auth=auth,
user=user,
node=node,
target=node.guids.all()[0],
content='This is a comment.'
)
assert mock_signals.signals_sent() == ({comment_added})
示例4: test_create_comment_content_cannot_be_whitespace
def test_create_comment_content_cannot_be_whitespace(self, node, user, auth):
with pytest.raises(ValidationError) as error:
Comment.create(
auth=auth,
user=user,
node=node,
target=node.guids.all()[0],
content=' '
)
assert error.value.messages[0] == 'Value must not be empty.'
示例5: test_create_sends_mention_added_signal_if_mentions
def test_create_sends_mention_added_signal_if_mentions(self, node, user, auth):
with capture_signals() as mock_signals:
Comment.create(
auth=auth,
user=user,
node=node,
target=node.guids.all()[0],
content='This is a comment with a bad mention [@Unconfirmed User](http://localhost:5000/' + user._id + '/).'
)
assert mock_signals.signals_sent() == ({comment_added, mention_added})
示例6: test_create_comment_content_cannot_be_empty
def test_create_comment_content_cannot_be_empty(self, node, user, auth):
with pytest.raises(ValidationError) as error:
Comment.create(
auth=auth,
user=user,
node=node,
target=node.guids.all()[0],
content=''
)
assert error.value.messages[0] == 'This field cannot be blank.'
示例7: setUp
def setUp(self):
super(TestSpamListView, self).setUp()
Comment.remove()
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)
示例8: test_create_does_not_send_mention_added_signal_if_nonuser_mentioned
def test_create_does_not_send_mention_added_signal_if_nonuser_mentioned(self, node, user, auth):
with pytest.raises(ValidationError) as error:
with capture_signals() as mock_signals:
Comment.create(
auth=auth,
user=user,
node=node,
target=node.guids.all()[0],
content='This is a comment with a bad mention [@Not a User](http://localhost:5000/qwert/).'
)
assert mock_signals.signals_sent() == set([])
assert error.value.message == 'User does not exist or is not active.'
示例9: test_create_does_not_send_mention_added_signal_if_noncontributor_mentioned
def test_create_does_not_send_mention_added_signal_if_noncontributor_mentioned(self, node, user, auth):
with pytest.raises(ValidationError) as error:
with capture_signals() as mock_signals:
user = UserFactory()
Comment.create(
auth=auth,
user=user,
node=node,
target=node.guids.all()[0],
content='This is a comment with a bad mention [@Non-contributor User](http://localhost:5000/' + user._id + '/).'
)
assert mock_signals.signals_sent() == set([])
assert error.value.message == 'Mentioned user is not a contributor.'
示例10: test_comments_move_when_file_moved_to_osfstorage
def test_comments_move_when_file_moved_to_osfstorage(self, project, user):
osfstorage = project.get_addon('osfstorage')
root_node = osfstorage.get_root()
osf_file = root_node.append_file('file.txt')
osf_file.create_version(user, {
'object': '06d80e',
'service': 'cloud',
osfstorage_settings.WATERBUTLER_RESOURCE: 'osf',
}, {
'size': 1337,
'contentType': 'img/png',
'etag': 'abcdefghijklmnop'
}).save()
source = {
'path': '/file.txt',
'node': project,
'provider': self.provider
}
destination = {
'path': osf_file.path,
'node': project,
'provider': 'osfstorage'
}
self._create_file_with_comment(node=source['node'], path=source['path'], user=user)
payload = self._create_payload('move', user, source, destination, self.file._id, destination_file_id=destination['path'].strip('/'))
update_file_guid_referent(self=None, node=destination['node'], event_type='addon_file_moved', payload=payload)
self.guid.reload()
file_node = BaseFileNode.resolve_class('osfstorage', BaseFileNode.FILE).get_or_create(destination['node'], destination['path'])
assert self.guid._id == file_node.get_guid()._id
file_comments = Comment.find(Q('root_target', 'eq', self.guid.pk))
assert file_comments.count() == 1
示例11: get_unread_comments_count
def get_unread_comments_count(self, obj):
user = get_user_auth(self.context['request']).user
node_comments = Comment.find_n_unread(user=user, node=obj, page='node')
return {
'node': node_comments
}
示例12: test_find_unread_new_comments
def test_find_unread_new_comments(self):
project = ProjectFactory()
user = UserFactory()
project.add_contributor(user, save=True)
CommentFactory(node=project, user=project.creator)
n_unread = Comment.find_n_unread(user=user, node=project, page='node')
assert n_unread == 1
示例13: test_create_does_not_send_mention_added_signal_if_unconfirmed_contributor_mentioned
def test_create_does_not_send_mention_added_signal_if_unconfirmed_contributor_mentioned(self, node, user, auth):
with pytest.raises(ValidationError) as error:
with capture_signals() as mock_signals:
user = UnregUserFactory()
user.save()
node.add_unregistered_contributor(user.fullname, user.email, Auth(node.creator), permissions=[permissions.READ], save=True)
Comment.create(
auth=auth,
user=user,
node=node,
target=node.guids.all()[0],
content='This is a comment with a bad mention [@Unconfirmed User](http://localhost:5000/' + user._id + '/).'
)
assert mock_signals.signals_sent() == ({contributor_added})
assert error.value.message == 'User does not exist or is not active.'
示例14: get_paginated_response
def get_paginated_response(self, data):
"""Add number of unread comments to links.meta when viewing list of comments filtered by
a target node, file or wiki page."""
response = super(CommentPagination, self).get_paginated_response(data)
response_dict = response.data
kwargs = self.request.parser_context['kwargs'].copy()
if self.request.query_params.get('related_counts', False):
target_id = self.request.query_params.get('filter[target]', None)
node_id = kwargs.get('node_id', None)
node = Node.load(node_id)
user = self.request.user
if target_id and not user.is_anonymous and node.is_contributor(user):
root_target = Guid.load(target_id)
if root_target:
page = getattr(root_target.referent, 'root_target_page', None)
if page:
if not len(data):
unread = 0
else:
unread = Comment.find_n_unread(user=user, node=node, page=page, root_id=target_id)
if self.request.version < '2.1':
response_dict['links']['meta']['unread'] = unread
else:
response_dict['meta']['unread'] = unread
return Response(response_dict)
示例15: update_file_guid_referent
def update_file_guid_referent(self, node, event_type, payload, user=None):
if event_type not in ('addon_file_moved', 'addon_file_renamed'):
return # Nothing to do
source, destination = payload['source'], payload['destination']
source_node, destination_node = Node.load(source['node']['_id']), Node.load(destination['node']['_id'])
if source['provider'] in settings.ADDONS_BASED_ON_IDS:
if event_type == 'addon_file_renamed':
return # Node has not changed and provider has not changed
# Must be a move
if source['provider'] == destination['provider'] and source_node == destination_node:
return # Node has not changed and provider has not changed
file_guids = BaseFileNode.resolve_class(source['provider'], BaseFileNode.ANY).get_file_guids(
materialized_path=source['materialized'] if source['provider'] != 'osfstorage' else source['path'],
provider=source['provider'],
node=source_node
)
for guid in file_guids:
obj = Guid.load(guid)
if source_node != destination_node and Comment.find(Q('root_target._id', 'eq', guid)).count() != 0:
update_comment_node(guid, source_node, destination_node)
if source['provider'] != destination['provider'] or source['provider'] != 'osfstorage':
old_file = BaseFileNode.load(obj.referent._id)
obj.referent = create_new_file(obj, source, destination, destination_node)
obj.save()
if old_file and not TrashedFileNode.load(old_file._id):
old_file.delete()