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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
from psqlextra.models import PostgresPartitionedModel
from psqlextra.types import PostgresPartitioningMethod
from .fake_model import define_fake_partitioned_model
def test_partitioned_model_abstract():
"""Tests whether :see:PostgresPartitionedModel is abstract."""
assert PostgresPartitionedModel._meta.abstract
def test_partitioning_model_options_meta():
"""Tests whether the `_partitioning_meta` attribute is available on the
class (created by the meta class) and not just creating when the model is
instantiated."""
assert PostgresPartitionedModel._partitioning_meta
def test_partitioned_model_default_options():
"""Tests whether the default partitioning options are set as expected on.
:see:PostgresPartitionedModel.
"""
model = define_fake_partitioned_model()
assert model._partitioning_meta.method == PostgresPartitioningMethod.RANGE
assert model._partitioning_meta.key == []
def test_partitioned_model_method_option():
"""Tests whether the `method` partitioning option is properly copied onto
the options object."""
model = define_fake_partitioned_model(
partitioning_options=dict(method=PostgresPartitioningMethod.LIST)
)
assert model._partitioning_meta.method == PostgresPartitioningMethod.LIST
def test_partitioned_model_method_option_none():
"""Tests whether setting the `method` partitioning option results in the
default being set."""
model = define_fake_partitioned_model(
partitioning_options=dict(method=None)
)
assert model._partitioning_meta.method == PostgresPartitioningMethod.RANGE
def test_partitioned_model_key_option():
"""Tests whether the `key` partitioning option is properly copied onto the
options object."""
model = define_fake_partitioned_model(
partitioning_options=dict(key=["timestamp"])
)
assert model._partitioning_meta.key == ["timestamp"]
def test_partitioned_model_key_option_none():
"""Tests whether setting the `key` partitioning option results in the
default being set."""
model = define_fake_partitioned_model(partitioning_options=dict(key=None))
assert model._partitioning_meta.key == []
|