Skip to content

Commit

Permalink
Fix tests where registry did not have the backends
Browse files Browse the repository at this point in the history
  • Loading branch information
leplatrem committed Oct 28, 2024
1 parent 7e20482 commit 6ff1279
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
9 changes: 4 additions & 5 deletions tests/core/resource/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,19 +613,18 @@ class StorageErrorTest(BaseWebTest, unittest.TestCase):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.error = storage_exceptions.BackendError(ValueError())
self.storage_error_patcher = mock.patch(
"kinto.core.storage.memory.Storage.create", side_effect=self.error
)

def test_backend_errors_are_served_as_503(self):
body = {"data": MINIMALIST_OBJECT}
with self.storage_error_patcher:
with mock.patch.object(self.app.app.registry.storage, "create", side_effect=self.error):
self.app.post_json(self.plural_url, body, headers=self.headers, status=503)

def test_backend_errors_original_error_is_logged(self):
body = {"data": MINIMALIST_OBJECT}
with mock.patch("kinto.core.views.errors.logger.critical") as mocked:
with self.storage_error_patcher:
with mock.patch.object(
self.app.app.registry.storage, "create", side_effect=self.error
):
self.app.post_json(self.plural_url, body, headers=self.headers, status=503)
self.assertTrue(mocked.called)
self.assertEqual(type(mocked.call_args[0][0]), ValueError)
Expand Down
19 changes: 11 additions & 8 deletions tests/core/test_initialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,18 +444,19 @@ def test_statsd_attr_is_exposed_in_the_registry_if_url_is_set(self):


class RequestsConfigurationTest(unittest.TestCase):
app_settings = {
"storage_backend": "kinto.core.storage.memory",
"cache_backend": "kinto.core.cache.memory",
"permission_backend": "kinto.core.permission.memory",
}

def _get_app(self, settings={}):
app_settings = {
"storage_backend": "kinto.core.storage.memory",
"cache_backend": "kinto.core.cache.memory",
}
app_settings.update(**settings)
config = Configurator(settings=app_settings)
config = Configurator(settings={**self.app_settings, **settings})
kinto.core.initialize(config, "0.0.1", "name")
return webtest.TestApp(config.make_wsgi_app())

def test_requests_have_a_bound_data_attribute(self):
config = Configurator()
config = Configurator(settings={**self.app_settings})
kinto.core.initialize(config, "0.0.1", "name")

def on_new_request(event):
Expand All @@ -468,7 +469,7 @@ def on_new_request(event):
app.get("/v0/")

def test_subrequests_share_parent_bound_data(self):
config = Configurator()
config = Configurator(settings={**self.app_settings})
kinto.core.initialize(config, "0.0.1", "name")

bound_datas = set()
Expand Down Expand Up @@ -532,6 +533,8 @@ def make_app(self, settings=None):
config = Configurator(settings={**kinto.core.DEFAULT_SETTINGS})
config.add_settings(
{
"storage_backend": "kinto.core.storage.memory",
"cache_backend": "kinto.core.cache.memory",
"permission_backend": "kinto.core.permission.memory",
"includes": "tests.core.testplugin",
"multiauth.policies": "basicauth",
Expand Down

0 comments on commit 6ff1279

Please sign in to comment.