Skip to content

Commit a0a9519

Browse files
committed
Add tests for back-end check in PostgresManager
1 parent 4e44e75 commit a0a9519

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

tests/test_manager.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,51 @@
11
import pytest
22

3+
from django.core.exceptions import ImproperlyConfigured
34
from django.db import models
5+
from django.test import override_settings
46

7+
from psqlextra.manager import PostgresManager
58
from psqlextra.models import PostgresModel
69

710
from .fake_model import get_fake_model
811

912

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+
1049
def test_manager_truncate():
1150
"""Tests whether truncating a table works."""
1251

0 commit comments

Comments
 (0)