Skip to content

Commit

Permalink
Fix failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
DavisRayM committed Jun 8, 2021
1 parent e0a0d48 commit 9ac4117
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions onadata/apps/main/tests/test_service_health.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
from django.http import HttpRequest
from django.core.cache.backends.base import InvalidCacheBackendError
from django.db.utils import DatabaseError
from mock import patch

from onadata.apps.main.tests.test_base import TestBase
Expand All @@ -26,17 +26,15 @@ def test_service_health(self):
'Cache-Service': 'OK'
})

with patch('onadata.apps.main.views.cache') as cache_mock:
cache_mock.set.side_effect = InvalidCacheBackendError(
'Invalid cache configuration')
with patch('onadata.apps.main.views.XForm') as xform_mock:
xform_mock.objects.using().first.side_effect = DatabaseError(
'Some database error')
resp = service_health(req)

self.assertEqual(resp.status_code, 500)
self.assertEqual(
json.loads(resp.content.decode('utf-8')),
{
'default-Database': 'OK',
'Cache-Service': (
'Degraded state; '
'Invalid cache configuration')
'default-Database': 'Degraded state; Some database error',
'Cache-Service': 'OK'
})

0 comments on commit 9ac4117

Please sign in to comment.