def test_issue_create_second(self): issue_0 = toolkit.get_action("issue_create")( context={"user": self.user["name"]}, data_dict={"title": "Title", "description": "Description", "dataset_id": self.dataset["id"]}, ) issue_1 = toolkit.get_action("issue_create")( context={"user": self.user["name"]}, data_dict={"title": "Title", "description": "Description", "dataset_id": self.dataset["id"]}, ) issue_object = Issue.get(issue_0["id"]) assert_equals(1, issue_object.number) issue_object = Issue.get(issue_1["id"]) assert_equals(2, issue_object.number)
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'], visibility='hidden') user = factories.User() model.Session.add(Issue.Report(user['id'], issue['id'])) model.Session.commit() context = { 'user': user['name'], 'model': model, } helpers.call_action( 'issue_report_clear', context=context, dataset_id=dataset['id'], issue_number=issue['number'] ) result = helpers.call_action('issue_show', dataset_id=dataset['id'], issue_number=issue['number']) assert_equals('visible', result['visibility']) issue_obj = Issue.get(issue['id']) assert_equals(len(issue_obj.abuse_reports), 0)
def test_issue_create(self): creator = factories.User(name='creator') admin = factories.User(name='admin') org = factories.Organization( users=[{'name': admin['id'], 'capacity': 'admin'}]) dataset = factories.Dataset(owner_org=org['id']) # mock the render as it is easier to look at the variables passed in # than the rendered text with mock.patch('ckanext.issues.logic.action.action.render_jinja2') \ as render_mock: issue_create_result = toolkit.get_action('issue_create')( context={'user': creator['name']}, data_dict={ 'title': 'Title', 'description': 'Description', 'dataset_id': dataset['id'], } ) issue_object = Issue.get(issue_create_result['id']) assert_equals('Title', issue_object.title) assert_equals('Description', issue_object.description) assert_equals(1, issue_object.number) # some test user for the org called 'test.ckan.net' gets emailed too users_emailed = [call[1]['extra_vars']['recipient']['user_id'] for call in render_mock.call_args_list] assert_in(admin['id'], users_emailed)
def test_max_strikes_hides_issues(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']) user_0 = factories.User() context = { 'user': user_0['name'], 'model': model, } helpers.call_action( 'issue_report', context=context, dataset_id=dataset['id'], issue_number=issue['number'] ) user_1 = factories.User() context = { 'user': user_1['name'], 'model': model, } helpers.call_action( 'issue_report', context=context, dataset_id=dataset['id'], issue_number=issue['number'] ) issue_obj = Issue.get(issue['id']) assert_equals(len(issue_obj.abuse_reports), 2) assert_equals('hidden', issue_obj.visibility)
def test_issue_create_cannot_set_abuse(self): issue_create_result = toolkit.get_action('issue_create')( context={'user': self.user['name']}, data_dict={ 'title': 'Title', 'description': 'Description', 'dataset_id': self.dataset['id'], 'visibility': 'hidden' } ) issue_object = Issue.get(issue_create_result['id']) assert_equals('visible', issue_object.visibility)
def test_issue_create_cannot_set_abuse(self): issue_create_result = toolkit.get_action("issue_create")( context={"user": self.user["name"]}, data_dict={ "title": "Title", "description": "Description", "dataset_id": self.dataset["id"], "visibility": "hidden", }, ) issue_object = Issue.get(issue_create_result["id"]) assert_equals("visible", issue_object.visibility)
def test_issue_create_second(self): issue_0 = toolkit.get_action('issue_create')( context={'user': self.user['name']}, data_dict={ 'title': 'Title', 'description': 'Description', 'dataset_id': self.dataset['id'], } ) issue_1 = toolkit.get_action('issue_create')( context={'user': self.user['name']}, data_dict={ 'title': 'Title', 'description': 'Description', 'dataset_id': self.dataset['id'], } ) issue_object = Issue.get(issue_0['id']) assert_equals(1, issue_object.number) issue_object = Issue.get(issue_1['id']) assert_equals(2, issue_object.number)
def setup(self): super(TestMarkedAsSpamAppears, self).setup() self.owner = factories.User() self.org = factories.Organization(user=self.owner) self.dataset = factories.Dataset(user=self.owner, owner_org=self.org['name']) self.issue = issue_factories.Issue(user=self.owner, user_id=self.owner['id'], dataset_id=self.dataset['id']) issue = Issue.get(self.issue['id']) issue.spam_state = 'hidden' issue.save() self.user = factories.User() self.app = self._get_test_app()
def setup(self): super(TestAbuseReport, self).setup() self.owner = factories.User() self.org = factories.Organization(user=self.owner) self.dataset = factories.Dataset(user=self.owner, owner_org=self.org['name']) self.issue = issue_factories.Issue(user=self.owner, user_id=self.owner['id'], dataset_id=self.dataset['id']) issue = Issue.get(self.issue['id']) issue.visibility = 'hidden' issue.save() self.user = factories.User() self.app = self._get_test_app()
def test_issue_create_multiple_datasets(self): issue_0 = toolkit.get_action('issue_create')( context={'user': self.user['name']}, data_dict={ 'title': 'Title', 'description': 'Description', 'dataset_id': self.dataset['id'], } ) issue_1 = toolkit.get_action('issue_create')( context={'user': self.user['name']}, data_dict={ 'title': 'Title', 'description': 'Description', 'dataset_id': self.dataset['id'], } ) issue_object = Issue.get(issue_0['id']) assert_equals(1, issue_object.number) issue_object = Issue.get(issue_1['id']) assert_equals(2, issue_object.number) # create a second dataset dataset = factories.Dataset() issue_2 = toolkit.get_action('issue_create')( context={'user': self.user['name']}, data_dict={ 'title': 'Title', 'description': 'Description', 'dataset_id': dataset['id'], } ) issue_object = Issue.get(issue_2['id']) # check that the issue number starts from 1 assert_equals(1, issue_object.number)
def test_issue_create(self): issue_create_result = toolkit.get_action('issue_create')( context={ 'user': self.user['name'] }, data_dict={ 'title': 'Title', 'description': 'Description', 'dataset_id': self.dataset['id'], }) issue_object = Issue.get(issue_create_result['id']) assert_equals('Title', issue_object.title) assert_equals('Description', issue_object.description) assert_equals(1, issue_object.number)
def test_issue_create_multiple_datasets(self): issue_0 = toolkit.get_action("issue_create")( context={"user": self.user["name"]}, data_dict={"title": "Title", "description": "Description", "dataset_id": self.dataset["id"]}, ) issue_1 = toolkit.get_action("issue_create")( context={"user": self.user["name"]}, data_dict={"title": "Title", "description": "Description", "dataset_id": self.dataset["id"]}, ) issue_object = Issue.get(issue_0["id"]) assert_equals(1, issue_object.number) issue_object = Issue.get(issue_1["id"]) assert_equals(2, issue_object.number) # create a second dataset dataset = factories.Dataset() issue_2 = toolkit.get_action("issue_create")( context={"user": self.user["name"]}, data_dict={"title": "Title", "description": "Description", "dataset_id": dataset["id"]}, ) issue_object = Issue.get(issue_2["id"]) # check that the issue number starts from 1 assert_equals(1, issue_object.number)
def setup(self): super(TestModeratedAbuseReport, self).setup() self.owner = factories.User() self.reporter = factories.User() self.org = factories.Organization(user=self.owner) self.dataset = factories.Dataset(user=self.owner, owner_org=self.org['name']) # issue_abuse is moderated - i.e. definitely abuse/spam self.issue_abuse = issue_factories.Issue(user=self.owner, user_id=self.owner['id'], dataset_id=self.dataset['id']) issue_abuse = Issue.get(self.issue_abuse['id']) issue_abuse.visibility = 'hidden' issue_abuse.report_abuse(model.Session, self.reporter['id']) issue_abuse.abuse_status = AbuseStatus.abuse.value issue_abuse.save() self.user = factories.User() self.app = self._get_test_app()
def setup(self): super(TestModeratedAbuseReport, self).setup() self.owner = factories.User() self.reporter = factories.User() self.org = factories.Organization(user=self.owner) self.dataset = factories.Dataset(user=self.owner, owner_org=self.org['name']) # issue_abuse is moderated - i.e. definitely abuse/spam self.issue_abuse = issue_factories.Issue( user=self.owner, user_id=self.owner['id'], dataset_id=self.dataset['id']) issue_abuse = Issue.get(self.issue_abuse['id']) issue_abuse.visibility = 'hidden' issue_abuse.report_abuse(model.Session, self.reporter['id']) issue_abuse.abuse_status = AbuseStatus.abuse.value issue_abuse.save() self.user = factories.User() self.app = self._get_test_app()
def test_report_an_issue(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']) user = factories.User(name='unauthed') context = { 'user': user['name'], 'model': model, } helpers.call_action('issue_report', context=context, dataset_id=dataset['id'], issue_number=issue['number']) issue_obj = Issue.get(issue['id']) assert_equals(len(issue_obj.abuse_reports), 1) assert_equals(issue_obj.visibility, 'visible')
def setup(self): super(TestUnmoderatedAbuseReport, self).setup() self.owner = factories.User() self.reporter = factories.User() self.org = factories.Organization(user=self.owner) self.dataset = factories.Dataset(user=self.owner, owner_org=self.org['name']) # issue_reported is reported by a user but not moderated - i.e. may be # abuse/spam but it is still visible self.issue_reported = issue_factories.Issue( user=self.owner, user_id=self.owner['id'], dataset_id=self.dataset['id']) issue_reported = Issue.get(self.issue_reported['id']) issue_reported.visibility = 'visible' issue_reported.report_abuse(model.Session, self.reporter['id']) issue_reported.abuse_status = AbuseStatus.unmoderated.value issue_reported.save() self.user = factories.User() self.app = self._get_test_app()
def test_report_an_issue(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']) user = factories.User(name='unauthed') context = { 'user': user['name'], 'model': model, } helpers.call_action( 'issue_report', context=context, dataset_id=dataset['id'], issue_number=issue['number'] ) issue_obj = Issue.get(issue['id']) assert_equals(len(issue_obj.abuse_reports), 1) assert_equals(issue_obj.visibility, 'visible')
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'], visibility='hidden') context = { 'user': owner['name'], 'model': model, } helpers.call_action('issue_report_clear', context=context, dataset_id=dataset['id'], issue_number=issue['number']) result = helpers.call_action( 'issue_show', dataset_id=dataset['id'], issue_number=issue['number'], ) assert_equals('visible', result['visibility']) issue_obj = Issue.get(issue['id']) assert_equals(len(issue_obj.abuse_reports), 0)