Skip to content

Commit

Permalink
Update controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
smotornyuk committed Dec 26, 2019
1 parent deb353a commit fe5a5f1
Show file tree
Hide file tree
Showing 13 changed files with 100 additions and 105 deletions.
6 changes: 3 additions & 3 deletions .circleci/config.yml
Expand Up @@ -14,8 +14,8 @@ defaults:
createdb --encoding=utf-8 --host=ckan-postgres --username=ckan --owner=${CKAN_DATASTORE_POSTGRES_WRITE_USER} ${CKAN_DATASTORE_POSTGRES_DB}
# Database Initialization
paster datastore -c test-core-circle-ci.ini set-permissions | psql --host=ckan-postgres --username=ckan
paster db init -c test-core-circle-ci.ini
ckan -c test-core-circle-ci.ini datastore set-permissions | psql --host=ckan-postgres --username=ckan
ckan -c test-core-circle-ci.ini db init
install_deps: &install_deps
run: |
# OS Dependencies
Expand Down Expand Up @@ -48,7 +48,7 @@ defaults:
run:
command: |
case $CIRCLE_NODE_INDEX in
$NODE_TESTS_CONTAINER) paster serve test-core-circle-ci.ini
$NODE_TESTS_CONTAINER) ckan -c test-core-circle-ci.ini run
;;
esac
background: true
Expand Down
2 changes: 1 addition & 1 deletion ckan/config/middleware/flask_app.py
Expand Up @@ -346,7 +346,7 @@ def ckan_after_request(response):
response = set_cors_headers_for_response(response)

r_time = time.time() - g.__timer
url = request.environ['CKAN_CURRENT_URL'].split('?')[0]
url = request.environ['PATH_INFO']

log.info(' %s render time %.3f seconds' % (url, r_time))

Expand Down
18 changes: 5 additions & 13 deletions ckan/tests/controllers/test_admin.py
Expand Up @@ -32,7 +32,7 @@ def _reset_config(app):
app.post(url=url_for("admin.reset_config"), extra_environ=env)


@pytest.mark.usefixtures("clean_db")
@pytest.mark.usefixtures("clean_db", "with_request_context")
class TestConfig(object):
"""View tests to go along with 'Customizing look and feel' docs."""

Expand Down Expand Up @@ -95,16 +95,8 @@ def test_main_css(self, app):
"red.css" in new_index_response
or "red.min.css" in new_index_response
)
assert "main.css" not in new_index_response
assert "main.min.css" not in new_index_response

# reset config value
_reset_config(app)
reset_index_response = app.get("/")
assert (
"main.css" in reset_index_response
or "main.min.css" in reset_index_response
)
assert not helpers.body_contains(new_index_response, "main.css")
assert not helpers.body_contains(new_index_response, "main.min.css")

def test_tag_line(self, app):
"""Add a tag line (only when no logo)"""
Expand Down Expand Up @@ -235,7 +227,7 @@ def test_homepage_style(self, app):
)


@pytest.mark.usefixtures("clean_db")
@pytest.mark.usefixtures("clean_db", "with_request_context")
class TestTrashView(object):
"""View tests for permanently deleting datasets with Admin Trash."""

Expand Down Expand Up @@ -327,7 +319,7 @@ def test_trash_purge_deleted_datasets(self, app):
assert pkgs_after_purge == 1


@pytest.mark.usefixtures("clean_db")
@pytest.mark.usefixtures("clean_db", "with_request_context")
class TestAdminConfigUpdate(object):
def _update_config_option(self, app):
sysadmin = factories.Sysadmin()
Expand Down
2 changes: 1 addition & 1 deletion ckan/tests/controllers/test_api.py
Expand Up @@ -35,7 +35,7 @@ def mock_open_if_open_fails(*args, **kwargs):
return fake_open(*args, **kwargs)


@pytest.mark.usefixtures("clean_db")
@pytest.mark.usefixtures("clean_db", "with_request_context")
class TestApiController(object):
@pytest.mark.ckan_config("ckan.storage_path", "/doesnt_exist")
@mock.patch.object(ckan_uploader, "os", fake_os)
Expand Down
4 changes: 2 additions & 2 deletions ckan/tests/controllers/test_feed.py
Expand Up @@ -12,7 +12,7 @@
from webhelpers.feedgenerator import GeoAtom1Feed


@pytest.mark.usefixtures("clean_db")
@pytest.mark.usefixtures("clean_db", "with_request_context")
class TestFeeds(object):
@pytest.mark.parametrize("page", [0, -2, "abc"])
def test_atom_feed_incorrect_page_gives_error(self, page, app):
Expand Down Expand Up @@ -69,7 +69,7 @@ def test_custom_atom_feed_works(self, app):


