0

My django projects use two type of database (mariadb and mongoengine) I have no idea how to write the unittest that test both of them in the same testcase. please guide me.

now i try to use fixtures_mongoengine to write fixture mongo data but that cannot use with mysql fixture in the same testcase

Fah Nateecha
  • 151
  • 3
  • 14

1 Answers1

1

If you are using multiple database like:

# settings.py
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    },
    'other': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'other.sqlite3',
    }
}

You may use TransactionTestCase like:

# test.py
class TestMyViews(TransactionTestCase):
    databases = {'default', 'other'}

    def test_index_page_view(self):
        call_some_test_code()

reference the document here.

I don't know if mongoengine works, you could have a try.

Allen Shaw
  • 1,164
  • 7
  • 23