From e6705332fac5b0c97f6ac657887e525d9e07ca51 Mon Sep 17 00:00:00 2001 From: amercader Date: Wed, 23 Aug 2017 11:40:09 +0100 Subject: [PATCH 1/5] [#3760] Auto generate a Flask test request context when calling url_for This is an attempt to try to avoid having to explicitly generate a Flask request context on all tests that involve url_for. There are two scenarios when url_for is called outside the context of a web request: tests and CLI. The idea is to provide a fallback test request context on url_for if there isn't one available. On tests, we have the added complexity that tests can modify the configuration and plugins loaded so we can't reuse the same. This is an ugly patch, as it uses to global variables. For CLI commands there's a test request context created on `load_config`, which all commands should run on startup. For tests, the only safe place to create it is at the lowest level, on `make_app`, as soon as the environment is loaded and there is a Flask app available. Of course this only works if the tests create a test web app, but that is the most common scenario (eg `FunctionalTestBase` or any test that creates its own app). Other tests can create their own test request context if needeed. --- ckan/config/middleware/__init__.py | 9 ++++++++ ckan/lib/cli.py | 17 ++++++++++++--- ckan/lib/helpers.py | 35 ++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 3 deletions(-) diff --git a/ckan/config/middleware/__init__.py b/ckan/config/middleware/__init__.py index 0b14a8c7e05..a6ec785ce4d 100644 --- a/ckan/config/middleware/__init__.py +++ b/ckan/config/middleware/__init__.py @@ -39,6 +39,10 @@ def custom_charset__set(self, charset): # End of webob.requests.BaseRequest monkey patch +# This is a test Flask request context to be used internally. +# Do not use it! +_internal_test_request_context = None + def make_app(conf, full_stack=True, static_files=True, **app_conf): ''' @@ -55,6 +59,11 @@ def make_app(conf, full_stack=True, static_files=True, **app_conf): app = AskAppDispatcherMiddleware({'pylons_app': pylons_app, 'flask_app': flask_app}) + # Set this internal test request context with the configured environment so + # it can be used when calling url_for from tests + global _internal_test_request_context + _internal_test_request_context = flask_app._wsgi_app.test_request_context() + return app diff --git a/ckan/lib/cli.py b/ckan/lib/cli.py index 7040c8afbdd..1fbe55bc3fb 100644 --- a/ckan/lib/cli.py +++ b/ckan/lib/cli.py @@ -28,11 +28,16 @@ import ckan.include.rcssmin as rcssmin import ckan.plugins as p from ckan.common import config +from ckan.tests.helpers import _get_test_app +# This is a test Flask request context to be used internally. +# Do not use it! +_cli_test_request_context = None -#NB No CKAN imports are allowed until after the config file is loaded. -# i.e. do the imports in methods, after _load_config is called. -# Otherwise loggers get disabled. + +# NB No CKAN imports are allowed until after the config file is loaded. +# i.e. do the imports in methods, after _load_config is called. +# Otherwise loggers get disabled. def deprecation_warning(message=None): @@ -224,6 +229,12 @@ def load_config(config, load_site_user=True): from ckan.config.environment import load_environment load_environment(conf.global_conf, conf.local_conf) + # Set this internal test request context with the configured environment so + # it can be used when calling url_for from the CLI. + global _cli_test_request_context + flask_app = _get_test_app().flask_app + _cli_test_request_context = flask_app.test_request_context() + registry = Registry() registry.prepare() import pylons diff --git a/ckan/lib/helpers.py b/ckan/lib/helpers.py index a701ef5ae81..d0268cc78da 100644 --- a/ckan/lib/helpers.py +++ b/ckan/lib/helpers.py @@ -28,6 +28,7 @@ from pylons import url as _pylons_default_url from ckan.common import config, is_flask_request from flask import redirect as _flask_redirect +from flask import _request_ctx_stack, current_app from routes import redirect_to as _routes_redirect_to from routes import url_for as _routes_default_url_for from flask import url_for as _flask_default_url_for @@ -201,6 +202,30 @@ def get_site_protocol_and_host(): return (None, None) +def _get_auto_flask_context(): + ''' + Provides a Flask test request context if we are outside the context + of a web request (tests or CLI) + ''' + + from ckan.config.middleware import _internal_test_request_context + from ckan.lib.cli import _cli_test_request_context + + # This is a normal web request, there is a request context present + if _request_ctx_stack.top: + return None + + # We are outside a web request. A test web application was created + # (and with it a test request context with the relevant configuration) + if _internal_test_request_context: + return _internal_test_request_context + + # We are outside a web request. This is a CLI command. A test request + # context was created when setting it up + if _cli_test_request_context: + return _cli_test_request_context + + @core_helper def url_for(*args, **kw): '''Return the URL for an endpoint given some parameters. @@ -252,13 +277,23 @@ def url_for(*args, **kw): ver = kw.get('ver') if not ver: raise Exception('API URLs must specify the version (eg ver=3)') + + _auto_flask_context = _get_auto_flask_context() + try: + if _auto_flask_context: + _auto_flask_context.push() + # First try to build the URL with the Flask router my_url = _url_for_flask(*args, **kw) except FlaskRouteBuildError: + # If it doesn't succeed, fallback to the Pylons router my_url = _url_for_pylons(*args, **kw) + finally: + if _auto_flask_context: + _auto_flask_context.pop() # Add back internal params kw['__ckan_no_root'] = no_root From 88711e9a3c2f0f9a772cf646570a95f33165f642 Mon Sep 17 00:00:00 2001 From: amercader Date: Wed, 23 Aug 2017 11:56:53 +0100 Subject: [PATCH 2/5] Revert "[#3196] Fix legacy tests dependant on url_for" This reverts commit 2d83e0d1366a76c8f83fd316301b9976f38fab62. --- ckan/tests/controllers/test_package.py | 4 +- ckan/tests/legacy/__init__.py | 5 +- ckan/tests/legacy/functional/api/base.py | 2 +- .../functional/api/model/test_package.py | 23 ++-- .../api/model/test_relationships.py | 16 +-- .../functional/api/model/test_vocabulary.py | 6 +- .../legacy/functional/api/test_activity.py | 4 +- .../legacy/functional/api/test_dashboard.py | 4 +- .../api/test_email_notifications.py | 13 ++- .../legacy/functional/api/test_follow.py | 8 +- .../legacy/functional/api/test_resource.py | 4 +- ckan/tests/legacy/functional/api/test_user.py | 29 ++--- ckan/tests/legacy/functional/api/test_util.py | 62 +++-------- ckan/tests/legacy/functional/test_activity.py | 14 +-- ckan/tests/legacy/functional/test_admin.py | 3 +- ckan/tests/legacy/functional/test_group.py | 14 +-- ckan/tests/legacy/functional/test_package.py | 66 +++-------- .../legacy/functional/test_pagination.py | 47 ++------ .../functional/test_preview_interface.py | 32 +++--- ckan/tests/legacy/functional/test_revision.py | 12 +- ckan/tests/legacy/functional/test_tag.py | 25 +---- ckan/tests/legacy/functional/test_tracking.py | 54 +++------ ckan/tests/legacy/functional/test_user.py | 49 +++------ ckan/tests/legacy/html_check.py | 10 +- .../legacy/lib/test_alphabet_pagination.py | 5 +- ckan/tests/legacy/logic/test_action.py | 23 ++-- ckan/tests/legacy/logic/test_auth.py | 7 +- ckan/tests/legacy/misc/test_format_text.py | 103 +++++------------- ckan/tests/legacy/models/test_package.py | 9 +- ckan/tests/legacy/test_coding_standards.py | 2 +- 30 files changed, 200 insertions(+), 455 deletions(-) diff --git a/ckan/tests/controllers/test_package.py b/ckan/tests/controllers/test_package.py index 5421c605d70..845bd3d45c3 100644 --- a/ckan/tests/controllers/test_package.py +++ b/ckan/tests/controllers/test_package.py @@ -734,7 +734,7 @@ def test_delete_on_non_existing_dataset(self): with app.flask_app.test_request_context(): url = url_for(controller='package', action='delete', - id='schrodingersdatset') + id='schrodingersdatset') response = app.post( url, @@ -1857,7 +1857,7 @@ def test_package_unfollow(self): with app.flask_app.test_request_context(): follow_url = url_for(controller='package', - action='follow', + action='follow', id=package['id']) app.post(follow_url, extra_environ=env, status=302) diff --git a/ckan/tests/legacy/__init__.py b/ckan/tests/legacy/__init__.py index a647c147899..3a056855f95 100644 --- a/ckan/tests/legacy/__init__.py +++ b/ckan/tests/legacy/__init__.py @@ -35,7 +35,6 @@ import ckan.model as model from ckan import ckan_nose_plugin from ckan.common import json -from ckan.tests import helpers # evil hack as url_for is passed out url_for = h.url_for @@ -238,8 +237,7 @@ class WsgiAppCase(BaseCase): # Either that, or this file got imported somehow before the tests started # running, meaning the pylonsapp wasn't setup yet (which is done in # pylons.test.py:begin()) - #app = paste.fixture.TestApp(wsgiapp) - app = helpers._get_test_app() + app = paste.fixture.TestApp(wsgiapp) def config_abspath(file_path): @@ -417,7 +415,6 @@ def call_action_api(app, action, apikey=None, status=200, **kwargs): params = json.dumps(kwargs) response = app.post('/api/action/{0}'.format(action), params=params, extra_environ={'Authorization': str(apikey)}, status=status) - assert '/api/3/action/help_show?name={0}'.format(action) \ in response.json['help'] diff --git a/ckan/tests/legacy/functional/api/base.py b/ckan/tests/legacy/functional/api/base.py index 6278e95077a..98c704ee979 100644 --- a/ckan/tests/legacy/functional/api/base.py +++ b/ckan/tests/legacy/functional/api/base.py @@ -190,7 +190,7 @@ def loads(self, chars): raise Exception, "Couldn't loads string '%s': %s" % (chars, inst) def assert_json_response(self, res, expected_in_body=None): - content_type = res.headers['Content-Type'] + content_type = res.header_dict['Content-Type'] assert 'application/json' in content_type, content_type res_json = self.loads(res.body) if expected_in_body: diff --git a/ckan/tests/legacy/functional/api/model/test_package.py b/ckan/tests/legacy/functional/api/model/test_package.py index 593f49d7612..22472d7dac3 100644 --- a/ckan/tests/legacy/functional/api/model/test_package.py +++ b/ckan/tests/legacy/functional/api/model/test_package.py @@ -13,7 +13,6 @@ from ckan.tests.legacy.functional.api.base import Api2TestCase as Version2TestCase import ckan.tests.legacy as tests -from ckan.tests import helpers # Todo: Remove this ckan.model stuff. import ckan.model as model @@ -66,7 +65,7 @@ def test_register_post_ok(self): assert_equal(pkg['extras'], self.package_fixture_data['extras']) # Check the value of the Location header. - location = res.headers['Location'] + location = res.header('Location') assert offset in location res = self.app.get(location, status=self.STATUS_200_OK) @@ -134,7 +133,7 @@ def test_register_post_with_group(self): package_fixture_data = self.package_fixture_data package_fixture_data['groups'] = groups data = self.dumps(package_fixture_data) - res = self.app.post(offset, data, status=self.STATUS_201_CREATED, + res = self.post_json(offset, data, status=self.STATUS_201_CREATED, extra_environ={'Authorization':str(user.apikey)}) # Check the database record. @@ -160,7 +159,7 @@ def test_register_post_with_group_not_authorized(self): package_fixture_data = self.package_fixture_data package_fixture_data['groups'] = groups data = self.dumps(package_fixture_data) - res = self.app.post(offset, data, status=self.STATUS_403_ACCESS_DENIED, + res = self.post_json(offset, data, status=self.STATUS_403_ACCESS_DENIED, extra_environ=self.extra_environ) del package_fixture_data['groups'] @@ -174,7 +173,7 @@ def test_register_post_with_group_not_found(self): package_fixture_data = self.package_fixture_data package_fixture_data['groups'] = groups data = self.dumps(package_fixture_data) - res = self.app.post(offset, data, status=self.STATUS_404_NOT_FOUND, + res = self.post_json(offset, data, status=self.STATUS_404_NOT_FOUND, extra_environ=self.extra_environ) del package_fixture_data['groups'] @@ -188,7 +187,7 @@ def test_register_post_with_group_sysadmin(self): package_fixture_data = self.package_fixture_data package_fixture_data['groups'] = groups data = self.dumps(package_fixture_data) - res = self.app.post(offset, data, status=self.STATUS_201_CREATED, + res = self.post_json(offset, data, status=self.STATUS_201_CREATED, extra_environ={'Authorization':str(user.apikey)}) # Check the database record. model.Session.remove() @@ -208,7 +207,7 @@ def test_register_post_json(self): assert not self.get_package_by_name(self.package_fixture_data['name']) offset = self.package_offset() data = self.dumps(self.package_fixture_data) - res = self.app.post(offset, data, status=self.STATUS_201_CREATED, + res = self.post_json(offset, data, status=self.STATUS_201_CREATED, extra_environ=self.admin_extra_environ) # Check the database record. model.Session.remove() @@ -220,7 +219,7 @@ def test_register_post_bad_content_type(self): assert not self.get_package_by_name(self.package_fixture_data['name']) offset = self.package_offset() data = self.dumps(self.package_fixture_data) - res = self.app.post(offset, data, + res = self.http_request(offset, data, content_type='something/unheard_of', status=[self.STATUS_400_BAD_REQUEST, self.STATUS_201_CREATED], @@ -263,7 +262,7 @@ def test_register_post_indexerror(self): offset = self.package_offset() data = self.dumps(self.package_fixture_data) - self.app.post(offset, data, status=500, extra_environ=self.admin_extra_environ) + self.post_json(offset, data, status=500, extra_environ=self.admin_extra_environ) model.Session.remove() finally: SolrSettings.init(original_settings) @@ -274,7 +273,7 @@ def test_register_post_tag_too_long(self): assert not self.get_package_by_name(pkg['name']) offset = self.package_offset() data = self.dumps(pkg) - res = self.app.post(offset, data, status=self.STATUS_409_CONFLICT, + res = self.post_json(offset, data, status=self.STATUS_409_CONFLICT, extra_environ=self.admin_extra_environ) assert 'length is more than maximum 100' in res.body, res.body assert 'tagok' not in res.body @@ -715,8 +714,8 @@ def test_entity_delete_ok_without_request_headers(self): assert self.get_package_by_name(self.package_fixture_data['name']) # delete it offset = self.package_offset(self.package_fixture_data['name']) - res = self.app.delete(offset, status=self.STATUS_200_OK, - extra_environ=self.admin_extra_environ) + res = self.delete_request(offset, status=self.STATUS_200_OK, + extra_environ=self.admin_extra_environ) package = self.get_package_by_name(self.package_fixture_data['name']) self.assert_equal(package.state, 'deleted') model.Session.remove() diff --git a/ckan/tests/legacy/functional/api/model/test_relationships.py b/ckan/tests/legacy/functional/api/model/test_relationships.py index 069776d663d..0bdc30c84e5 100644 --- a/ckan/tests/legacy/functional/api/model/test_relationships.py +++ b/ckan/tests/legacy/functional/api/model/test_relationships.py @@ -1,14 +1,14 @@ # encoding: utf-8 -from nose.tools import assert_equal +from nose.tools import assert_equal from nose.plugins.skip import SkipTest from ckan import model from ckan.lib.create_test_data import CreateTestData from ckan.tests.legacy.functional.api.base import BaseModelApiTestCase -from ckan.tests.legacy.functional.api.base import Api1TestCase as Version1TestCase -from ckan.tests.legacy.functional.api.base import Api2TestCase as Version2TestCase +from ckan.tests.legacy.functional.api.base import Api1TestCase as Version1TestCase +from ckan.tests.legacy.functional.api.base import Api2TestCase as Version2TestCase class RelationshipsTestCase(BaseModelApiTestCase): @@ -115,7 +115,7 @@ def test_01_create_and_read_relationship(self): assert len(rels) == 1 self.check_relationship_dict(rels[0], 'annakarenina', 'parent_of', 'warandpeace', self.comment) - + def test_02_create_relationship_way_2(self): # Create a relationship using 2nd way self.create_annakarenina_parent_of_war_and_peace(way=2) @@ -189,7 +189,7 @@ def test_create_relationship_unknown(self): def create_annakarenina_parent_of_war_and_peace(self, way=1): # Create package relationship. # More than one 'way' to create a package. - # Todo: Redesign this in a RESTful style, so that a relationship is + # Todo: Redesign this in a RESTful style, so that a relationship is # created by posting a relationship to a relationship **register**. assert way in (1, 2, 3, 4) if way == 1: @@ -220,7 +220,7 @@ def create_annakarenina_parent_of_war_and_peace(self, way=1): assert_equal(rel['type'], 'child_of') assert_equal(rel['subject'], self.ref_package(self.war)) assert_equal(rel['object'], self.ref_package(self.anna)) - + # Check the model, directly. rels = self.anna.get_relationships() assert len(rels) == 1, rels @@ -271,7 +271,7 @@ def get_relationships(self, package1_name=u'annakarenina', type='relationships', if type: allowable_statuses.append(404) res = self.app.get(offset, status=allowable_statuses) - if res.status_int == 200: + if res.status == 200: res_dict = self.data_from_res(res) if res.body else [] return res_dict else: @@ -300,7 +300,7 @@ def check_relationships_rest(self, pkg1_name, pkg2_name=None, expected_relationships=[]): rels = self.get_relationships(package1_name=pkg1_name, package2_name=pkg2_name) - self.assert_len_relationships(rels, expected_relationships) + self.assert_len_relationships(rels, expected_relationships) for rel in rels: the_expected_rel = None for expected_rel in expected_relationships: diff --git a/ckan/tests/legacy/functional/api/model/test_vocabulary.py b/ckan/tests/legacy/functional/api/model/test_vocabulary.py index ab6bb25f6f2..feb03af3717 100644 --- a/ckan/tests/legacy/functional/api/model/test_vocabulary.py +++ b/ckan/tests/legacy/functional/api/model/test_vocabulary.py @@ -1,17 +1,17 @@ # encoding: utf-8 import ckan +import pylons.test +import paste.fixture import ckan.lib.helpers as helpers import ckan.lib.dictization.model_dictize as model_dictize -from ckan.tests import helpers as test_helpers - class TestVocabulary(object): @classmethod def setup_class(self): - self.app = test_helpers._get_test_app() + self.app = paste.fixture.TestApp(pylons.test.pylonsapp) @classmethod def teardown_class(self): diff --git a/ckan/tests/legacy/functional/api/test_activity.py b/ckan/tests/legacy/functional/api/test_activity.py index 571c8ae4701..ffb9834de08 100644 --- a/ckan/tests/legacy/functional/api/test_activity.py +++ b/ckan/tests/legacy/functional/api/test_activity.py @@ -23,8 +23,6 @@ import ckan.tests.legacy as tests from ckan.tests.helpers import call_action -from ckan.tests import helpers - ##def package_update(context, data_dict): ## # These tests call package_update directly which is really bad @@ -208,7 +206,7 @@ def setup_class(self): 'id': annakarenina.id, } self.users = [self.sysadmin_user, self.normal_user] - self.app = helpers._get_test_app() + self.app = paste.fixture.TestApp(pylons.test.pylonsapp) @classmethod def teardown_class(self): diff --git a/ckan/tests/legacy/functional/api/test_dashboard.py b/ckan/tests/legacy/functional/api/test_dashboard.py index e3a7c4b521e..1dec5c9cbd2 100644 --- a/ckan/tests/legacy/functional/api/test_dashboard.py +++ b/ckan/tests/legacy/functional/api/test_dashboard.py @@ -12,8 +12,6 @@ import paste import pylons.test from ckan.tests.legacy import CreateTestData -from ckan.tests import helpers - class TestDashboard(object): '''Tests for the logic action functions related to the user's dashboard.''' @@ -37,7 +35,7 @@ def setup_class(cls): ckan.model.repo.rebuild_db() ckan.lib.search.clear_all() CreateTestData.create() - cls.app = helpers._get_test_app() + cls.app = paste.fixture.TestApp(pylons.test.pylonsapp) joeadmin = ckan.model.User.get('joeadmin') cls.joeadmin = { 'id': joeadmin.id, diff --git a/ckan/tests/legacy/functional/api/test_email_notifications.py b/ckan/tests/legacy/functional/api/test_email_notifications.py index 8ecee84a549..cfc5d417395 100644 --- a/ckan/tests/legacy/functional/api/test_email_notifications.py +++ b/ckan/tests/legacy/functional/api/test_email_notifications.py @@ -10,12 +10,13 @@ import ckan.tests.legacy.pylons_controller as pylons_controller import ckan.config.middleware -from ckan.tests import helpers +import paste +import paste.deploy +import pylons.test from ckan.common import config - class TestEmailNotifications(mock_mail_server.SmtpServerHarness, pylons_controller.PylonsTestCase): @@ -24,7 +25,7 @@ def setup_class(cls): mock_mail_server.SmtpServerHarness.setup_class() pylons_controller.PylonsTestCase.setup_class() tests.CreateTestData.create() - cls.app = helpers._get_test_app() + cls.app = paste.fixture.TestApp(pylons.test.pylonsapp) joeadmin = model.User.get('joeadmin') cls.joeadmin = {'id': joeadmin.id, 'apikey': joeadmin.apikey, @@ -197,7 +198,7 @@ def setup_class(cls): mock_mail_server.SmtpServerHarness.setup_class() pylons_controller.PylonsTestCase.setup_class() tests.CreateTestData.create() - cls.app = helpers._get_test_app() + cls.app = paste.fixture.TestApp(pylons.test.pylonsapp) joeadmin = model.User.get('joeadmin') cls.joeadmin = {'id': joeadmin.id, 'apikey': joeadmin.apikey, @@ -337,7 +338,7 @@ def setup_class(cls): wsgiapp = ckan.config.middleware.make_app(config['global_conf'], **config) - cls.app = helpers._get_test_app() + cls.app = paste.fixture.TestApp(wsgiapp) mock_mail_server.SmtpServerHarness.setup_class() pylons_controller.PylonsTestCase.setup_class() @@ -421,7 +422,7 @@ def setup_class(cls): wsgiapp = ckan.config.middleware.make_app(config['global_conf'], **config) - cls.app = helpers._get_test_app() + cls.app = paste.fixture.TestApp(wsgiapp) mock_mail_server.SmtpServerHarness.setup_class() pylons_controller.PylonsTestCase.setup_class() diff --git a/ckan/tests/legacy/functional/api/test_follow.py b/ckan/tests/legacy/functional/api/test_follow.py index 98f4bd23073..909b2e77606 100644 --- a/ckan/tests/legacy/functional/api/test_follow.py +++ b/ckan/tests/legacy/functional/api/test_follow.py @@ -18,8 +18,6 @@ import ckan from ckan.tests.legacy import are_foreign_keys_supported, SkipTest, CreateTestData, call_action_api -from ckan.tests import helpers - def datetime_from_string(s): '''Return a standard datetime.datetime object initialised from a string in @@ -297,7 +295,7 @@ def setup_class(self): 'id': ckan.model.Group.get('david').id, 'name': ckan.model.Group.get('david').name, } - self.app = helpers._get_test_app() + self.app = paste.fixture.TestApp(pylons.test.pylonsapp) @classmethod def teardown_class(self): @@ -806,7 +804,7 @@ def setup_class(self): 'id': ckan.model.Group.get('david').id, 'name': ckan.model.Group.get('david').name, } - self.app = helpers._get_test_app() + self.app = paste.fixture.TestApp(pylons.test.pylonsapp) follow_user(self.app, self.testsysadmin['id'], self.testsysadmin['apikey'], self.joeadmin['id'], self.joeadmin['id'], self.testsysadmin['apikey']) @@ -1156,7 +1154,7 @@ def setup_class(self): 'id': ckan.model.Group.get('david').id, 'name': ckan.model.Group.get('david').name, } - self.app = helpers._get_test_app() + self.app = paste.fixture.TestApp(pylons.test.pylonsapp) follow_user(self.app, self.joeadmin['id'], self.joeadmin['apikey'], self.testsysadmin['id'], self.testsysadmin['id'], diff --git a/ckan/tests/legacy/functional/api/test_resource.py b/ckan/tests/legacy/functional/api/test_resource.py index 28c3a6bed15..e8c53593bcd 100644 --- a/ckan/tests/legacy/functional/api/test_resource.py +++ b/ckan/tests/legacy/functional/api/test_resource.py @@ -45,7 +45,7 @@ def teardown_class(self): def test_good_input(self): offset = self.base_url + '/format_autocomplete?incomplete=cs' result = self.app.get(offset, status=200) - content_type = result.headers['Content-Type'] + content_type = result.header_dict['Content-Type'] assert 'application/json' in content_type, content_type res_json = self.loads(result.body) assert 'ResultSet' in res_json, res_json @@ -58,7 +58,7 @@ def test_good_input(self): def test_missing_format(self): offset = self.base_url + '/format_autocomplete?incomplete=incorrectformat' result = self.app.get(offset, status=200) - content_type = result.headers['Content-Type'] + content_type = result.header_dict['Content-Type'] assert 'application/json' in content_type, content_type res_json = self.loads(result.body) assert 'ResultSet' in res_json, res_json diff --git a/ckan/tests/legacy/functional/api/test_user.py b/ckan/tests/legacy/functional/api/test_user.py index 3096a9f9cff..c2718fc1bdc 100644 --- a/ckan/tests/legacy/functional/api/test_user.py +++ b/ckan/tests/legacy/functional/api/test_user.py @@ -13,7 +13,6 @@ from ckan.tests.legacy import url_for import ckan.config.middleware from ckan.common import json -from ckan.tests import helpers class TestUserApi(ControllerTestCase): @@ -26,12 +25,8 @@ def teardown_class(cls): model.repo.rebuild_db() def test_autocomplete(self): - - with self.app.flask_app.test_request_context(): - url = url_for(controller='api', action='user_autocomplete', ver=2) - response = self.app.get( - url, + url=url_for(controller='api', action='user_autocomplete', ver=2), params={ 'q': u'sysadmin', }, @@ -40,15 +35,11 @@ def test_autocomplete(self): print response.json assert set(response.json[0].keys()) == set(['id', 'name', 'fullname']) assert_equal(response.json[0]['name'], u'testsysadmin') - assert_equal(response.headers['Content-Type'], 'application/json;charset=utf-8') + assert_equal(response.header('Content-Type'), 'application/json;charset=utf-8') def test_autocomplete_multiple(self): - - with self.app.flask_app.test_request_context(): - url = url_for(controller='api', action='user_autocomplete', ver=2) - response = self.app.get( - url, + url=url_for(controller='api', action='user_autocomplete', ver=2), params={ 'q': u'tes', }, @@ -58,12 +49,8 @@ def test_autocomplete_multiple(self): assert_equal(len(response.json), 2) def test_autocomplete_limit(self): - - with self.app.flask_app.test_request_context(): - url = url_for(controller='api', action='user_autocomplete', ver=2) - response = self.app.get( - url, + url=url_for(controller='api', action='user_autocomplete', ver=2), params={ 'q': u'tes', 'limit': 1 @@ -85,7 +72,7 @@ def setup_class(cls): cls._original_config = config.copy() wsgiapp = ckan.config.middleware.make_app( config['global_conf'], **config) - cls.app = helpers._get_test_app() + cls.app = paste.fixture.TestApp(wsgiapp) cls.sysadmin_user = model.User.get('testsysadmin') PylonsTestCase.setup_class() @@ -135,7 +122,7 @@ def setup_class(cls): config['ckan.auth.create_user_via_api'] = True wsgiapp = ckan.config.middleware.make_app( config['global_conf'], **config) - cls.app = helpers._get_test_app() + cls.app = paste.fixture.TestApp(wsgiapp) PylonsTestCase.setup_class() cls.sysadmin_user = model.User.get('testsysadmin') @@ -183,7 +170,7 @@ def setup_class(cls): config['ckan.auth.create_user_via_web'] = False wsgiapp = ckan.config.middleware.make_app( config['global_conf'], **config) - cls.app = helpers._get_test_app() + cls.app = paste.fixture.TestApp(wsgiapp) cls.sysadmin_user = model.User.get('testsysadmin') PylonsTestCase.setup_class() @@ -219,7 +206,7 @@ def setup_class(cls): config['ckan.auth.create_user_via_web'] = True wsgiapp = ckan.config.middleware.make_app( config['global_conf'], **config) - cls.app = helpers._get_test_app() + cls.app = paste.fixture.TestApp(wsgiapp) cls.sysadmin_user = model.User.get('testsysadmin') PylonsTestCase.setup_class() diff --git a/ckan/tests/legacy/functional/api/test_util.py b/ckan/tests/legacy/functional/api/test_util.py index 9065d00e7da..9ba2adb9afe 100644 --- a/ckan/tests/legacy/functional/api/test_util.py +++ b/ckan/tests/legacy/functional/api/test_util.py @@ -18,12 +18,8 @@ def teardown_class(cls): model.repo.rebuild_db() def test_package_slug_invalid(self): - - with self.app.flask_app.test_request_context(): - url = url_for(controller='api', action='is_slug_valid', ver=2) - response = self.app.get( - url, + url=url_for(controller='api', action='is_slug_valid', ver=2), params={ 'type': u'package', 'slug': u'edit', @@ -31,14 +27,10 @@ def test_package_slug_invalid(self): status=200, ) assert_equal(response.body, '{"valid": false}') - assert_equal(response.headers['Content-Type'], 'application/json;charset=utf-8') - - - with self.app.flask_app.test_request_context(): - url = url_for(controller='api', action='is_slug_valid', ver=2) + assert_equal(response.header('Content-Type'), 'application/json;charset=utf-8') response = self.app.get( - url, + url=url_for(controller='api', action='is_slug_valid', ver=2), params={ 'type': u'package', 'slug': u'new', @@ -46,15 +38,11 @@ def test_package_slug_invalid(self): status=200, ) assert_equal(response.body, '{"valid": false}') - assert_equal(response.headers['Content-Type'], 'application/json;charset=utf-8') + assert_equal(response.header('Content-Type'), 'application/json;charset=utf-8') def test_package_slug_valid(self): - - with self.app.flask_app.test_request_context(): - url = url_for(controller='api', action='is_slug_valid', ver=2) - response = self.app.get( - url, + url=url_for(controller='api', action='is_slug_valid', ver=2), params={ 'type': u'package', 'slug': u'A New Title * With & Funny CHARacters', @@ -62,14 +50,10 @@ def test_package_slug_valid(self): status=200, ) assert_equal(response.body, '{"valid": true}') - assert_equal(response.headers['Content-Type'], 'application/json;charset=utf-8') - - - with self.app.flask_app.test_request_context(): - url = url_for(controller='api', action='is_slug_valid', ver=2) + assert_equal(response.header('Content-Type'), 'application/json;charset=utf-8') response = self.app.get( - url, + url=url_for(controller='api', action='is_slug_valid', ver=2), params={ 'type': u'package', 'slug': u'warandpeace', @@ -77,64 +61,44 @@ def test_package_slug_valid(self): status=200, ) assert_equal(response.body, '{"valid": false}') - assert_equal(response.headers['Content-Type'], 'application/json;charset=utf-8') + assert_equal(response.header('Content-Type'), 'application/json;charset=utf-8') def test_markdown(self): markdown = '''##Title''' - - with self.app.flask_app.test_request_context(): - url = url_for(controller='api', action='markdown', ver=2) - response = self.app.get( - url, + url=url_for(controller='api', action='markdown', ver=2), params={'q': markdown}, status=200, ) assert_equal(response.body, '"

Title

"') def test_munge_package_name(self): - - with self.app.flask_app.test_request_context(): - url = url_for(controller='api', action='munge_package_name', ver=2) - response = self.app.get( - url, + url=url_for(controller='api', action='munge_package_name', ver=2), params={'name': 'test name'}, status=200, ) assert_equal(response.body, '"test-name"') def test_munge_title_to_package_name(self): - - with self.app.flask_app.test_request_context(): - url = url_for(controller='api', action='munge_title_to_package_name', ver=2) - response = self.app.get( - url, + url=url_for(controller='api', action='munge_title_to_package_name', ver=2), params={'name': 'Test title'}, status=200, ) assert_equal(response.body, '"test-title"') def test_munge_tag(self): - - with self.app.flask_app.test_request_context(): - url = url_for(controller='api', action='munge_tag', ver=2) - response = self.app.get( - url, + url=url_for(controller='api', action='munge_tag', ver=2), params={'name': 'Test subject'}, status=200, ) assert_equal(response.body, '"test-subject"') def test_status(self): - - with self.app.flask_app.test_request_context(): - url = url_for(controller='api', action='status', ver=2) - response = self.app.get( - url, + url=url_for(controller='api', action='status', ver=2), params={}, status=200, ) diff --git a/ckan/tests/legacy/functional/test_activity.py b/ckan/tests/legacy/functional/test_activity.py index 49e228a7d87..e6aa85fc843 100644 --- a/ckan/tests/legacy/functional/test_activity.py +++ b/ckan/tests/legacy/functional/test_activity.py @@ -14,10 +14,9 @@ from ckan.logic.action.update import user_update, group_update from ckan.logic.action.delete import package_delete from ckan.tests.legacy.html_check import HtmlCheckMethods -from ckan.tests.legacy import CreateTestData, WsgiAppCase +from ckan.tests.legacy import CreateTestData - -class TestActivity(WsgiAppCase, HtmlCheckMethods): +class TestActivity(HtmlCheckMethods): """Test the rendering of activity streams into HTML pages. Activity streams are tested in detail elsewhere, this class just briefly @@ -30,6 +29,7 @@ def setup(cls): raise SkipTest('Activity streams not enabled') CreateTestData.create() cls.sysadmin_user = ckan.model.User.get('testsysadmin') + cls.app = paste.fixture.TestApp(pylonsapp) @classmethod def teardown(cls): @@ -52,9 +52,7 @@ def test_user_activity(self): 'allow_partial_update': True, } user = user_create(context, user_dict) - - with self.app.flask_app.test_request_context(): - offset = url_for(controller='user', action='activity', id=user['id']) + offset = url_for(controller='user', action='activity', id=user['id']) result = self.app.get(offset, status=200) stripped = self.strip_tags(result) assert '%s signed up' % user['fullname'] in stripped, stripped @@ -241,9 +239,7 @@ def test_user_activity(self): # The user's dashboard page should load successfully and have the # latest 15 activities on it. - - with self.app.flask_app.test_request_context(): - offset = url_for(controller='user', action='dashboard') + offset = url_for(controller='user', action='dashboard') extra_environ = {'Authorization': str(ckan.model.User.get('billybeane').apikey)} result = self.app.post(offset, extra_environ=extra_environ, diff --git a/ckan/tests/legacy/functional/test_admin.py b/ckan/tests/legacy/functional/test_admin.py index 41ba685fc38..7737f036650 100644 --- a/ckan/tests/legacy/functional/test_admin.py +++ b/ckan/tests/legacy/functional/test_admin.py @@ -15,8 +15,7 @@ def teardown_class(self): #test that only sysadmins can access the /ckan-admin page def test_index(self): - with self.app.flask_app.test_request_context(): - url = url_for('ckanadmin', action='index') + url = url_for('ckanadmin', action='index') response = self.app.get(url, status=[403]) # random username response = self.app.get(url, status=[403], diff --git a/ckan/tests/legacy/functional/test_group.py b/ckan/tests/legacy/functional/test_group.py index 1e952879ad1..0223375f232 100644 --- a/ckan/tests/legacy/functional/test_group.py +++ b/ckan/tests/legacy/functional/test_group.py @@ -95,9 +95,7 @@ def test_sorting(self): def test_read_non_existent(self): name = u'group_does_not_exist' - - with self.app.flask_app.test_request_context(): - offset = url_for(controller='group', action='read', id=name) + offset = url_for(controller='group', action='read', id=name) res = self.app.get(offset, status=404) @@ -133,10 +131,8 @@ def teardown_class(self): model.repo.rebuild_db() def test_2_atom_feed(self): - - with self.app.flask_app.test_request_context(): - offset = url_for(controller='group', action='history', - id=self.grp.name) + offset = url_for(controller='group', action='history', + id=self.grp.name) offset = "%s?format=atom" % offset res = self.app.get(offset) assert ']') # edit the package - - with self.app.flask_app.test_request_context(): - self.offset = url_for(controller='package', action='edit', id=self.editpkg_name) + self.offset = url_for(controller='package', action='edit', id=self.editpkg_name) self.res = self.app.get(self.offset, extra_environ=self.extra_environ_admin) fv = self.res.forms['dataset-edit'] fv['title'] = u'New Title' @@ -564,8 +547,7 @@ def test_delete(self): plugins.load('test_package_controller_plugin') plugin = plugins.get_plugin('test_package_controller_plugin') - with self.app.flask_app.test_request_context(): - offset = url_for(controller='package', action='delete', + offset = url_for(controller='package', action='delete', id='warandpeace') # Since organizations, any owned dataset can be edited/deleted by any # user @@ -600,9 +582,7 @@ def teardown_class(self): def test_new_plugin_hook(self): plugins.load('test_package_controller_plugin') plugin = plugins.get_plugin('test_package_controller_plugin') - - with self.app.flask_app.test_request_context(): - offset = url_for(controller='package', action='new') + offset = url_for(controller='package', action='new') res = self.app.get(offset, extra_environ=self.extra_environ_tester) new_name = u'plugged' fv = res.forms['dataset-edit'] @@ -617,9 +597,7 @@ def test_new_plugin_hook(self): def test_after_create_plugin_hook(self): plugins.load('test_package_controller_plugin') plugin = plugins.get_plugin('test_package_controller_plugin') - - with self.app.flask_app.test_request_context(): - offset = url_for(controller='package', action='new') + offset = url_for(controller='package', action='new') res = self.app.get(offset, extra_environ=self.extra_environ_tester) new_name = u'plugged2' fv = res.forms['dataset-edit'] @@ -639,8 +617,8 @@ def test_new_indexerror(self): try: SolrSettings.init(bad_solr_url) new_package_name = u'new-package-missing-solr' - with self.app.flask_app.test_request_context(): - offset = url_for(controller='package', action='new') + + offset = url_for(controller='package', action='new') res = self.app.get(offset, extra_environ=self.extra_environ_tester) fv = res.forms['dataset-edit'] fv['name'] = new_package_name @@ -655,9 +633,7 @@ def test_new_indexerror(self): SolrSettings.init(solr_url) def test_change_locale(self): - - with self.app.flask_app.test_request_context(): - offset = url_for(controller='package', action='new') + offset = url_for(controller='package', action='new') res = self.app.get(offset, extra_environ=self.extra_environ_tester) res = self.app.get('/de/dataset/new', extra_environ=self.extra_environ_tester) @@ -707,16 +683,12 @@ def teardown_class(self): model.repo.rebuild_db() def test_read(self): - - with self.app.flask_app.test_request_context(): - offset = url_for(controller='package', action='read', id=self.non_active_name) + offset = url_for(controller='package', action='read', id=self.non_active_name) res = self.app.get(offset, status=[404]) def test_read_as_admin(self): - - with self.app.flask_app.test_request_context(): - offset = url_for(controller='package', action='read', id=self.non_active_name) + offset = url_for(controller='package', action='read', id=self.non_active_name) res = self.app.get(offset, status=200, extra_environ={'REMOTE_USER':'testsysadmin'}) @@ -746,9 +718,7 @@ def setup_class(cls): cls.revision_ids = [rev[0].id for rev in cls.pkg1.all_related_revisions] # revision ids are newest first cls.revision_timestamps = [rev[0].timestamp for rev in cls.pkg1.all_related_revisions] - - with cls.app.flask_app.test_request_context(): - cls.offset = url_for(controller='package', action='history', id=cls.pkg1.name) + cls.offset = url_for(controller='package', action='history', id=cls.pkg1.name) @classmethod def teardown_class(cls): diff --git a/ckan/tests/legacy/functional/test_pagination.py b/ckan/tests/legacy/functional/test_pagination.py index 3a4fc7912c7..596bc5fa453 100644 --- a/ckan/tests/legacy/functional/test_pagination.py +++ b/ckan/tests/legacy/functional/test_pagination.py @@ -59,41 +59,25 @@ def teardown_class(self): model.repo.rebuild_db() def test_package_search_p1(self): - - with self.app.flask_app.test_request_context(): - url = url_for(controller='package', action='search', q='groups:group_00') - - res = self.app.get(url) + res = self.app.get(url_for(controller='package', action='search', q='groups:group_00')) assert 'href="/dataset?q=groups%3Agroup_00&page=2"' in res pkg_numbers = scrape_search_results(res, 'dataset') assert_equal(['50', '49', '48', '47', '46', '45', '44', '43', '42', '41', '40', '39', '38', '37', '36', '35', '34', '33', '32', '31'], pkg_numbers) def test_package_search_p2(self): - - with self.app.flask_app.test_request_context(): - url = url_for(controller='package', action='search', q='groups:group_00', page=2) - - res = self.app.get(url) + res = self.app.get(url_for(controller='package', action='search', q='groups:group_00', page=2)) assert 'href="/dataset?q=groups%3Agroup_00&page=1"' in res pkg_numbers = scrape_search_results(res, 'dataset') assert_equal(['30', '29', '28', '27', '26', '25', '24', '23', '22', '21', '20', '19', '18', '17', '16', '15', '14', '13', '12', '11'], pkg_numbers) def test_group_datasets_read_p1(self): - - with self.app.flask_app.test_request_context(): - url = url_for(controller='group', action='read', id='group_00') - - res = self.app.get(url) + res = self.app.get(url_for(controller='group', action='read', id='group_00')) assert 'href="/group/group_00?page=2' in res, res pkg_numbers = scrape_search_results(res, 'group_dataset') assert_equal(['50', '49', '48', '47', '46', '45', '44', '43', '42', '41', '40', '39', '38', '37', '36', '35', '34', '33', '32', '31'], pkg_numbers) def test_group_datasets_read_p2(self): - - with self.app.flask_app.test_request_context(): - url = url_for(controller='group', action='read', id='group_00', page=2) - - res = self.app.get(url) + res = self.app.get(url_for(controller='group', action='read', id='group_00', page=2)) assert 'href="/group/group_00?page=1' in res, res pkg_numbers = scrape_search_results(res, 'group_dataset') assert_equal(['30', '29', '28', '27', '26', '25', '24', '23', '22', '21', '20', '19', '18', '17', '16', '15', '14', '13', '12', '11'], pkg_numbers) @@ -117,20 +101,12 @@ def teardown_class(self): model.repo.rebuild_db() def test_group_index(self): - - with self.app.flask_app.test_request_context(): - url = url_for(controller='group', action='index') - - res = self.app.get(url) + res = self.app.get(url_for(controller='group', action='index')) assert 'href="/group?q=&sort=&page=2"' in res, res grp_numbers = scrape_search_results(res, 'group') assert_equal(['00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20'], grp_numbers) - - with self.app.flask_app.test_request_context(): - url = url_for(controller='group', action='index', page=2) - - res = self.app.get(url) + res = self.app.get(url_for(controller='group', action='index', page=2)) assert 'href="/group?q=&sort=&page=1"' in res grp_numbers = scrape_search_results(res, 'group') assert_equal(['21'], grp_numbers) @@ -154,19 +130,12 @@ def teardown_class(self): model.repo.rebuild_db() def test_users_index(self): - - with self.app.flask_app.test_request_context(): - url = url_for(controller='user', action='index') - - res = self.app.get(url) + res = self.app.get(url_for(controller='user', action='index')) assert 'href="/user?q=&order_by=name&page=2"' in res user_numbers = scrape_search_results(res, 'user') assert_equal(['00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19'], user_numbers) - with self.app.flask_app.test_request_context(): - url = url_for(controller='user', action='index', page=2) - - res = self.app.get(url) + res = self.app.get(url_for(controller='user', action='index', page=2)) assert 'href="/user?q=&order_by=name&page=1"' in res user_numbers = scrape_search_results(res, 'user') assert_equal(['20'], user_numbers) diff --git a/ckan/tests/legacy/functional/test_preview_interface.py b/ckan/tests/legacy/functional/test_preview_interface.py index 747834446e3..deb7aa6f965 100644 --- a/ckan/tests/legacy/functional/test_preview_interface.py +++ b/ckan/tests/legacy/functional/test_preview_interface.py @@ -19,16 +19,14 @@ def setup_class(cls): cls.package = model.Package.get('annakarenina') cls.resource = cls.package.resources[0] - - with cls.app.flask_app.test_request_context(): - cls.url = h.url_for(controller='package', - action='resource_read', - id=cls.package.name, - resource_id=cls.resource.id) - cls.preview_url = h.url_for(controller='package', - action='resource_datapreview', - id=cls.package.id, - resource_id=cls.resource.id) + cls.url = h.url_for(controller='package', + action='resource_read', + id=cls.package.name, + resource_id=cls.resource.id) + cls.preview_url = h.url_for(controller='package', + action='resource_datapreview', + id=cls.package.id, + resource_id=cls.resource.id) @classmethod def teardown_class(cls): @@ -37,9 +35,7 @@ def teardown_class(cls): def test_hook(self): testpackage = self.package - - with self.app.flask_app.test_request_context(): - resource_dict = model_dictize.resource_dictize(self.resource, {'model': model}) + resource_dict = model_dictize.resource_dictize(self.resource, {'model': model}) context = { 'model': model, @@ -74,12 +70,10 @@ def test_hook(self): assert self.plugin.calls['preview_templates'] == 1, self.plugin.calls # test whether the json preview is used - - with self.app.flask_app.test_request_context(): - preview_url = h.url_for(controller='package', - action='resource_datapreview', - id=testpackage.id, - resource_id=testpackage.resources[1].id) + preview_url = h.url_for(controller='package', + action='resource_datapreview', + id=testpackage.id, + resource_id=testpackage.resources[1].id) result = self.app.get(preview_url, status=200) assert 'mock-json-preview' in result.body diff --git a/ckan/tests/legacy/functional/test_revision.py b/ckan/tests/legacy/functional/test_revision.py index 5312aad7c29..af0f653fa1c 100644 --- a/ckan/tests/legacy/functional/test_revision.py +++ b/ckan/tests/legacy/functional/test_revision.py @@ -90,9 +90,7 @@ def get_package(self, name): def test_read(self): anna = model.Package.by_name(u'annakarenina') rev_id = anna.revision.id - - with self.app.flask_app.test_request_context(): - offset = url_for(controller='revision', action='read', id='%s' % rev_id) + offset = url_for(controller='revision', action='read', id='%s' % rev_id) res = self.app.get(offset) assert 'Revision %s' % rev_id in res assert 'Revision: %s' % rev_id in res @@ -134,18 +132,14 @@ def test_list_format_atom(self): # Todo: Test for first revision on last page. # Todo: Test for last revision minus 50 on second page. # Page 1. (Implied id=1) - - with self.app.flask_app.test_request_context(): - offset = url_for(controller='revision', action='list', format='atom') + offset = url_for(controller='revision', action='list', format='atom') res = self.app.get(offset) assert '' in res, res # Todo: Better test for 'days' request param. # - fake some older revisions and check they aren't included. - - with self.app.flask_app.test_request_context(): - offset = url_for(controller='revision', action='list', format='atom', + offset = url_for(controller='revision', action='list', format='atom', days=30) res = self.app.get(offset) assert ' section' the_html = self._get_html_from_res(html) @@ -34,13 +33,13 @@ def strip_tags(self, res): '''Call strip_tags on a TestResponse object to strip any and all HTML and normalise whitespace.''' if not isinstance(res, basestring): res = res.body.decode('utf-8') - return Stripper().strip(res) + return Stripper().strip(res) def check_named_element(self, html, tag_name, *html_to_find): '''Searches in the html and returns True if it can find a particular tag and all its subtags & data which contains all the of the html_to_find''' - named_element_re = re.compile('(<(%(tag)s\w*).*?(>.*?)' % {'tag':tag_name}) + named_element_re = re.compile('(<(%(tag)s\w*).*?(>.*?)' % {'tag':tag_name}) html_str = self._get_html_from_res(html) self._check_html(named_element_re, html_str.replace('\n', ''), html_to_find) @@ -61,14 +60,13 @@ def check_tag(self, html, *html_to_find): self._check_html(self.tag_re, html, html_to_find) def _get_html_from_res(self, html): - if isinstance(html, (paste.fixture.TestResponse, webtest.app.TestResponse)): + if isinstance(html, paste.fixture.TestResponse): html_str = html.body.decode('utf8') elif isinstance(html, unicode): html_str = html elif isinstance(html, str): html_str = html.decode('utf8') else: - import ipdb; ipdb.set_trace() raise TypeError return html_str # always unicode diff --git a/ckan/tests/legacy/lib/test_alphabet_pagination.py b/ckan/tests/legacy/lib/test_alphabet_pagination.py index c3f4cdaa428..97d2773c634 100644 --- a/ckan/tests/legacy/lib/test_alphabet_pagination.py +++ b/ckan/tests/legacy/lib/test_alphabet_pagination.py @@ -8,7 +8,6 @@ from ckan.tests.legacy import regex_related from ckan.lib.create_test_data import CreateTestData from ckan import model -from ckan.tests import helpers other = 'Other' @@ -55,9 +54,7 @@ def test_01_package_page(self): page='A', other_text=other, ) - app = helpers._get_test_app() - with app.flask_app.test_request_context(): - pager = page.pager() + pager = page.pager() assert_true( pager.startswith( '