I would like to test a create view with django TransactionTestCase. Here is my settings.py:
DATABASES = {
'default': {
"ENGINE": PG_ENGINE,
'OPTIONS':{'options': '-c search_path=schema1,schema2,public', 'isolation_level': psycopg2.extensions.ISOLATION_LEVEL_SERIALIZABLE,},
'NAME': DB_NAME,
'USER': DB_USER,
'PASSWORD':DB_PASSWD,
'HOST': HOST_NAME,
'PORT': '5432',
},
'schema2': {
"ENGINE": PG_ENGINE,
'OPTIONS':{'options': '-c search_path=schema2, schema1,public', 'isolation_level': psycopg2.extensions.ISOLATION_LEVEL_SERIALIZABLE,},
'NAME': DB_NAME,
'USER': DB_USER,
'PASSWORD':DB_PASSWD,
'HOST': HOST_NAME,
'PORT': '5432',
# 'TEST_MIRROR': 'default',
"TEST": {
"NAME": "schema2",
"OPTIONS":{'options': '-c search_path=schema2,schema1,public'}
},
},
And my test case:
class CreateTestCase(TransactionTestCase):
databases={'schema2', 'default', }
def setUp(self):
self.client=Client()
self.user= Model_in_default.objects.create(name='test', username='test', permission='Admin')
self.model_in_schema2=Model_in_schema2.objects.create(name='for_test', urlname='fortest', some_id=1, parent_some_id=2000, rank='test', code='tetcode', other_names='test' )
self.create_url=reverse('model_create')
def test_create_url_is_resolved(self):
url=self.create_url
self.assertEquals(resolve(url).func.view_class,ModelListView)
# def test_create(self):
# request=self.client.get(self.create_url, follow=True)
# request.user = self.user
# request.model_in_schema2=self.model_in_schema2
# response = ModelCreateView.as_view()(request)
When I run test - 'test_create_url_is_solved' firstly, I got error: django.db.utils.ProgrammingError: relation "django_content_type" does not exist...
My problem might be I put default django migartions and some models in default schema while some other models in schema2. I added OPTIONS to config test database and apparently it is not the right way... Any ideas on how to create test case in this situation? Thank you.