On Tue, Jan 14, 2014 at 3:26 PM, Shai Berger <s...@platonix.com> wrote:

>
> The way testing currently works is by creating a throw-away database,
> running
> the tests on that, and throwing it away. This means, among other things,
> that
> you need settings for a database service and credentials for a user that
> can
> create databases on this service. The common use-case is that this user is
> your "main" database user, and the service is your main service. Your
> suggestion, if I understand it correctly, gives the user two options:
>
> 1) Use separate credentials, and perhaps even a separate service, for
> testing;
> this implies that the test database stays alive all the time.
>

As it stands, the privileges for running the tests are greater than those
needed to run syncdb (or runserver), so I'm not sure what point you are
trying to make. If you want to be able to use only one set of credentials
to do everything, then you're going to use a user with enough privileges to
do everything. This assumes you're not using Oracle and need to provide the
slew of other configuration values, which should really be moved to OPTIONS.

2) Write configurations with repetitions or some other awkwardness, e.g.
>
> default_db = {
>         'ENGINE': 'this',
>         'HOST': 'that',
>         'NAME': 'the_other',
>         'USER': 'me',
>         'PASSWORD': 'my secret',
> }
>
> DATABASES = {
>         'default' : default_db,
>         'test_default' : dict(default_db,
>                 NAME='test_the_other',
>                 IS_TEST=True),
> }
>
> I don't see that as an improvement; you seem to be optimizing for the edge
> case at the expense of the common case.
>

This is not what I envisioned. By separate aliases, I don't mean to just
add more test aliases in with your existing settings. What I mean is that
each database alias defined in a settings file should define a single
connection configuration, not potentially two different configurations. If
you need a different configuration for testing, put them in a separate
configuration file.

 Example:

# settings.py - for local development
DATABASES = {
'default': {
'ENGINE': 'oracle',
 'NAME': 'my_db',
'USER': 'my_user', # user can syncdb, but database exists
 ...
# 'CAN_USE_FOR_TESTS': False, # Protect database from unit test trampling
  }
}


# test_settings.py - for unit tests
DATABASES = {
'default': {
'ENGINE': 'oracle',
 'NAME': 'test_my_db', # This was TEST_NAME
'USER': 'dba_user', # This is a user with proper credentials to drop a
database
 ...
'OPTIONS': {
# backend specific settings belong here
 'TEST_CREATE': True,
'TEST_TBLSPACE': 'test_',
'CHARSET': 'utf-8', # Or leave named as TEST_CHARSET
 ...
},
'CAN_USE_FOR_TESTS': True, # DB is safe to trample with tests
 }
}

Regards,
Michael Manfre

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CAGdCwBvFLOykSGUByx67gtST%2BThFbhdavUHKeWJwYOVNjXKMcQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to