These are chat archives for django/django

Jun 2016
Zeeshan Asgar
Jun 20 2016 06:04

hi guys,

I m writing test cases in django. I have a separate settings file for the tests and a separate database.

    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': join(PROJECT_ROOT, 'run', 'TEST.sqlite3'),

I want to use this database while testing. I am able to override the behaviour of django testcases of creating/destroying the database.
Now how i can use this database in my test cases.


Jun 20 2016 06:08
@asgarzee you need to use that settings when running your tests
python test --settings=test_settings_file
Zeeshan Asgar
Jun 20 2016 06:11
okay let me check
Zeeshan Asgar
Jun 20 2016 06:41
it's not using this database @mpachas
(pdb) connections.__dict__

{'databases': {'default': {'TIME_ZONE': None, 'PORT': '', 'PASSWORD': '', 'HOST': '', 'TEST': {'CHARSET': None, 'MIRROR': None, 'NAME': None, 'COLLATION': None}, 'USER': '', 'NAME': '/run/TEST.sqlite3', 'OPTIONS': {}, 'AUTOCOMMIT': True, 'CONN_MAX_AGE': 0, 'ENGINE': 'django.db.backends.sqlite3', 'ATOMIC_REQUESTS': False}}, '_databases': {'default': {'TIME_ZONE': None, 'PORT': '', 'PASSWORD': '', 'HOST': '', 'TEST': {'CHARSET': None, 'MIRROR': None, 'NAME': None, 'COLLATION': None}, 'USER': '', 'NAME': '/run/TEST.sqlite3', 'OPTIONS': {}, 'AUTOCOMMIT': True, 'CONN_MAX_AGE': 0, 'ENGINE': 'django.db.backends.sqlite3', 'ATOMIC_REQUESTS': False}}, '_connections': <_thread._local object at 0x7f6cdf0c5f10>}
I am getting this. @mpachas
Zeeshan Asgar
Jun 20 2016 06:47

what i m doing is I am hitting an api. This api is saving a record in the db('TEST.sqlite3'). Then in my testcase method I am accessing this created record using

order = self.model.objects.filter(id="45125")

and then I am deleting this record using


and I am using the following code to not create/destroy db:

from django.test.runner import DiscoverRunner

class NoDbTestRunner(DiscoverRunner):
    """ A test runner to test without database creation """

    def setup_databases(self, **kwargs):
        """ Override the database creation defined in parent class """

    def teardown_databases(self, old_config, **kwargs):
        """ Override the database teardown defined in parent class """

In pdb I can check that it is deleting the record but It is not reflecting this in the TEST.sqlite3 db.

Robin Papa
Jun 20 2016 08:15
Hey! I need to pass a lot of filters to a query, what is the best way to do this? Add headers to the request and manage the response in the view? Or add the parameters to the request url and manage the response in the view?
what is best practice? :)
Filip Figiel
Jun 20 2016 09:20
@robinpapa you usually do this stuff via querystring
check out django-filters, it may help you with building the filters you need
Jun 20 2016 10:05
Is it necessary to delete modelform instances from modelformsets which I don't save? I am saving only the instances where the text boxes are filled and are not empty.
Gheorghita BUTNARU
Jun 20 2016 12:04
anyone worked at / with freeIPA plugins?