On 25/12/2015 7:09 PM, varun naganathan wrote:
Hi,
I basically want to know how i  can run unittests on different
databases like Postgres and Mysql.The documnetation says something about
writing a custom settings file.However I'm unable to actually understand
how actually the settings file must look.
Could someone perhaps post a sample file ??

It is quite simple and fully documented in Two Scoops of Django which I recommend with enthusiasm.

One of the options in testing is --settings=<whatever> where you can nominate any settings file you like. For example settings.test_mysql

To follow the Two Scoops recipe you create a settings directory and a base settings file with all the settings which are common to all scenarios you wish to run. Hence you might have basic settings specified in ../settings/base.py - including your regular database settings eg.,

DATABASES = {
 'default': {
  'ENGINE': 'django.db.backends.postgresql_psycopg2',
  'NAME': <database_name>,
  'USER': <database_user>,
  'PASSWORD': <database_pass>,
  'HOST': <database_host>,
  'PORT': database_port>,
 }
}

... all exactly as set out in Django docs which I'm sure you have already studied.

Then in the same directory you have eg., test_mysql.py which needs to import the base.py settings into its own (ie., test_mysql) namespace like this ...

from __future__ import absolute_import
from .base import *

# now overwrite/override particular base.py settings
DATABASES = {
 'default': {
  'ENGINE': 'django.db.backends.<mysql_interface*>',
  'NAME': <database_name>,
  'USER': <database_user>,
  'PASSWORD': <database_pass>,
  'HOST': <database_host>,
  'PORT': database_port>,which take your fancy.
 }
}

* Don't know what that is because I don't use it.

So this lets you name any settings file - provided that it imports the settings you don't wish to rewrite - and in which you can rewrite any settings or even add other settings or other code which suits your needs.

To continue the recipe I have a settings/production.py which imports "base" in the same manner and adds its own changes (if any). Similarly, settings/mike for my own development settings where different than those in base.py and so it goes.

All the best

Mike


--
You received this message because you are subscribed to the Google
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to [email protected]
<mailto:[email protected]>.
To post to this group, send email to [email protected]
<mailto:[email protected]>.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/f2f08c73-83ea-4f68-8fca-70e64d97b25d%40googlegroups.com
<https://groups.google.com/d/msgid/django-users/f2f08c73-83ea-4f68-8fca-70e64d97b25d%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/567D2E95.6000404%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.

Reply via email to