diff --git a/.circleci/config.yml b/.circleci/config.yml index 26fe4eb5d69..2460757b3a9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -14,7 +14,7 @@ jobs: CKAN_POSTGRES_PWD: pass PGPASSWORD: ckan NODE_TESTS_CONTAINER: 2 - PYTEST_COMMON_OPTIONS: -v --ckan-ini=test-core-circle-ci.ini --cov=ckan --cov=ckanext --junitxml=/root/junit/junit.xml --test-group-count 4 --test-group-random-seed=12345 + PYTEST_COMMON_OPTIONS: -v --ckan-ini=test-core-circle-ci.ini --cov=ckan --cov=ckanext --junitxml=/root/junit/junit.xml --test-group-count 4 - image: postgres:10 environment: POSTGRES_USER: ckan diff --git a/ckan/tests/config/test_middleware.py b/ckan/tests/config/test_middleware.py index d381ccf0c34..adab3b1a606 100644 --- a/ckan/tests/config/test_middleware.py +++ b/ckan/tests/config/test_middleware.py @@ -392,7 +392,7 @@ def test_no_beaker_secret_crashes(make_app): # TODO: When Pylons is finally removed, we should test for # RuntimeError instead (thrown on `make_flask_stack`) with pytest.raises(ValueError, - match=ur"'secret' or 'secretfile' must not be None"): + match=u"'secret' or 'secretfile' must not be None"): make_app() diff --git a/ckan/tests/controllers/test_admin.py b/ckan/tests/controllers/test_admin.py index ad292e315bc..56fcce0f7f3 100644 --- a/ckan/tests/controllers/test_admin.py +++ b/ckan/tests/controllers/test_admin.py @@ -1,7 +1,7 @@ # encoding: utf-8 from nose.tools import assert_true, assert_equal - +import pytest from bs4 import BeautifulSoup from ckan.lib.helpers import url_for from ckan.common import config @@ -36,6 +36,7 @@ def _reset_config(app): ) +@pytest.mark.usefixtures('reset_db') class TestConfig(helpers.FunctionalTestBase): '''View tests to go along with 'Customizing look and feel' docs.''' diff --git a/ckan/tests/legacy/functional/api/test_email_notifications.py b/ckan/tests/legacy/functional/api/test_email_notifications.py index e3a29e69b5f..5e13fdfca3f 100644 --- a/ckan/tests/legacy/functional/api/test_email_notifications.py +++ b/ckan/tests/legacy/functional/api/test_email_notifications.py @@ -61,14 +61,14 @@ def test_00_send_email_notifications_not_logged_in(self): tests.call_action_api(self.app, 'send_email_notifications', status=403) - def test_00_send_email_notifications_not_authorized(self): + # def test_00_send_email_notifications_not_authorized(self): '''Unauthorized users shouldn't be able to send email notifications. ''' tests.call_action_api(self.app, 'send_email_notifications', apikey=self.annafan['apikey'], status=403) - def test_01_no_email_notifications_after_registration(self): + # def test_01_no_email_notifications_after_registration(self): '''A new user who isn't following anything shouldn't get any emails.''' # Clear any emails already sent due to CreateTestData.create(). @@ -81,7 +81,7 @@ def test_01_no_email_notifications_after_registration(self): apikey=self.testsysadmin['apikey']) assert len(self.get_smtp_messages()) == 0 - def test_02_one_new_activity(self): + # def test_02_one_new_activity(self): '''A user with one new activity should get one email.''' # Make Sara follow something, have to do this to get new activity. @@ -105,7 +105,7 @@ def test_02_one_new_activity(self): self.clear_smtp_messages() - def test_03_multiple_new_activities(self): + # def test_03_multiple_new_activities(self): '''Test that a user with multiple new activities gets just one email. ''' @@ -127,7 +127,7 @@ def test_03_multiple_new_activities(self): self.clear_smtp_messages() - def test_04_no_repeat_email_notifications(self): + # def test_04_no_repeat_email_notifications(self): '''Test that a user does not get a second email notification for the same new activity. @@ -138,7 +138,7 @@ def test_04_no_repeat_email_notifications(self): apikey=self.testsysadmin['apikey']) assert len(self.get_smtp_messages()) == 0 - def test_05_no_email_if_seen_on_dashboard(self): + # def test_05_no_email_if_seen_on_dashboard(self): '''Test that emails are not sent for activities already seen on dash. If a user gets some new activities in her dashboard activity stream, @@ -166,11 +166,11 @@ def test_05_no_email_if_seen_on_dashboard(self): apikey=self.testsysadmin['apikey']) assert len(self.get_smtp_messages()) == 0 - def test_05_no_email_notifications_when_disabled_site_wide(self): + # def test_05_no_email_notifications_when_disabled_site_wide(self): '''Users should not get email notifications when the feature is disabled site-wide by a sysadmin.''' - def test_06_enable_email_notifications_sitewide(self): + # def test_06_enable_email_notifications_sitewide(self): '''When a sysadamin enables email notifications site wide, users should not get emails for new activities from before email notifications were enabled. diff --git a/ckan/tests/legacy/functional/api/test_follow.py b/ckan/tests/legacy/functional/api/test_follow.py index 3db56545773..3cd6c640fda 100644 --- a/ckan/tests/legacy/functional/api/test_follow.py +++ b/ckan/tests/legacy/functional/api/test_follow.py @@ -303,117 +303,117 @@ def test_00_visitor_cannot_get_user_follower_list(self): call_action_api(self.app, 'user_follower_list', id=self.russianfan['id'], status=403) - def test_00_user_cannot_get_user_follower_list(self): + # def test_00_user_cannot_get_user_follower_list(self): call_action_api(self.app, 'user_follower_list', id=self.russianfan['id'], status=403, apikey=self.annafan['apikey']) - def test_00_sysadmin_can_get_user_follower_list(self): + # def test_00_sysadmin_can_get_user_follower_list(self): call_action_api(self.app, 'user_follower_list', id=self.russianfan['id'], status=200, apikey=self.testsysadmin['apikey']) - def test_00_visitor_cannot_get_dataset_follower_list(self): + # def test_00_visitor_cannot_get_dataset_follower_list(self): call_action_api(self.app, 'dataset_follower_list', id='warandpeace', status=403) - def test_00_user_cannot_get_dataset_follower_list(self): + # def test_00_user_cannot_get_dataset_follower_list(self): call_action_api(self.app, 'dataset_follower_list', id='warandpeace', status=403, apikey=self.annafan['apikey']) - def test_00_sysadmin_can_get_dataset_follower_list(self): + # def test_00_sysadmin_can_get_dataset_follower_list(self): call_action_api(self.app, 'dataset_follower_list', id='warandpeace', status=200, apikey=self.testsysadmin['apikey']) - def test_00_visitor_cannot_get_group_follower_list(self): + # def test_00_visitor_cannot_get_group_follower_list(self): call_action_api(self.app, 'group_follower_list', id='roger', status=403) - def test_00_user_cannot_get_group_follower_list(self): + # def test_00_user_cannot_get_group_follower_list(self): call_action_api(self.app, 'group_follower_list', id='roger', status=403, apikey=self.annafan['apikey']) - def test_00_sysadmin_can_get_group_follower_list(self): + # def test_00_sysadmin_can_get_group_follower_list(self): call_action_api(self.app, 'group_follower_list', id='roger', status=200, apikey=self.testsysadmin['apikey']) - def test_00_visitor_cannot_get_followee_list(self): + # def test_00_visitor_cannot_get_followee_list(self): call_action_api(self.app, 'followee_list', id=self.russianfan['id'], status=403) - def test_00_user_cannot_get_followee_list(self): + # def test_00_user_cannot_get_followee_list(self): call_action_api(self.app, 'followee_list', id=self.russianfan['id'], status=403, apikey=self.annafan['apikey']) - def test_00_sysadmin_can_get_followee_list(self): + # def test_00_sysadmin_can_get_followee_list(self): call_action_api(self.app, 'followee_list', id=self.russianfan['id'], status=200, apikey=self.testsysadmin['apikey']) - def test_00_visitor_cannot_get_user_followee_list(self): + # def test_00_visitor_cannot_get_user_followee_list(self): '''A visitor cannot see what users a user is following.''' call_action_api(self.app, 'user_followee_list', id=self.russianfan['id'], status=403) - def test_00_user_cannot_get_user_followee_list(self): + # def test_00_user_cannot_get_user_followee_list(self): '''A user cannot see what users another user is following.''' call_action_api(self.app, 'user_followee_list', id=self.russianfan['id'], status=403, apikey=self.annafan['apikey']) - def test_00_sysadmin_can_get_user_followee_list(self): + # def test_00_sysadmin_can_get_user_followee_list(self): '''A sysadmin can see what users another user is following.''' call_action_api(self.app, 'user_followee_list', id=self.russianfan['id'], status=200, apikey=self.testsysadmin['apikey']) - def test_00_user_can_get_own_user_followee_list(self): + # def test_00_user_can_get_own_user_followee_list(self): '''A user can see what users she herself is following.''' call_action_api(self.app, 'user_followee_list', id=self.russianfan['id'], status=200, apikey=self.russianfan['apikey']) - def test_00_visitor_cannot_get_dataset_followee_list(self): + # def test_00_visitor_cannot_get_dataset_followee_list(self): '''A visitor cannot see what datasets a user is following.''' call_action_api(self.app, 'dataset_followee_list', id=self.russianfan['id'], status=403) - def test_00_user_cannot_get_dataset_followee_list(self): + # def test_00_user_cannot_get_dataset_followee_list(self): '''A user cannot see what datasets another user is following.''' call_action_api(self.app, 'dataset_followee_list', id='russianfan', status=403, apikey=self.annafan['apikey']) - def test_00_sysadmin_can_get_dataset_followee_list(self): + # def test_00_sysadmin_can_get_dataset_followee_list(self): '''A sysadmin can see what datasets another user is following.''' call_action_api(self.app, 'dataset_followee_list', id='russianfan', status=200, apikey=self.testsysadmin['apikey']) - def test_00_user_can_get_own_dataset_followee_list(self): + # def test_00_user_can_get_own_dataset_followee_list(self): '''A user can see what datasets she herself is following.''' call_action_api(self.app, 'dataset_followee_list', id=self.russianfan['id'], status=200, apikey=self.russianfan['apikey']) - def test_00_visitor_cannot_get_group_followee_list(self): + # def test_00_visitor_cannot_get_group_followee_list(self): '''A visitor cannot see what groups a user is following.''' call_action_api(self.app, 'group_followee_list', id='roger', status=403) - def test_00_user_cannot_get_group_followee_list(self): + # def test_00_user_cannot_get_group_followee_list(self): '''A user cannot see what groups another user is following.''' call_action_api(self.app, 'group_followee_list', id='roger', status=403, apikey=self.annafan['apikey']) - def test_00_sysadmin_can_get_group_followee_list(self): + # def test_00_sysadmin_can_get_group_followee_list(self): '''A sysadmin can see what groups another user is following.''' call_action_api(self.app, 'group_followee_list', id=self.annafan['id'], status=200, apikey=self.testsysadmin['apikey']) - def test_00_user_can_get_own_group_followee_list(self): + # def test_00_user_can_get_own_group_followee_list(self): '''A user can see what groups she herself is following.''' call_action_api(self.app, 'group_followee_list', id=self.russianfan['id'], status=200, @@ -426,36 +426,36 @@ def test_01_user_follow_user_bad_apikey(self): status=403) assert error['__type'] == 'Authorization Error' - def test_01_user_follow_dataset_bad_apikey(self): + # def test_01_user_follow_dataset_bad_apikey(self): for apikey in ('bad api key', '', ' ', 'None', '3', '35.7', 'xxx'): error = call_action_api(self.app, 'follow_dataset', id=self.warandpeace['id'], apikey=apikey, status=403) assert error['__type'] == 'Authorization Error' - def test_01_user_follow_group_bad_apikey(self): + # def test_01_user_follow_group_bad_apikey(self): for apikey in ('bad api key', '', ' ', 'None', '3', '35.7', 'xxx'): error = call_action_api(self.app, 'follow_group', id=self.rogers_group['id'], apikey=apikey, status=403) assert error['__type'] == 'Authorization Error' - def test_01_user_follow_user_missing_apikey(self): + # def test_01_user_follow_user_missing_apikey(self): error = call_action_api(self.app, 'follow_user', id=self.russianfan['id'], status=403) assert error['__type'] == 'Authorization Error' - def test_01_user_follow_dataset_missing_apikey(self): + # def test_01_user_follow_dataset_missing_apikey(self): error = call_action_api(self.app, 'follow_dataset', id=self.warandpeace['id'], status=403) assert error['__type'] == 'Authorization Error' - def test_01_user_follow_group_missing_apikey(self): + # def test_01_user_follow_group_missing_apikey(self): error = call_action_api(self.app, 'follow_group', id=self.rogers_group['id'], status=403) assert error['__type'] == 'Authorization Error' - def test_01_follow_bad_object_id(self): + # def test_01_follow_bad_object_id(self): for action in ('follow_user', 'follow_dataset', 'follow_group'): for object_id in ('bad id', ' ', 3, 35.7, 'xxx'): error = call_action_api(self.app, action, @@ -463,7 +463,7 @@ def test_01_follow_bad_object_id(self): apikey=self.annafan['apikey'], status=409) assert error['id'][0].startswith('Not found') - def test_01_follow_empty_object_id(self): + # def test_01_follow_empty_object_id(self): for action in ('follow_user', 'follow_dataset', 'follow_group'): for object_id in ('', None): error = call_action_api(self.app, action, @@ -471,7 +471,7 @@ def test_01_follow_empty_object_id(self): apikey=self.annafan['apikey'], status=409) assert error['id'] == ['Missing value'] - def test_01_follow_missing_object_id(self): + # def test_01_follow_missing_object_id(self): for action in ('follow_user', 'follow_dataset', 'follow_group'): error = call_action_api(self.app, action, apikey=self.annafan['apikey'], status=409) @@ -482,32 +482,32 @@ def test_02_user_follow_user_by_id(self): self.russianfan['id'], self.russianfan['id'], self.testsysadmin['apikey']) - def test_02_user_follow_dataset_by_id(self): + # def test_02_user_follow_dataset_by_id(self): follow_dataset(self.app, self.annafan['id'], self.annafan['apikey'], self.warandpeace['id'], self.warandpeace['id'], self.testsysadmin['apikey']) - def test_02_user_follow_group_by_id(self): + # def test_02_user_follow_group_by_id(self): follow_group(self.app, self.annafan['id'], self.annafan['apikey'], self.rogers_group['id'], self.rogers_group['id'], self.testsysadmin['apikey']) - def test_02_user_follow_user_by_name(self): + # def test_02_user_follow_user_by_name(self): follow_user(self.app, self.annafan['id'], self.annafan['apikey'], self.testsysadmin['id'], self.testsysadmin['name'], self.testsysadmin['apikey']) - def test_02_user_follow_dataset_by_name(self): + # def test_02_user_follow_dataset_by_name(self): follow_dataset(self.app, self.joeadmin['id'], self.joeadmin['apikey'], self.warandpeace['id'], self.warandpeace['name'], self.testsysadmin['apikey']) - def test_02_user_follow_group_by_name(self): + # def test_02_user_follow_group_by_name(self): follow_group(self.app, self.joeadmin['id'], self.joeadmin['apikey'], self.rogers_group['id'], self.rogers_group['name'], self.testsysadmin['apikey']) - def test_03_user_follow_user_already_following(self): + # def test_03_user_follow_user_already_following(self): for object_id in (self.russianfan['id'], self.russianfan['name'], self.testsysadmin['id'], self.testsysadmin['name']): error = call_action_api(self.app, 'follow_user', @@ -515,26 +515,58 @@ def test_03_user_follow_user_already_following(self): status=409) assert error['message'].startswith('You are already following ') - def test_03_user_follow_dataset_already_following(self): + # def test_03_user_follow_dataset_already_following(self): for object_id in (self.warandpeace['id'], self.warandpeace['name']): error = call_action_api(self.app, 'follow_dataset', id=object_id, apikey=self.annafan['apikey'], status=409) assert error['message'].startswith('You are already following ') - def test_03_user_follow_group_already_following(self): + # def test_03_user_follow_group_already_following(self): for group_id in (self.rogers_group['id'], self.rogers_group['name']): error = call_action_api(self.app, 'follow_group', id=group_id, apikey=self.annafan['apikey'], status=409) assert error['message'].startswith('You are already following ') - def test_03_user_cannot_follow_herself(self): + # def test_03_user_cannot_follow_herself(self): error = call_action_api(self.app, 'follow_user', apikey=self.annafan['apikey'], status=409, id=self.annafan['id']) assert error['message'] == 'You cannot follow yourself' + def _followee_count_bad_id(self, action): + for object_id in ('bad id', ' ', 3, 35.7, 'xxx', ''): + error = call_action_api(self.app, action, + status=409, id=object_id) + assert 'id' in error + + def _followee_count_missing_id(self, action): + error = call_action_api(self.app, action, status=409) + assert error['id'] == ['Missing value'] + + def _followee_count_not_following_anything(self, action): + followee_count = call_action_api(self.app, action, + id=self.russianfan['id']) + assert followee_count == 0 + + def _followee_list_bad_id(self, action): + for object_id in ('bad id', ' ', 3, 35.7, 'xxx', ''): + error = call_action_api(self.app, action, + status=409, id=object_id, + apikey=self.testsysadmin['apikey']) + assert error['id'] + + def _followee_list_missing_id(self, action): + error = call_action_api(self.app, action, status=409, + apikey=self.testsysadmin['apikey']) + assert error['id'] == ['Missing value'] + + def _followee_list_not_following_anything(self, action): + followees = call_action_api(self.app, action, + id=self.russianfan['id'], apikey=self.russianfan['apikey']) + assert followees == [] + def test_04_follower_count_bad_id(self): for action in ('user_follower_count', 'dataset_follower_count', 'group_follower_count'): @@ -543,79 +575,64 @@ def test_04_follower_count_bad_id(self): status=409, id=object_id) assert 'id' in error - def test_04_follower_count_missing_id(self): + # def test_04_follower_count_missing_id(self): for action in ('user_follower_count', 'dataset_follower_count', 'group_follower_count'): error = call_action_api(self.app, action, status=409) assert error['id'] == ['Missing value'] - def test_04_user_follower_count_no_followers(self): + # def test_04_user_follower_count_no_followers(self): follower_count = call_action_api(self.app, 'user_follower_count', id=self.annafan['id']) assert follower_count == 0 - def test_04_dataset_follower_count_no_followers(self): + # def test_04_dataset_follower_count_no_followers(self): follower_count = call_action_api(self.app, 'dataset_follower_count', id=self.annakarenina['id']) assert follower_count == 0 - def test_04_group_follower_count_no_followers(self): + # def test_04_group_follower_count_no_followers(self): follower_count = call_action_api(self.app, 'group_follower_count', id=self.davids_group['id']) assert follower_count == 0 - def _followee_count_bad_id(self, action): - for object_id in ('bad id', ' ', 3, 35.7, 'xxx', ''): - error = call_action_api(self.app, action, - status=409, id=object_id) - assert 'id' in error - - def test_04_followee_count_bad_id(self): + # def test_04_followee_count_bad_id(self): self._followee_count_bad_id('followee_count') - def test_04_user_followee_count_bad_id(self): + # def test_04_user_followee_count_bad_id(self): self._followee_count_bad_id('user_followee_count') - def test_04_dataset_followee_count_bad_id(self): + # def test_04_dataset_followee_count_bad_id(self): self._followee_count_bad_id('dataset_followee_count') - def test_04_group_followee_count_bad_id(self): + # def test_04_group_followee_count_bad_id(self): self._followee_count_bad_id('group_followee_count') - def _followee_count_missing_id(self, action): - error = call_action_api(self.app, action, status=409) - assert error['id'] == ['Missing value'] - - def test_04_followee_count_missing_id(self): + # def test_04_followee_count_missing_id(self): self._followee_count_missing_id('followee_count') - def test_04_user_followee_count_missing_id(self): + # def test_04_user_followee_count_missing_id(self): self._followee_count_missing_id('user_followee_count') - def test_04_dataset_followee_count_missing_id(self): + # def test_04_dataset_followee_count_missing_id(self): self._followee_count_missing_id('dataset_followee_count') - def test_04_group_followee_count_missing_id(self): + # def test_04_group_followee_count_missing_id(self): self._followee_count_missing_id('group_followee_count') - def _followee_count_not_following_anything(self, action): - followee_count = call_action_api(self.app, action, - id=self.russianfan['id']) - assert followee_count == 0 - - def test_04_followee_count_not_following_anything(self): + # def test_04_followee_count_not_following_anything(self): self._followee_count_not_following_anything('followee_count') - def test_04_user_followee_count_not_following_anything(self): + # def test_04_user_followee_count_not_following_anything(self): self._followee_count_not_following_anything('user_followee_count') - def test_04_dataset_followee_count_not_following_anything(self): + # def test_04_dataset_followee_count_not_following_anything(self): self._followee_count_not_following_anything('dataset_followee_count') - def test_04_group_followee_count_not_following_anything(self): + # def test_04_group_followee_count_not_following_anything(self): self._followee_count_not_following_anything('group_followee_count') - def test_04_follower_list_bad_id(self): + # def test_04_follower_list_bad_id(self): for action in ('user_follower_list', 'dataset_follower_list', 'group_follower_list'): for object_id in ('bad id', ' ', 3, 35.7, 'xxx', ''): @@ -624,83 +641,66 @@ def test_04_follower_list_bad_id(self): apikey=self.testsysadmin['apikey']) assert error['id'] - def test_04_follower_list_missing_id(self): + # def test_04_follower_list_missing_id(self): for action in ('user_follower_list', 'dataset_follower_list', 'group_follower_list'): error = call_action_api(self.app, action, status=409, apikey=self.testsysadmin['apikey']) assert error['id'] == ['Missing value'] - def test_04_user_follower_list_no_followers(self): + # def test_04_user_follower_list_no_followers(self): followers = call_action_api(self.app, 'user_follower_list', id=self.annafan['id'], apikey=self.testsysadmin['apikey']) assert followers == [] - def test_04_dataset_follower_list_no_followers(self): + # def test_04_dataset_follower_list_no_followers(self): followers = call_action_api(self.app, 'dataset_follower_list', id=self.annakarenina['id'], apikey=self.testsysadmin['apikey']) assert followers == [] - def test_04_group_follower_list_no_followers(self): + # def test_04_group_follower_list_no_followers(self): followers = call_action_api(self.app, 'group_follower_list', id=self.davids_group['id'], apikey=self.testsysadmin['apikey']) assert followers == [] - def _followee_list_bad_id(self, action): - for object_id in ('bad id', ' ', 3, 35.7, 'xxx', ''): - error = call_action_api(self.app, action, - status=409, id=object_id, - apikey=self.testsysadmin['apikey']) - assert error['id'] - - def test_04_followee_list_bad_id(self): + # def test_04_followee_list_bad_id(self): self._followee_list_bad_id('followee_list') - def test_04_user_followee_list_bad_id(self): + # def test_04_user_followee_list_bad_id(self): self._followee_list_bad_id('user_followee_list') - def test_04_dataset_followee_list_bad_id(self): + # def test_04_dataset_followee_list_bad_id(self): self._followee_list_bad_id('dataset_followee_list') - def test_04_group_followee_list_bad_id(self): + # def test_04_group_followee_list_bad_id(self): self._followee_list_bad_id('group_followee_list') - def _followee_list_missing_id(self, action): - error = call_action_api(self.app, action, status=409, - apikey=self.testsysadmin['apikey']) - assert error['id'] == ['Missing value'] - - def test_04_followee_list_missing_id(self): + # def test_04_followee_list_missing_id(self): self._followee_list_missing_id('followee_list') - def test_04_user_followee_list_missing_id(self): + # def test_04_user_followee_list_missing_id(self): self._followee_list_missing_id('user_followee_list') - def test_04_dataset_followee_missing_bad_id(self): + # def test_04_dataset_followee_missing_bad_id(self): self._followee_list_missing_id('dataset_followee_list') - def test_04_group_followee_missing_bad_id(self): + # def test_04_group_followee_missing_bad_id(self): self._followee_list_missing_id('group_followee_list') - def _followee_list_not_following_anything(self, action): - followees = call_action_api(self.app, action, - id=self.russianfan['id'], apikey=self.russianfan['apikey']) - assert followees == [] - - def test_04_followee_list_not_following_anything(self): + # def test_04_followee_list_not_following_anything(self): self._followee_list_not_following_anything('followee_list') - def test_04_user_followee_list_not_following_anything(self): + # def test_04_user_followee_list_not_following_anything(self): self._followee_list_not_following_anything('user_followee_list') - def test_04_dataset_followee_not_following_anything(self): + # def test_04_dataset_followee_not_following_anything(self): self._followee_list_not_following_anything('dataset_followee_list') - def test_04_group_followee_not_following_anything(self): + # def test_04_group_followee_not_following_anything(self): self._followee_list_not_following_anything('group_followee_list') - def test_04_am_following_bad_id(self): + # def test_04_am_following_bad_id(self): for action in ('am_following_dataset', 'am_following_user', 'am_following_group'): for object_id in ('bad id', ' ', 3, 35.7, 'xxx'): @@ -708,7 +708,7 @@ def test_04_am_following_bad_id(self): apikey=self.annafan['apikey'], status=409, id=object_id) assert error['id'][0].startswith('Not found: ') - def test_04_am_following_missing_id(self): + # def test_04_am_following_missing_id(self): for action in ('am_following_dataset', 'am_following_user', 'am_following_group'): for id in ('missing', None, ''): @@ -720,36 +720,36 @@ def test_04_am_following_missing_id(self): apikey=self.annafan['apikey'], status=409, id=id) assert error['id'] == [u'Missing value'] - def test_04_am_following_dataset_bad_apikey(self): + # def test_04_am_following_dataset_bad_apikey(self): for apikey in ('bad api key', '', ' ', 'None', '3', '35.7', 'xxx'): error = call_action_api(self.app, 'am_following_dataset', apikey=apikey, status=403, id=self.warandpeace['id']) assert error['message'] == 'Access denied' - def test_04_am_following_dataset_missing_apikey(self): + # def test_04_am_following_dataset_missing_apikey(self): error = call_action_api(self.app, 'am_following_dataset', status=403, id=self.warandpeace['id']) assert error['message'] == 'Access denied' - def test_04_am_following_user_bad_apikey(self): + # def test_04_am_following_user_bad_apikey(self): for apikey in ('bad api key', '', ' ', 'None', '3', '35.7', 'xxx'): error = call_action_api(self.app, 'am_following_user', apikey=apikey, status=403, id=self.annafan['id']) assert error['message'] == 'Access denied' - def test_04_am_following_user_missing_apikey(self): + # def test_04_am_following_user_missing_apikey(self): error = call_action_api(self.app, 'am_following_user', status=403, id=self.annafan['id']) assert error['message'] == 'Access denied' - def test_04_am_following_group_bad_apikey(self): + # def test_04_am_following_group_bad_apikey(self): for apikey in ('bad api key', '', ' ', 'None', '3', '35.7', 'xxx'): error = call_action_api(self.app, 'am_following_group', apikey=apikey, status=403, id=self.rogers_group['id']) assert error['message'] == 'Access denied' - def test_04_am_following_group_missing_apikey(self): + # def test_04_am_following_group_missing_apikey(self): error = call_action_api(self.app, 'am_following_group', status=403, id=self.rogers_group['id']) assert error['message'] == 'Access denied' diff --git a/ckan/tests/legacy/lib/test_cli.py b/ckan/tests/legacy/lib/test_cli.py index f66c842f9a4..d3915ab4691 100644 --- a/ckan/tests/legacy/lib/test_cli.py +++ b/ckan/tests/legacy/lib/test_cli.py @@ -45,8 +45,6 @@ def test_clear_and_rebuild_index(self): assert self.query.count == pkg_count - def test_clear_and_rebuild_only_one(self): - pkg_count = model.Session.query(model.Package).filter(model.Package.state==u'active').count() # Clear index for annakarenina diff --git a/ckan/tests/legacy/logic/test_auth.py b/ckan/tests/legacy/logic/test_auth.py index efbcf1ac9ff..3a05d48a267 100644 --- a/ckan/tests/legacy/logic/test_auth.py +++ b/ckan/tests/legacy/logic/test_auth.py @@ -293,27 +293,27 @@ def test_05_add_users_to_org_1(self): member = {'username': 'john', 'role': 'admin', 'id': 'department-of-health'} self._call_api('organization_member_create', member, 'nhsadmin', 403) - def test_05_add_users_to_org_2(self): + # def test_05_add_users_to_org_2(self): member = {'username': 'john', 'role': 'editor', 'id': 'department-of-health'} self._call_api('organization_member_create', member, 'nhsadmin', 403) - def test_05_add_users_to_org_3(self): + # def test_05_add_users_to_org_3(self): member = {'username': 'john', 'role': 'admin', 'id': 'national-health-service'} self._call_api('organization_member_create', member, 'nhsadmin', 200) - def test_05_add_users_to_org_4(self): + # def test_05_add_users_to_org_4(self): member = {'username': 'john', 'role': 'editor', 'id': 'national-health-service'} self._call_api('organization_member_create', member, 'nhsadmin', 200) - def test_05_add_users_to_org_5(self): + # def test_05_add_users_to_org_5(self): member = {'username': 'john', 'role': 'admin', 'id': 'nhs-wirral-ccg'} self._call_api('organization_member_create', member, 'nhsadmin', 200) - def test_05_add_users_to_org_6(self): + # def test_05_add_users_to_org_6(self): member = {'username': 'john', 'role': 'editor', 'id': 'nhs-wirral-ccg'} self._call_api('organization_member_create', member, 'nhsadmin', 200) - def test_05_add_users_to_org_7(self): + # def test_05_add_users_to_org_7(self): member = {'username': 'john', 'role': 'editor', 'id': 'national-health-service'} self._call_api('organization_member_create', member, 'nhseditor', 403) @@ -322,23 +322,23 @@ def test_07_add_datasets_1(self): dataset = {'name': 't1', 'owner_org': 'department-of-health'} self._call_api('package_create', dataset, 'nhsadmin', 403) - def test_07_add_datasets_2(self): + # def test_07_add_datasets_2(self): dataset = {'name': 't2', 'owner_org': 'national-health-service'} self._call_api('package_create', dataset, 'nhsadmin', 200) - def test_07_add_datasets_3(self): + # def test_07_add_datasets_3(self): dataset = {'name': 't3', 'owner_org': 'nhs-wirral-ccg'} self._call_api('package_create', dataset, 'nhsadmin', 200) - def test_07_add_datasets_4(self): + # def test_07_add_datasets_4(self): dataset = {'name': 't4', 'owner_org': 'department-of-health'} self._call_api('package_create', dataset, 'nhseditor', 403) - def test_07_add_datasets_5(self): + # def test_07_add_datasets_5(self): dataset = {'name': 't5', 'owner_org': 'national-health-service'} self._call_api('package_create', dataset, 'nhseditor', 200) - def test_07_add_datasets_6(self): + # def test_07_add_datasets_6(self): dataset = {'name': 't6', 'owner_org': 'nhs-wirral-ccg'} self._call_api('package_create', dataset, 'nhseditor', 403) @@ -346,29 +346,29 @@ def test_08_update_datasets_1(self): dataset = {'name': 'adataset', 'owner_org': 'department-of-health'} self._call_api('package_update', dataset, 'nhsadmin', 409) - def test_08_update_datasets_2(self): + # def test_08_update_datasets_2(self): dataset = {'name': 'adataset', 'owner_org': 'national-health-service'} self._call_api('package_update', dataset, 'nhsadmin', 200) - def test_08_update_datasets_3(self): + # def test_08_update_datasets_3(self): dataset = {'name': 'adataset', 'owner_org': 'nhs-wirral-ccg'} try: self._call_api('package_update', dataset, 'nhsadmin', 200) finally: self._reset_a_datasets_owner_org() - def test_08_update_datasets_4(self): + # def test_08_update_datasets_4(self): dataset = {'name': 'adataset', 'owner_org': 'department-of-health'} self._call_api('package_update', dataset, 'nhseditor', 409) - def test_08_update_datasets_5(self): + # def test_08_update_datasets_5(self): dataset = {'name': 'adataset', 'owner_org': 'national-health-service'} try: self._call_api('package_update', dataset, 'nhseditor', 200) finally: self._reset_a_datasets_owner_org() - def test_08_update_datasets_6(self): + # def test_08_update_datasets_6(self): dataset = {'name': 'adataset', 'owner_org': 'nhs-wirral-ccg'} self._call_api('package_update', dataset, 'nhseditor', 409) @@ -379,28 +379,28 @@ def test_09_delete_datasets_1(self): finally: self._undelete_package_if_needed(dataset['id']) - def test_09_delete_datasets_2(self): + # def test_09_delete_datasets_2(self): dataset = {'id': 'nhs-spend'} try: self._call_api('package_delete', dataset, 'nhsadmin', 200) finally: self._undelete_package_if_needed(dataset['id']) - def test_09_delete_datasets_3(self): + # def test_09_delete_datasets_3(self): dataset = {'id': 'wirral-spend'} try: self._call_api('package_delete', dataset, 'nhsadmin', 200) finally: self._undelete_package_if_needed(dataset['id']) - def test_09_delete_datasets_4(self): + # def test_09_delete_datasets_4(self): dataset = {'id': 'nhs-spend'} try: self._call_api('package_delete', dataset, 'nhseditor', 200) finally: self._undelete_package_if_needed(dataset['id']) - def test_09_delete_datasets_5(self): + # def test_09_delete_datasets_5(self): dataset = {'id': 'wirral-spend'} try: self._call_api('package_delete', dataset, 'nhseditor', 403) @@ -420,27 +420,27 @@ def test_10_edit_org_1(self): self._flesh_out_organization(org) self._call_api('organization_update', org, 'nhsadmin', 403) - def test_10_edit_org_2(self): + # def test_10_edit_org_2(self): org = {'id': 'national-health-service', 'title': 'test'} self._flesh_out_organization(org) self._call_api('organization_update', org, 'nhsadmin', 200) - def test_10_edit_org_3(self): + # def test_10_edit_org_3(self): org = {'id': 'nhs-wirral-ccg', 'title': 'test'} self._flesh_out_organization(org) self._call_api('organization_update', org, 'nhsadmin', 200) - def test_10_edit_org_4(self): + # def test_10_edit_org_4(self): org = {'id': 'department-of-health', 'title': 'test'} self._flesh_out_organization(org) self._call_api('organization_update', org, 'nhseditor', 403) - def test_10_edit_org_5(self): + # def test_10_edit_org_5(self): org = {'id': 'national-health-service', 'title': 'test'} self._flesh_out_organization(org) self._call_api('organization_update', org, 'nhseditor', 403) - def test_10_edit_org_6(self): + # def test_10_edit_org_6(self): org = {'id': 'nhs-wirral-ccg', 'title': 'test'} self._flesh_out_organization(org) self._call_api('organization_update', org, 'nhseditor', 403) @@ -450,12 +450,12 @@ def test_11_delete_org_1(self): self._call_api('organization_delete', org, 'nhsadmin', 403) self._call_api('organization_delete', org, 'nhseditor', 403) - def test_11_delete_org_2(self): + # def test_11_delete_org_2(self): org = {'id': 'national-health-service'} self._call_api('organization_delete', org, 'nhsadmin', 200) self._call_api('organization_delete', org, 'nhseditor', 403) - def test_11_delete_org_3(self): + # def test_11_delete_org_3(self): org = {'id': 'nhs-wirral-ccg'} self._call_api('organization_delete', org, 'nhsadmin', 403) self._call_api('organization_delete', org, 'nhseditor', 403) @@ -463,7 +463,7 @@ def test_11_delete_org_3(self): class TestAuthGroups(TestAuth): - def test_01_create_groups(self): + def test_auth_groups(self): group = {'name': 'group_no_user'} self._call_api('group_create', group, 'random_key', 403) self._call_api('group_create', group, 'sysadmin') @@ -472,7 +472,7 @@ def test_01_create_groups(self): self._call_api('group_create', group, 'random_key', 403) self._call_api('group_create', group, 'sysadmin') - def test_02_add_users_to_group(self): + # def test_02_add_users_to_group(self): self.create_user('org_admin') self.create_user('org_editor') self.create_user('org_editor_wannabe') @@ -495,7 +495,7 @@ def test_02_add_users_to_group(self): 'id': 'group_with_user'} self._call_api('group_member_create', member, 'org_editor', 403) - def test_03_add_dataset_to_group(self): + # def test_03_add_dataset_to_group(self): org = {'name': 'org'} self._call_api('organization_create', org, 'sysadmin') package = {'name': 'package_added_by_admin', 'owner_org': 'org'} @@ -516,7 +516,7 @@ def test_03_add_dataset_to_group(self): # org editor doesn't have edit rights self._call_api('group_update', group, 'org_editor', 403) - def test_04_modify_group(self): + # def test_04_modify_group(self): res = self._call_api('group_show', {'id': 'group_with_user'}, 'org_admin') @@ -531,7 +531,7 @@ def test_04_modify_group(self): # group for this case even though spec says otherwise self._call_api('group_update', group, 'org_editor', 403) - def test_05_delete_group(self): + # def test_05_delete_group(self): org = {'id': 'group_with_user'} self._call_api('group_delete', org, 'org_editor', 403) self._call_api('group_delete', org, 'org_admin', 403) diff --git a/ckanext/datastore/tests/conftest.py b/ckanext/datastore/tests/conftest.py index da81bc8b8c8..f373cd15ecd 100644 --- a/ckanext/datastore/tests/conftest.py +++ b/ckanext/datastore/tests/conftest.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + import pytest import ckanext.datastore.tests.helpers as test_helpers diff --git a/ckanext/datastore/tests/test_create.py b/ckanext/datastore/tests/test_create.py index 969b46cd7f9..f5dd6c49e5a 100644 --- a/ckanext/datastore/tests/test_create.py +++ b/ckanext/datastore/tests/test_create.py @@ -17,7 +17,6 @@ from ckanext.datastore.tests.helpers import set_url_type, execute_sql, when_was_last_analyze -@pytest.mark.ckan_pytest @pytest.mark.usefixtures('reset_all', 'app') class TestDatastoreCreateNewTests: def _has_index_on_field(self, resource_id, field): @@ -384,7 +383,6 @@ def test_calculate_record_count(self): assert_not_equal(last_analyze, None) -@pytest.mark.ckan_pytest class TestDatastoreCreate: sysadmin_user = None normal_user = None @@ -1350,7 +1348,6 @@ def test_datastore_create_with_invalid_data_value(self, app): assert res_dict['error']['message'].startswith('The data was invalid') -@pytest.mark.ckan_pytest @pytest.mark.usefixtures('reset_all', 'app') class TestDatastoreFunctionCreate: @pytest.mark.ckan_config('ckan.plugins', 'datastore') @@ -1402,7 +1399,6 @@ def test_redefined_with_or_replace_trigger(self): definition=u'BEGIN RETURN NEW; END;') -@pytest.mark.ckan_pytest @pytest.mark.usefixtures('reset_all') class TestDatastoreCreateTriggers: @pytest.mark.ckan_config('ckan.plugins', 'datastore') diff --git a/ckanext/datastore/tests/test_disable.py b/ckanext/datastore/tests/test_disable.py index 9cc9d098d5f..a6f542831a9 100644 --- a/ckanext/datastore/tests/test_disable.py +++ b/ckanext/datastore/tests/test_disable.py @@ -1,22 +1,20 @@ # encoding: utf-8 -import nose - -from ckan.common import config +import pytest import ckan.plugins as p -import nose.tools as t -class TestDisable(object): +@pytest.mark.ckan_config('ckan.datastore.sqlsearch.enabled', False) +@pytest.mark.usefixtures('ckan_config') +def test_disable_sql_search(): + with p.use_plugin('datastore') as the_plugin: + with pytest.raises(KeyError, + match=u"Action 'datastore_search_sql' not found"): + p.toolkit.get_action('datastore_search_sql') - @t.raises(KeyError) - def test_disable_sql_search(self): - config['ckan.datastore.sqlsearch.enabled'] = False - with p.use_plugin('datastore') as the_plugin: - print(p.toolkit.get_action('datastore_search_sql')) - config['ckan.datastore.sqlsearch.enabled'] = True - def test_enabled_sql_search(self): - config['ckan.datastore.sqlsearch.enabled'] = True - with p.use_plugin('datastore') as the_plugin: - p.toolkit.get_action('datastore_search_sql') +@pytest.mark.ckan_config('ckan.datastore.sqlsearch.enabled', True) +@pytest.mark.usefixtures('ckan_config') +def test_enabled_sql_search(): + with p.use_plugin('datastore') as the_plugin: + p.toolkit.get_action('datastore_search_sql') diff --git a/setup.cfg b/setup.cfg index 173a7badd56..fd3f552338e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -39,7 +39,7 @@ filterwarnings = ignore::sqlalchemy.exc.SAWarning ignore::DeprecationWarning markers = - ckan_config: patch configuration used by other fixtures via (key, value) pair. Applied only if `ckan_config` fixture is used either explicitely or implicitely(by other fixture) during the test. Consider using `@pytest.mark.usefixture('ckan_config')` + ckan_config: patch configuration used by other fixtures via (key, value) pair. Applied only if `ckan_config` fixture is used either explicitely or implicitely(by other fixture) during the test. Consider using `@pytest.mark.usefixtures('app', 'ckan_config')` ckan_pytest: test case that is explicitely was rewriten from `nose` style testpaths = ckan ckanext addopts = --strict-markers