|
1 | 1 | import pytest
|
2 | 2 |
|
| 3 | +from django.core.exceptions import ImproperlyConfigured |
3 | 4 | from django.db import models
|
| 5 | +from django.test import override_settings |
4 | 6 |
|
| 7 | +from psqlextra.manager import PostgresManager |
5 | 8 | from psqlextra.models import PostgresModel
|
6 | 9 |
|
7 | 10 | from .fake_model import get_fake_model
|
8 | 11 |
|
9 | 12 |
|
| 13 | +@pytest.mark.parametrize( |
| 14 | + "databases", |
| 15 | + [ |
| 16 | + {"default": {"ENGINE": "psqlextra.backend"}}, |
| 17 | + { |
| 18 | + "default": {"ENGINE": "django.db.backends.postgresql"}, |
| 19 | + "other": {"ENGINE": "psqlextra.backend"}, |
| 20 | + }, |
| 21 | + { |
| 22 | + "default": {"ENGINE": "psqlextra.backend"}, |
| 23 | + "other": {"ENGINE": "psqlextra.backend"}, |
| 24 | + }, |
| 25 | + ], |
| 26 | +) |
| 27 | +def test_manager_backend_set(databases): |
| 28 | + """Tests that creating a new instance of :see:PostgresManager succeseeds |
| 29 | + without any errors if one or more databases are configured with |
| 30 | + `psqlextra.backend` as its ENGINE.""" |
| 31 | + |
| 32 | + with override_settings(DATABASES=databases): |
| 33 | + assert PostgresManager() |
| 34 | + |
| 35 | + |
| 36 | +def test_manager_backend_not_set(): |
| 37 | + """Tests whether creating a new instance of |
| 38 | + :see:PostgresManager fails if no database |
| 39 | + has `psqlextra.backend` configured |
| 40 | + as its ENGINE.""" |
| 41 | + |
| 42 | + with override_settings( |
| 43 | + DATABASES={"default": {"ENGINE": "django.db.backends.postgresql"}} |
| 44 | + ): |
| 45 | + with pytest.raises(ImproperlyConfigured): |
| 46 | + PostgresManager() |
| 47 | + |
| 48 | + |
10 | 49 | def test_manager_truncate():
|
11 | 50 | """Tests whether truncating a table works."""
|
12 | 51 |
|
|
0 commit comments