File: test_schema_editor_storage_settings.py

package info (click to toggle)
python-django-postgres-extra 2.0.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,096 kB
  • sloc: python: 9,057; makefile: 17; sh: 7; sql: 1
file content (47 lines) | stat: -rw-r--r-- 1,385 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import pytest

from django.db import connection, models

from psqlextra.backend.schema import PostgresSchemaEditor

from . import db_introspection
from .fake_model import get_fake_model


@pytest.fixture
def fake_model():
    return get_fake_model(
        {
            "text": models.TextField(),
        }
    )


def test_schema_editor_storage_settings_table_alter_and_reset(fake_model):
    table_name = fake_model._meta.db_table
    schema_editor = PostgresSchemaEditor(connection)

    schema_editor.alter_table_storage_setting(
        table_name, "autovacuum_enabled", "false"
    )
    assert db_introspection.get_storage_settings(table_name) == {
        "autovacuum_enabled": "false"
    }

    schema_editor.reset_table_storage_setting(table_name, "autovacuum_enabled")
    assert db_introspection.get_storage_settings(table_name) == {}


def test_schema_editor_storage_settings_model_alter_and_reset(fake_model):
    table_name = fake_model._meta.db_table
    schema_editor = PostgresSchemaEditor(connection)

    schema_editor.alter_model_storage_setting(
        fake_model, "autovacuum_enabled", "false"
    )
    assert db_introspection.get_storage_settings(table_name) == {
        "autovacuum_enabled": "false"
    }

    schema_editor.reset_model_storage_setting(fake_model, "autovacuum_enabled")
    assert db_introspection.get_storage_settings(table_name) == {}