On May 11, 4:38 pm, Gelonida <gelon...@gmail.com> wrote:
> For one unit test I would like to use the real data base and not the
> test data base.
>
> Basically this unit test shall verify that the server database fulfills
> certain consistency criterea.
>
> How can I write one django test, that uses the 'default' (non test database)
>
> I tried to use Model.objects.using('default').all() but still seem to
> receive an empty list (thus the contents of the test data base)

The real database is not available in testing (it's a feature). If you
want to access the real database, you will have to do it yourself,
something like this might work in 1.4:
def test_something():
    try:
        old_db = django.db.connections['default']
        django.db.connections['default'] =
old_db.__class__(old_db.settings_dict)
        # you might want to print the settings dict to see what you
need to update...
        django.db.connections['default'].settings_dict['NAME'] =
real_db_name
        # test the db here
    finally:
       django.db.connections['default'] = old_db

The above relies on internals of Django, and in addition if something
goes wrong, it is possible the real database gets flushed (Django's
testing framework aggressively flushes databases). I haven't tested
the above code. Test carefully and don't blame me if something goes
wrong.

I am not sure but I guess the testing framework misses the concept of
read-only database. That might be useful for some testing cases.

 - Anssi

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to