Skip to content

Commit d43f2da

Browse files
committed
- feat: add custom test runner
1 parent dafc833 commit d43f2da

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

core/settings.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,28 @@
132132

133133
AUTH_USER_MODEL = 'api_user.User'
134134

135+
# ##################################################################### #
136+
# ################### REST FRAMEWORK ###################### #
137+
# ##################################################################### #
138+
135139
REST_FRAMEWORK = {
136140
'DEFAULT_AUTHENTICATION_CLASSES': (
137141
'api.authentication.backends.ActiveSessionAuthentication',
138142
),
139143
}
140144

145+
# ##################################################################### #
146+
# ################### CORS ############################### #
147+
# ##################################################################### #
148+
141149
CORS_ALLOWED_ORIGINS = [
142150
"http://localhost:3000",
143151
"http://127.0.0.1:3000"
144152
]
145153

154+
# ##################################################################### #
155+
# ################### TESTING ############################### #
156+
# ##################################################################### #
157+
158+
TESTING = False
159+
TEST_RUNNER = 'core.test_runner.CoreTestRunner'

core/test_runner.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from importlib import import_module
2+
3+
from django.conf import settings
4+
from django.db import connections
5+
from django.test.runner import DiscoverRunner
6+
7+
8+
class CoreTestRunner(DiscoverRunner):
9+
def setup_test_environment(self, **kwargs):
10+
"""We set the TESTING setting to True. By default, it's on False."""
11+
super().setup_test_environment(**kwargs)
12+
settings.TESTING = True
13+
14+
def setup_databases(self, **kwargs):
15+
"""We set the database"""
16+
kwargs['aliases'] = connections
17+
r = super().setup_databases(**kwargs)
18+
self.load_fixtures()
19+
return r
20+
21+
@classmethod
22+
def load_fixtures(cls):
23+
try:
24+
module = import_module(f'api.fixtures')
25+
getattr(module, 'run_fixtures')()
26+
except ImportError:
27+
return

0 commit comments

Comments
 (0)