Add test case database connection check

Signed-off-by: Roberto Rosario <roberto.rosario@mayan-edms.com>
This commit is contained in:
Roberto Rosario
2019-06-27 11:35:58 -04:00
parent 22aa14282b
commit d636174c85
2 changed files with 32 additions and 7 deletions

View File

@@ -12,7 +12,7 @@ from django.apps import apps
from django.conf import settings
from django.conf.urls import url
from django.contrib.contenttypes.models import ContentType
from django.db import connection, models
from django.db import connection, connections, models
from django.db.models.signals import post_save, pre_save
from django.http import HttpResponse
from django.template import Context, Template
@@ -80,6 +80,29 @@ class ClientMethodsTestCaseMixin(object):
)
class ConnectionsCheckTestCaseMixin(object):
_open_connections_check_enable = True
def _get_open_connections_count(self):
return len(connections.all())
def setUp(self):
super(ConnectionsCheckTestCaseMixin, self).setUp()
self._connections_count = self._get_open_connections_count()
def tearDown(self):
if self._open_connections_check_enable:
self.assertEqual(
self._connections_count, self._get_open_connections_count(),
msg='Database connection leak. The number of database '
'connections at the start and at the end of the test are not '
'the same.'
)
super(ConnectionsCheckTestCaseMixin, self).tearDown()
class ContentTypeCheckTestCaseMixin(object):
expected_content_type = 'text/html; charset=utf-8'