Вопрос

Our app has a specific behavior when the database is out of service. I want to write a test for this behavior but in can't find a solution.

I suppose the simplest way is to break database auth or name but :

override_settings can't change the DATABASE settings ( https://code.djangoproject.com/ticket/19031 )

modify_settings isn't implemented in django 1.6

There is a solution to do this ?

Thanks

Это было полезно?

Решение

You can try closing your connection to the database in your test.

from django import db

from myapp.models import MyModel

# assuming only one connection
db.connections.all()[0].connection.close()

try:
    MyModel.objects.first()
except db.InterfaceError, e:
    print e
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top