def test_partitioned_model_state_from_model(model):
    """Tests whether creating state from an existing model works as
    expected."""

    state = PostgresPartitionedModelState.from_model(model)
    assert state.partitions == {}
    assert (state.partitioning_options["method"] ==
            model._partitioning_meta.method)
    assert state.partitioning_options["key"] == model._partitioning_meta.key
def test_partitioned_model_clone(model):
    """Tests whether cloning the state actually clones the partitioning
    options.

    If its not a copy, but a reference instead, bad things can happen as
    the options are mutated to build up migration state.
    """

    state = PostgresPartitionedModelState.from_model(model)
    state.partitions = {
        "pt1":
        PostgresPartitionState(app_label="tests",
                               model_name="tests",
                               name="pt1")
    }

    state_copy = state.clone()
    assert state.partitions is not state_copy.partitions
    assert state.partitioning_options is not state_copy.partitioning_options