def test_clear_as_user(self): owner = factories.User() org = factories.Organization(user=owner) dataset = factories.Dataset(owner_org=org['name']) issue = issue_factories.Issue(user_id=owner['id'], dataset_id=dataset['id']) comment = issue_factories.IssueComment(user_id=owner['id'], dataset_id=dataset['id'], issue_number=issue['number']) user = factories.User() model.Session.add( IssueComment.Report(user['id'], parent_id=comment['id'])) model.Session.commit() context = { 'user': user['name'], 'model': model, } helpers.call_action('issue_comment_report_clear', context=context, dataset_id=dataset['id'], issue_number=issue['number'], comment_id=comment['id']) comment_obj = IssueComment.get(comment['id']) assert_equals(len(comment_obj.abuse_reports), 0) assert_equals('visible', comment_obj.visibility)
def setup(self): # Organization 1 self.organization = factories.Organization() dataset = factories.Dataset(owner_org=self.organization['id']) issue = issue_factories.Issue(dataset_id=dataset['id']) self.comment1 = issue_factories.IssueComment( issue_number=issue['number'], dataset_id=issue['dataset_id'], ) comment_object = IssueComment.get(self.comment1['id']) comment_object.change_visibility(model.Session, u'hidden') self.comment2 = issue_factories.IssueComment( # unreported comment issue_number=issue['number'], dataset_id=issue['dataset_id'], ) # Organization 2 self.organization2 = factories.Organization() dataset2 = factories.Dataset(owner_org=self.organization2['id']) issue2 = issue_factories.Issue(dataset_id=dataset2['id']) self.comment3 = issue_factories.IssueComment( issue_number=issue2['number'], dataset_id=issue2['dataset_id'], ) comment_object = IssueComment.get(self.comment3['id']) comment_object.change_visibility(model.Session, u'hidden') self.comment4 = issue_factories.IssueComment( # unreported comment issue_number=issue2['number'], dataset_id=issue2['dataset_id'], )
def test_clear_as_publisher(self): owner = factories.User() org = factories.Organization(user=owner) dataset = factories.Dataset(owner_org=org['name']) issue = issue_factories.Issue(user_id=owner['id'], dataset_id=dataset['id']) comment = issue_factories.IssueComment(user_id=owner['id'], dataset_id=dataset['id'], issue_number=issue['number'], visibility='hidden') context = { 'user': owner['name'], 'model': model, } model.Session.add( IssueComment.Report(owner['id'], parent_id=comment['id'])) model.Session.commit() helpers.call_action('issue_comment_report_clear', context=context, dataset_id=dataset['id'], issue_number=issue['number'], comment_id=comment['id']) result = helpers.call_action('issue_show', issue_number=issue['number'], dataset_id=dataset['id']) assert_equals('visible', result['comments'][0]['visibility']) comment_obj = IssueComment.get(comment['id']) model.Session.refresh(comment_obj) assert_equals(len(comment_obj.abuse_reports), 0)
def test_max_strikes_hides_comment(self): owner = factories.User() org = factories.Organization(user=owner) dataset = factories.Dataset(owner_org=org['name']) issue = issue_factories.Issue(user_id=owner['id'], dataset_id=dataset['id']) comment = issue_factories.IssueComment(user_id=owner['id'], dataset_id=dataset['id'], issue_number=issue['number']) user = factories.User(name='unauthed') context = { 'user': user['name'], 'model': model, } helpers.call_action('issue_comment_report', context=context, dataset_id=dataset['id'], issue_number=issue['number'], comment_id=comment['id']) result = helpers.call_action('issue_show', dataset_id=dataset['id'], issue_number=issue['number']) comment_obj = IssueComment.get(comment['id']) assert_equals(len(comment_obj.abuse_reports), 1) assert_equals('hidden', result['comments'][0]['visibility'])
def test_clear_as_publisher(self): owner = factories.User() org = factories.Organization(user=owner) dataset = factories.Dataset(owner_org=org['name']) issue = issue_factories.Issue(user_id=owner['id'], dataset_id=dataset['id']) comment = issue_factories.IssueComment(user_id=owner['id'], dataset_id=dataset['id'], issue_number=issue['number'], visibility='hidden') context = { 'user': owner['name'], 'model': model, } model.Session.add(IssueComment.Report(owner['id'], parent_id=comment['id'])) model.Session.commit() helpers.call_action('issue_comment_report_clear', context=context, dataset_id=dataset['id'], issue_number=issue['number'], comment_id=comment['id']) result = helpers.call_action('issue_show', issue_number=issue['number'], dataset_id=dataset['id']) assert_equals('visible', result['comments'][0]['visibility']) comment_obj = IssueComment.get(comment['id']) model.Session.refresh(comment_obj) assert_equals(len(comment_obj.abuse_reports), 0)
def test_clear_as_user(self): owner = factories.User() org = factories.Organization(user=owner) dataset = factories.Dataset(owner_org=org['name']) issue = issue_factories.Issue(user_id=owner['id'], dataset_id=dataset['id']) comment = issue_factories.IssueComment(user_id=owner['id'], dataset_id=dataset['id'], issue_number=issue['number']) user = factories.User() model.Session.add(IssueComment.Report(user['id'], parent_id=comment['id'])) model.Session.commit() context = { 'user': user['name'], 'model': model, } helpers.call_action('issue_comment_report_clear', context=context, dataset_id=dataset['id'], issue_number=issue['number'], comment_id=comment['id']) comment_obj = IssueComment.get(comment['id']) assert_equals(len(comment_obj.abuse_reports), 0) assert_equals('visible', comment_obj.visibility)
def comment3(self, issue): comment3 = issue_factories.IssueComment( issue_number=issue['number'], dataset_id=issue['dataset_id'], ) comment_object = IssueComment.get(comment3['id']) comment_object.change_visibility(model.Session, u'hidden') return comment3
def test_clear_as_user(self, owner, org, dataset, issue): comment = issue_factories.IssueComment(user_id=owner['id'], dataset_id=dataset['id'], issue_number=issue['number']) user = factories.User() model.Session.add(IssueComment.Report(user['id'], parent_id=comment['id'])) model.Session.commit() context = { 'user': user['name'], 'model': model, } helpers.call_action('issue_comment_report_clear', context=context, dataset_id=dataset['id'], issue_number=issue['number'], comment_id=comment['id']) comment_obj = IssueComment.get(comment['id']) assert len(comment_obj.abuse_reports) == 0 assert 'visible' == comment_obj.visibility
def test_report_clear_state_normal_user(self, app, dataset, issue, comment): user = factories.User() model.Session.add(IssueComment.Report(user['id'], comment['id'])) model.Session.commit() env = {'REMOTE_USER': user['name'].encode('ascii')} response = app.post( url=toolkit.url_for('issues.comment_report_clear', dataset_id=dataset['id'], issue_number=issue['number'], comment_id=comment['id']), extra_environ=env, ) assert 'Spam/abuse report cleared' in response.body
def test_report_clear_state_normal_user(self): user = factories.User() model.Session.add(IssueComment.Report(user['id'], self.comment['id'])) model.Session.commit() env = {'REMOTE_USER': user['name'].encode('ascii')} response = self.app.post( url=toolkit.url_for('issues_comment_report_clear', dataset_id=self.dataset['id'], issue_number=self.issue['number'], comment_id=self.comment['id']), extra_environ=env, ) response = response.follow() assert_in('Spam/abuse report cleared', response.body)
def test_clear_as_publisher(self, owner, org, dataset, issue): comment = issue_factories.IssueComment(user_id=owner['id'], dataset_id=dataset['id'], issue_number=issue['number'], visibility='hidden') context = { 'user': owner['name'], 'model': model, } model.Session.add(IssueComment.Report(owner['id'], parent_id=comment['id'])) model.Session.commit() helpers.call_action('issue_comment_report_clear', context=context, dataset_id=dataset['id'], issue_number=issue['number'], comment_id=comment['id']) result = helpers.call_action('issue_show', issue_number=issue['number'], dataset_id=dataset['id']) assert 'visible' == result['comments'][0]['visibility'] comment_obj = IssueComment.get(comment['id']) model.Session.refresh(comment_obj) assert len(comment_obj.abuse_reports) == 0
def test_report_comment(self, owner, dataset, issue): comment = issue_factories.IssueComment(user_id=owner['id'], dataset_id=dataset['id'], issue_number=issue['number']) user = factories.User(name='unauthed') context = { 'user': user['name'], 'model': model, } helpers.call_action('issue_comment_report', context=context, dataset_id=dataset['id'], issue_number=issue['number'], comment_id=comment['id']) comment_obj = IssueComment.get(comment['id']) assert len(comment_obj.abuse_reports) == 1 assert comment_obj.visibility == 'visible'
def test_max_strikes_hides_comment(self, owner, org, dataset, issue): comment = issue_factories.IssueComment(user_id=owner['id'], dataset_id=dataset['id'], issue_number=issue['number']) user = factories.User(name='unauthed') context = { 'user': user['name'], 'model': model, } helpers.call_action('issue_comment_report', context=context, dataset_id=dataset['id'], issue_number=issue['number'], comment_id=comment['id']) result = helpers.call_action('issue_show', dataset_id=dataset['id'], issue_number=issue['number']) comment_obj = IssueComment.get(comment['id']) assert len(comment_obj.abuse_reports) == 1 assert 'hidden' == result['comments'][0]['visibility']
def test_search(self): organization = factories.Organization() dataset = factories.Dataset(owner_org=organization['id']) issue = issue_factories.Issue(dataset_id=dataset['id']) comment = issue_factories.IssueComment( issue_number=issue['number'], dataset_id=issue['dataset_id'], ) issue_factories.IssueComment( # unreported comment issue_number=issue['number'], dataset_id=issue['dataset_id'], ) comment_object = IssueComment.get(comment['id']) comment_object.visibility = u'hidden' comment_object.abuse_status = AbuseStatus.unmoderated.value comment_object.save() result = helpers.call_action('issue_comment_search', organization_id=organization['id']) assert_equals([comment['id']], [c['id'] for c in result])