def _set_up_public_project_comment_reply(self): self.public_project = ProjectFactory(is_public=True, creator=self.user) self.public_comment = CommentFactory(node=self.public_project, user=self.user) self.public_comment_reply = CommentFactory(node=self.public_project, target=self.public_comment, user=self.user) self.public_url = '/{}comments/{}/replies/'.format( API_BASE, self.public_comment._id)
def test_find_unread_includes_comment_replies(self): project = ProjectFactory() user = UserFactory() project.add_contributor(user) project.save() comment = CommentFactory(node=project, user=user) reply = CommentFactory(node=project, target=Guid.load(comment._id), user=project.creator) n_unread = Comment.find_n_unread(user=user, node=project, page='node') assert_equal(n_unread, 1)
def _set_up_registration_comment_reply(self): self.registration = RegistrationFactory(creator=self.user) self.registration_comment = CommentFactory(node=self.registration, user=self.user) self.registration_comment_reply = CommentFactory( node=self.registration, target=self.registration_comment, user=self.user) self.registration_url = '/{}comments/{}/replies/'.format( API_BASE, self.registration_comment._id)
def _set_up_registration_with_comment(self): self.registration = RegistrationFactory(creator=self.user) self.registration_url = '/{}registrations/{}/'.format( API_BASE, self.registration._id) self.registration_comment = CommentFactory(node=self.registration, user=self.user) self.comment_url = '/{}comments/{}/'.format( API_BASE, self.registration_comment._id) reply_target = Guid.load(self.registration_comment._id) self.registration_comment_reply = CommentFactory( node=self.registration, target=reply_target, user=self.user) self.replies_url = '/{}registrations/{}/comments/?filter[target]={}'.format( API_BASE, self.registration._id, self.registration_comment._id)
def _set_up_public_project_with_comment(self): self.public_project = ProjectFactory.create(is_public=True, creator=self.user) self.public_project.add_contributor(self.contributor, save=True) self.public_comment = CommentFactory(node=self.public_project, user=self.user) reply_target = Guid.load(self.public_comment._id) self.public_comment_reply = CommentFactory(node=self.public_project, target=reply_target, 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)
def _set_up_registration_with_comment(self): self.registration = RegistrationFactory(creator=self.user, comment_level='private') self.registration_wiki = NodeWikiFactory(node=self.registration, user=self.user) self.registration_comment = CommentFactory( node=self.registration, target=Guid.load(self.registration_wiki._id), user=self.user) self.comment_url = '/{}comments/{}/'.format( API_BASE, self.registration_comment._id) reply_target = Guid.load(self.registration_comment._id) self.registration_comment_reply = CommentFactory( node=self.registration, target=reply_target, user=self.user)
def _set_up_registration_with_comment(self): self.registration = RegistrationFactory(creator=self.user, comment_level='private') self.registration_file = test_utils.create_test_file( self.registration, self.user) self.registration_comment = CommentFactory( node=self.registration, target=self.registration_file.get_guid(), user=self.user) self.comment_url = '/{}comments/{}/'.format( API_BASE, self.registration_comment._id) reply_target = Guid.load(self.registration_comment._id) self.registration_comment_reply = CommentFactory( node=self.registration, target=reply_target, user=self.user)
def _set_up_public_project_with_public_comment_level(self): self.public_project_with_public_comment_level = ProjectFactory( is_public=True, creator=self.user, comment_level='public') self.public_project_with_public_comment_level.add_contributor( self.read_only_contributor, permissions=['read'], save=True) comment = CommentFactory( node=self.public_project_with_public_comment_level, user=self.user) reply = CommentFactory( node=self.public_project_with_public_comment_level, target=comment, user=self.user) self.public_project_with_public_comment_level_url = '/{}nodes/{}/comments/'.format( API_BASE, self.public_project_with_public_comment_level._id) self.public_project_with_public_comment_level_payload = self._set_up_payload( reply._id)
def test_public_node_non_contributor_commenter_can_delete_wiki_comment(self): project = ProjectFactory(is_public=True, comment_level='public') test_wiki = NodeWikiFactory(node=project, user=self.user) comment = CommentFactory(node=project, target=Guid.load(test_wiki), user=self.non_contributor) url = '/{}comments/{}/'.format(API_BASE, comment._id) res = self.app.delete_json_api(url, auth=self.non_contributor.auth) assert_equal(res.status_code, 204)
def _set_up_private_project_with_comment(self): self.private_project = ProjectFactory.create(is_public=False, creator=self.user, comment_level='private') self.private_project.add_contributor(self.contributor, save=True) self.wiki = NodeWikiFactory(node=self.private_project, user=self.user) self.comment = CommentFactory(node=self.private_project, target=Guid.load(self.wiki._id), user=self.user) self.private_url = '/{}comments/{}/'.format(API_BASE, self.comment._id) self.payload = self._set_up_payload(self.comment._id)
def test_public_node_non_contributor_commenter_can_delete_file_comment(self): project = ProjectFactory(is_public=True, comment_level='public') test_file = test_utils.create_test_file(project, project.creator) comment = CommentFactory(node=project, target=test_file.get_guid(), user=self.non_contributor) url = '/{}comments/{}/'.format(API_BASE, comment._id) res = self.app.delete_json_api(url, auth=self.non_contributor.auth) assert_equal(res.status_code, 204)
def _set_up_public_project_with_comment(self): self.public_project = ProjectFactory.create(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.get_guid(), 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)
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_update_default_modified_updates_all_targets(self): comment = CommentFactory(modified=None) targets = get_targets() assert_equal(targets.count(), 1) do_migration(get_targets()) assert_equal(targets.count(), 0)
def test_private_node_logged_in_contributor_can_report_comment(self): self._set_up_private_project_comment_reports() comment = CommentFactory(node=self.private_project, user=self.contributor) url = '/{}comments/{}/reports/'.format(API_BASE, comment._id) res = self.app.post_json_api(url, self.payload, auth=self.user.auth) assert_equal(res.status_code, 201) assert_equal(res.json['data']['id'], self.user._id)
def test_redirect_to_comment_view(self): comment = CommentFactory() url = '/{}guids/{}/'.format(API_BASE, comment._id) res = self.app.get(url, auth=self.user.auth) redirect_url = '{}{}comments/{}/'.format(API_DOMAIN, API_BASE, comment._id) assert_equal(res.status_code, 302) assert_equal(res.location, redirect_url)
def _set_up_private_project_with_comment(self): self.private_project = ProjectFactory(is_public=False, creator=self.user) self.comment = CommentFactory(node=self.private_project, user=self.user) self.private_url = '/{}nodes/{}/comments/'.format( API_BASE, self.private_project._id)
def test_cannot_access_withdrawn_comments(self): self.public_project = ProjectFactory(is_public=True, creator=self.user) self.public_comment = CommentFactory(node=self.public_project, user=self.user) url = '/{}registrations/{}/comments/'.format(API_BASE, self.registration._id) res = self.app.get(url, auth=self.user.auth, expect_errors=True) assert_equal(res.status_code, 403)
def test_public_node_non_contributor_commenter_can_update_comment(self): project = ProjectFactory(is_public=True, comment_level='public') comment = CommentFactory(node=project, user=self.non_contributor) url = '/{}comments/{}/'.format(API_BASE, comment._id) payload = self._set_up_payload(comment._id) res = self.app.put_json_api(url, payload, auth=self.non_contributor.auth) assert_equal(res.status_code, 200) assert_equal(payload['data']['attributes']['content'], res.json['data']['attributes']['content'])
def test_find_unread_does_not_include_deleted_comments(self): project = ProjectFactory() user = AuthUserFactory() project.add_contributor(user) project.save() comment = CommentFactory(node=project, user=project.creator, is_deleted=True) n_unread = Comment.find_n_unread(user=user, node=project, page='node') assert_equal(n_unread, 0)
def test_file_has_correct_unread_comments_count(self): contributor = AuthUserFactory() self.node.add_contributor(contributor, auth=Auth(self.user), save=True) comment = CommentFactory(node=self.node, target=self.file.get_guid(), user=contributor, page='files') res = self.app.get('/{}files/{}/?related_counts=True'.format(API_BASE, self.file._id), auth=self.user.auth) assert_equal(res.status_code, 200) unread_comments = res.json['data']['relationships']['comments']['links']['related']['meta']['unread'] assert_equal(unread_comments, 1)
def test_node_has_correct_unread_comments_count(self): contributor = AuthUserFactory() self.public_project.add_contributor(contributor=contributor, auth=Auth(self.user), save=True) comment = CommentFactory(node=self.public_project, user=contributor, page='node') res = self.app.get(self.public_url + '?related_counts=True', auth=self.user.auth) unread = res.json['data']['relationships']['comments']['links']['related']['meta']['unread'] unread_comments_node = unread['node'] assert_equal(unread_comments_node, 1)
def test_find_unread_new_comments(self): project = ProjectFactory() user = UserFactory() project.add_contributor(user) project.save() comment = CommentFactory(node=project, user=project.creator) n_unread = Comment.find_n_unread(user=user, node=project) assert_equal(n_unread, 1)
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)
def test_public_node_non_contributor_commenter_can_update_file_comment(self): project = ProjectFactory(is_public=True) test_file = test_utils.create_test_file(project, project.creator) comment = CommentFactory(node=project, target=test_file.get_guid(), user=self.non_contributor) url = '/{}comments/{}/'.format(API_BASE, comment._id) payload = self._set_up_payload(comment._id) res = self.app.put_json_api(url, payload, auth=self.non_contributor.auth) assert_equal(res.status_code, 200) assert_equal(payload['data']['attributes']['content'], res.json['data']['attributes']['content'])
def test_redirect_when_viewing_private_project_comment_through_view_only_link(self): project = ProjectFactory() view_only_link = self._add_private_link(project) comment = CommentFactory(node=project) url = '/{}guids/{}/?view_only={}'.format(API_BASE, comment._id, view_only_link.key) res = self.app.get(url, auth=AuthUserFactory().auth) redirect_url = '{}{}comments/{}/?view_only={}'.format(API_DOMAIN, API_BASE, comment._id, view_only_link.key) assert_equal(res.status_code, 302) assert_equal(res.location, redirect_url)
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_private_node_contributor_cannot_see_other_users_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.contributor.auth) assert_equal(res.status_code, 200) assert_is_none(res.json['data']['attributes']['content'])
def test_public_node_logged_out_user_cannot_view_deleted_comments(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) assert_equal(res.status_code, 200) assert_is_none(res.json['data']['attributes']['content'])
def test_return_both_deleted_and_undeleted_comments(self): self._set_up_private_project_with_comment() deleted_comment = CommentFactory(node=self.private_project, user=self.user) res = self.app.get(self.private_url, auth=self.user.auth) assert_equal(res.status_code, 200) comment_json = res.json['data'] comment_ids = [comment['id'] for comment in comment_json] assert_in(self.comment._id, comment_ids) assert_in(deleted_comment._id, comment_ids)