28 lines
1.0 KiB
Python
28 lines
1.0 KiB
Python
"""Safety checks for cleanup of the disposable PostgreSQL regression database."""
|
|
|
|
import pytest
|
|
from django.core.management.color import no_style
|
|
from django.db import connection
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_cascading_flush_is_restricted_to_test_database_names(monkeypatch):
|
|
if connection.vendor != "postgresql":
|
|
pytest.skip("PostgreSQL-only test cleanup")
|
|
|
|
with monkeypatch.context() as patcher:
|
|
patcher.setitem(connection.settings_dict, "NAME", "not_a_test_database")
|
|
with pytest.raises(RuntimeError, match="outside a test_ database"):
|
|
connection.ops.sql_flush(no_style(), ["employees_employee"])
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_postgres_test_flush_can_include_legacy_foreign_key_tables():
|
|
if connection.vendor != "postgresql":
|
|
pytest.skip("PostgreSQL-only test cleanup")
|
|
|
|
assert str(connection.settings_dict["NAME"]).startswith("test_")
|
|
statements = connection.ops.sql_flush(no_style(), ["employees_employee"])
|
|
assert len(statements) == 1
|
|
assert statements[0].endswith(" CASCADE;")
|