Skip to content

Commit

Permalink
Prevented tests to create and destroy the DB
Browse files Browse the repository at this point in the history
  • Loading branch information
Genarito committed Dec 13, 2023
1 parent 8d7f50e commit 3a58c1e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 77 deletions.
3 changes: 3 additions & 0 deletions ModulectorBackend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@
MEDIA_ROOT = os.getenv('MEDIA_ROOT', os.path.join(BASE_DIR, ''))
MEDIA_URL = os.getenv('MEDIA_URL', '/media/')

# Test runner
TEST_RUNNER = 'modulector.tests.runner.DjangoTestSuiteRunner'

# Email Server
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
# This email configuration is what postfix uses, for production, use your own
Expand Down
72 changes: 0 additions & 72 deletions modulector/tests/data_init.py

This file was deleted.

13 changes: 13 additions & 0 deletions modulector/tests/runner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from django.test.runner import DiscoverRunner


class DjangoTestSuiteRunner(DiscoverRunner):
"""
This runner prevents Django from creating and destroying the test database. This is useful as Modulector has
read-only preloaded data in the database.
"""
def setup_databases(self, **kwargs):
pass

def teardown_databases(self, old_config, **kwargs):
pass
5 changes: 0 additions & 5 deletions modulector/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
from django.test import Client, TestCase
from modulector.tests.data_init import load_test_data

client = Client()


class ViewTests(TestCase):
@classmethod
def setUpTestData(cls):
load_test_data(cls)

def __check_empty_pagination(self, response):
"""Checks if fields of response are valid for an empty pagination response"""
self.assertEqual(response.data['count'], 0)
Expand Down

0 comments on commit 3a58c1e

Please sign in to comment.