-
Install package
pip install django-gajo-utils
-
Add
GajoDebugUtilsMiddleware
to project settings before all other none-dev related middlewares.MIDDLEWARE = [ 'gajo_utils.middleware.GajoDebugUtilsMiddleware', ... other apps ]
-
Add
gajo_utils
toINSTALLED_APPS
.INSTALLED_APPS = [ ...other apps 'gajo_utils', ]
-
Turn on any of the utils by settings its value to
True
(by default all utils are disabled)GAJO_UTILS_CONFIG = { "REQUEST_TIMER": False, "REQUEST_DELAY": False, "REQUEST_COOKIES": False, "RESPONSE_COOKIES": False, "RESPONSE_CONTENT": False, "RESPONSE_QUERIES": False, "DUMP_FIXTURES": [ "dummy.Model1", "dummy.Model2", ], "LOAD_FIXTURES": [ "dummy.Model1", "dummy.Model2", ], }
-
"REQUEST_TIMER": True
prints in terminal how much time it needed for request/response cycle to finish. -
"REQUEST_DELAY": True
adds random delay (50ms - 300ms) to every request and than prints in terminal how much was request delayed. This config is used to simulate latency on server. -
"REQUEST_COOKIES": True
prints in terminal request cookies. -
"RESPONSE_COOKIES": True
prints in terminal response cookies. -
"RESPONSE_CONTENT": True
prints in terminal response content. -
"RESPONSE_QUERIES": True
prints all queries that were made in response/request cycle with time for each one. It also prints total time for all queries and number of similar queries (queries that can be probably optimized withselect_related
orprefetch_related
).
Decorator for timing how much time took for view to run. If you want to time whole
request/response cycle than you should use REQUEST_TIMER
configuration.
from gajo_utils.decorators import timeview
@timeview
def example_view(request):
return ...
Function time (function_name): 43.22ms
gajo_utils
adds three extra commands to your django app.
-
./manage.py testsingle {test_name}
offers you option to test single function test or test single TestCase class without needing to providing full path to test likeapps.dummy.tests.test_dummies.DummyTest.test_dummy
. You can instead just specifyDummyTest
ortest_dummy
.If command finds two functions or classes with same name in different app it will test both separately (with two commands executed).
-
./manage.py dumpfixtures
this management command needs extra configuration insettings.py
. You can specify which models you want to be dumped into database inGAJO_UTILS_CONFIG
. Every model is than dumped in json format atROOT_DIR/fixtures/app_name/ModelName.json
.GAJO_UTILS_CONFIG = { "DUMP_FIXTURES": [ "dummy.Model1", "dummy.Model2", ] }
-
./manage.py loadfixtures
this management command needs extra configuration insettings.py
. You can specify which models you want to be loaded into database inGAJO_UTILS_CONFIG
. There must be file created at correct path:ROOT_DIR/fixtures/app_name/ModelName.json
GAJO_UTILS_CONFIG = { "LOAD_FIXTURES": [ "dummy.Model1", "dummy.Model2", ] }
This package is using Semantic Versioning. You can find informations about it here: https://semver.org/.
Distributed under the MIT License. See LICENSE.txt
for more information.