-
Notifications
You must be signed in to change notification settings - Fork 62
Open
Description
There was some hacky code put in place for this test:
django-watchman/tests/test_views.py
Lines 281 to 320 in 67e4707
| class TestDBError(TransactionTestCase): | |
| """ | |
| Ensure that we produce a valid response even in case of database | |
| connection issues with `ATOMIC_REQUESTS` enabled. | |
| Since overriding `DATABASES` isn't officially supported we need to perform | |
| some gymnastics here to convince django. | |
| """ | |
| def setUp(self): | |
| # Cache current database connections | |
| self.databases = copy(connections._databases) | |
| self.connection = getattr(connections._connections, DEFAULT_DB_ALIAS, None) | |
| del connections.__dict__['databases'] # remove cached_property value | |
| connections._databases = None | |
| connections._connections = local() | |
| def tearDown(self): | |
| # Restore previous database connections | |
| connections._databases = self.databases | |
| setattr(connections._connections, DEFAULT_DB_ALIAS, self.connection) | |
| del connections.__dict__['databases'] # remove cached_property value | |
| @override_settings( | |
| DATABASES={ | |
| 'default': { | |
| "ENGINE": "django.db.backends.mysql", | |
| "HOST": "no.host.by.this.name.some-tld-that-doesnt-exist", | |
| "ATOMIC_REQUESTS": True | |
| }, | |
| } | |
| ) | |
| # can't use override_settings because of | |
| # https://github.com/mwarkentin/django-watchman/issues/13 | |
| @patch('watchman.settings.WATCHMAN_ERROR_CODE', 201) | |
| def test_db_error_w_atomic_requests(self): | |
| # Ensure we don't trigger django's generic 500 page in case of DB error | |
| response = Client().get('/', data={ | |
| 'check': 'watchman.checks.databases', | |
| }) | |
| self.assertEqual(response.status_code, 201) |
- Figure out if overriding DATABASES is more supported these days
- Figure out if Clean up module level settings #13 is still an issue and how to fix
======================================================================
| FAIL: test_db_error_w_atomic_requests (tests.test_views.TestDBError)
| ----------------------------------------------------------------------
| Traceback (most recent call last):
| File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/site-packages/django/test/utils.py", line 437, in inner
| return func(*args, **kwargs)
| File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/unittest/mock.py", line 1336, in patched
| return func(*newargs, **newkeywargs)
| File "/Users/michael/wave/src/sandbox/django-watchman/tests/test_views.py", line 319, in test_db_error_w_atomic_requests
| self.assertEqual(response.status_code, 201)
| AssertionError: 200 != 201
Full test class that will be removed for now:
class TestDBError(TransactionTestCase):
"""
Ensure that we produce a valid response even in case of database
connection issues with `ATOMIC_REQUESTS` enabled.
Since overriding `DATABASES` isn't officially supported we need to perform
some gymnastics here to convince django.
"""
def setUp(self):
# Cache current database connections
self.databases = copy(connections._databases)
self.connection = getattr(connections._connections, DEFAULT_DB_ALIAS, None)
del connections.__dict__['databases'] # remove cached_property value
connections._databases = None
connections._connections = local()
def tearDown(self):
# Restore previous database connections
connections._databases = self.databases
setattr(connections._connections, DEFAULT_DB_ALIAS, self.connection)
del connections.__dict__['databases'] # remove cached_property value
@override_settings(
DATABASES={
'default': {
"ENGINE": "django.db.backends.mysql",
"HOST": "no.host.by.this.name.some-tld-that-doesnt-exist",
"ATOMIC_REQUESTS": True
},
}
)
# can't use override_settings because of
# https://github.com/mwarkentin/django-watchman/issues/13
@patch('watchman.settings.WATCHMAN_ERROR_CODE', 201)
def test_db_error_w_atomic_requests(self):
# Ensure we don't trigger django's generic 500 page in case of DB error
response = Client().get('/', data={
'check': 'watchman.checks.databases',
})
self.assertEqual(response.status_code, 201)Metadata
Metadata
Assignees
Labels
No labels