@pytest.mark.ckan_config("ckan.plugins", "test_feed_plugin")
@pytest.mark.usefixtures("clean_db", "clean_index", "with_plugins")
@pytest.mark.usefixtures("clean_db", "clean_index", "with_plugins", "with_request_context")
class TestCustomFeedPlugin:
def test_custom_class_used(self, app):
offset = url_for(u"feeds.general")
Expand Down
23 changes: 12 additions & 11 deletions ckan/tests/controllers/test_group.py
Expand Up @@ -13,7 +13,7 @@
submit_and_follow = helpers.submit_and_follow


@pytest.mark.usefixtures("clean_db")
@pytest.mark.usefixtures("clean_db", "with_request_context")
class TestGroupController(object):
def test_bulk_process_throws_404_for_nonexistent_org(self, app):
bulk_process_url = url_for(
Expand Down Expand Up @@ -63,7 +63,7 @@ def _get_group_new_page(app):
return env, response


@pytest.mark.usefixtures("clean_db")
@pytest.mark.usefixtures("clean_db", "with_request_context")
class TestGroupControllerNew(object):
def test_not_logged_in(self, app):
app.get(url=url_for("group.new"), status=403)
Expand Down Expand Up @@ -116,7 +116,7 @@ def _get_group_edit_page(app, group_name=None):
return env, response, group_name


@pytest.mark.usefixtures("clean_db")
@pytest.mark.usefixtures("clean_db", "with_request_context")
class TestGroupControllerEdit(object):
def test_not_logged_in(self, app):
app.get(url=url_for("group.new"), status=403)
Expand Down Expand Up @@ -154,7 +154,7 @@ def test_all_fields_saved(self, app):
assert group.image_url == "http://example.com/image.png"


@pytest.mark.usefixtures("clean_db")
@pytest.mark.usefixtures("clean_db", "with_request_context")
class TestGroupRead(object):
def test_group_read(self, app):
group = factories.Group()
Expand All @@ -178,6 +178,7 @@ def test_no_redirect_loop_when_name_is_the_same_as_the_id(self, app):
app.get(url_for("group.read", id=group["id"]), status=200)


@pytest.mark.usefixtures("with_request_context")
class TestGroupDelete(object):
@pytest.fixture
def initial_data(self):
Expand Down Expand Up @@ -250,7 +251,7 @@ def test_anon_user_trying_to_delete_fails(self, app, initial_data):
assert group["state"] == "active"


@pytest.mark.usefixtures("clean_db")
@pytest.mark.usefixtures("clean_db", "with_request_context")
class TestGroupMembership(object):
def _create_group(self, owner_username, users=None):
"""Create a group with the owner defined by owner_username and
Expand Down Expand Up @@ -445,7 +446,7 @@ def test_anonymous_users_cannot_add_members(self, app):
)


@pytest.mark.usefixtures("clean_db")
@pytest.mark.usefixtures("clean_db", "with_request_context")
class TestGroupFollow:
def test_group_follow(self, app):

Expand Down Expand Up @@ -541,7 +542,7 @@ def test_group_follower_list(self, app):
assert user_one["display_name"] in followers_response


@pytest.mark.usefixtures("clean_db", "clean_index")
@pytest.mark.usefixtures("clean_db", "clean_index", "with_request_context")
class TestGroupSearch(object):
"""Test searching for groups."""

Expand Down Expand Up @@ -607,7 +608,7 @@ def test_group_search_no_results(self, app):
assert 'No groups found for "No Results Here"' in search_response


@pytest.mark.usefixtures("clean_db", "clean_index")
@pytest.mark.usefixtures("clean_db", "clean_index", "with_request_context")
class TestGroupInnerSearch(object):
"""Test searching within an group."""

Expand Down Expand Up @@ -693,7 +694,7 @@ def test_group_search_within_org_no_results(self, app):
search_form["q"] = "Nout"
search_response = webtest_submit(search_form)

assert 'No datasets found for "Nout"' in search_response.body
assert helpers.body_contains(search_response, 'No datasets found for "Nout"')

search_response_html = BeautifulSoup(search_response.body)

Expand All @@ -705,7 +706,7 @@ def test_group_search_within_org_no_results(self, app):
assert len(ds_titles) == 0


@pytest.mark.usefixtures("clean_db")
@pytest.mark.usefixtures("clean_db", "with_request_context")
class TestGroupIndex(object):
def test_group_index(self, app):

Expand Down Expand Up @@ -743,7 +744,7 @@ def test_group_index(self, app):
assert "Test Group 20" not in response


@pytest.mark.usefixtures("clean_db")
@pytest.mark.usefixtures("clean_db", "with_request_context")
class TestActivity:
def test_simple(self, app):
"""Checking the template shows the activity stream."""
Expand Down
2 changes: 2 additions & 0 deletions ckan/tests/controllers/test_home.py
Expand Up @@ -8,6 +8,7 @@
from ckan.tests import factories


@pytest.mark.usefixtures("with_request_context")
class TestHome(object):
def test_home_renders(self, app):
response = app.get(url_for("home.index"))
Expand Down Expand Up @@ -75,6 +76,7 @@ def test_map_pylons_to_flask_route_using_dict(self, app):
assert "Welcome to CKAN" in response.body


@pytest.mark.usefixtures("with_request_context")
class TestI18nURLs(object):
def test_right_urls_are_rendered_on_language_selector(self, app):

Expand Down
19 changes: 10 additions & 9 deletions ckan/tests/controllers/test_organization.py
Expand Up @@ -11,7 +11,7 @@
from ckan.tests.helpers import webtest_submit, submit_and_follow


@pytest.mark.usefixtures("clean_db")
@pytest.mark.usefixtures("clean_db", "with_request_context")
class TestOrganizationNew(object):
@pytest.fixture
def user_env(self):
Expand Down Expand Up @@ -66,6 +66,7 @@ def test_all_fields_saved(self, app, user_env):
assert group["description"] == "Sciencey datasets"


@pytest.mark.usefixtures("with_request_context")
class TestOrganizationList(object):
@patch(
"ckan.logic.auth.get.organization_list",
Expand All @@ -86,7 +87,7 @@ def test_error_message_shown_when_no_organization_list_permission(
)


@pytest.mark.usefixtures("clean_db")
@pytest.mark.usefixtures("clean_db", "with_request_context")
class TestOrganizationRead(object):
def test_group_read(self, app):
org = factories.Organization()
Expand All @@ -111,7 +112,7 @@ def test_no_redirect_loop_when_name_is_the_same_as_the_id(self, app):
) # ie no redirect


@pytest.mark.usefixtures("clean_db")
@pytest.mark.usefixtures("clean_db", "with_request_context")
class TestOrganizationEdit(object):
@pytest.fixture
def initial_data(self):
Expand Down Expand Up @@ -170,7 +171,7 @@ def test_all_fields_saved(self, app, initial_data):
assert group["image_url"] == "http://example.com/image.png"


@pytest.mark.usefixtures("clean_db")
@pytest.mark.usefixtures("clean_db", "with_request_context")
class TestOrganizationDelete(object):
@pytest.fixture
def initial_data(self):
Expand Down Expand Up @@ -290,7 +291,7 @@ def test_delete_organization_with_unknown_dataset_true(self, initial_data):
assert dataset["owner_org"] is None


@pytest.mark.usefixtures("clean_db")
@pytest.mark.usefixtures("clean_db", "with_request_context")
class TestOrganizationBulkProcess(object):
def test_make_private(self, app):
self.user = factories.User()
Expand Down Expand Up @@ -388,7 +389,7 @@ def test_delete(self, app):
assert d["state"] == "deleted"


@pytest.mark.usefixtures("clean_db")
@pytest.mark.usefixtures("clean_db", "with_request_context")
class TestOrganizationSearch(object):
"""Test searching for organizations."""

Expand Down Expand Up @@ -459,7 +460,7 @@ def test_organization_search_no_results(self, app):
)


@pytest.mark.usefixtures("clean_db", "clean_index")
@pytest.mark.usefixtures("clean_db", "clean_index", "with_request_context")
class TestOrganizationInnerSearch(object):
"""Test searching within an organization."""

Expand Down Expand Up @@ -558,7 +559,7 @@ def test_organization_search_within_org_no_results(self, app):
assert len(ds_titles) == 0


@pytest.mark.usefixtures("clean_db")
@pytest.mark.usefixtures("clean_db", "with_request_context")
class TestOrganizationMembership(object):
def test_editor_users_cannot_add_members(self, app):

Expand Down Expand Up @@ -636,7 +637,7 @@ def test_anonymous_users_cannot_add_members(self, app):
)


@pytest.mark.usefixtures("clean_db")
@pytest.mark.usefixtures("clean_db", "with_request_context")
class TestActivity(object):
def test_simple(self, app):
"""Checking the template shows the activity stream."""
Expand Down

0 comments on commit fe5a5f1

Please sign in to comment.