Exemple #1
0
def test_healthcheck_attributes_index_non_primitive_with_key(
        sheraf_database, capsys):
    from .fixture1 import Model3k, DummyModel

    with sheraf.connection(commit=True) as conn:
        Model3k.create(simple="simple1",
                       obj_indexed=DummyModel.create(v="str1"))
        Model3k.create(simple="simple2",
                       obj_indexed=DummyModel.create(v="str2"))

        index_table = conn.root()["model3k_table"]["obj"]
        del index_table["str1"]

    with sheraf.connection() as conn:
        assert "str1" not in conn.root()["model3k_table"]["obj"]
        assert "str2" in conn.root()["model3k_table"]["obj"]

        health = check_health(fixture1,
                              instance_checks=[],
                              attribute_checks=["index"
                                                ])["check_attributes_index"]

        assert {
            "obj": {
                "ok": 1,
                "ko": 1
            }
        } == health["tests.health.fixture1.Model3k"]

        print_health(fixture1)
        stdout = capsys.readouterr().out
        assert re.search(r"tests.health.fixture1.Model3k[^\n]*1[^\n]*1",
                         stdout)
Exemple #2
0
def test_healthcheck_attributes_index_when_instance_deleted(
        sheraf_database, capsys):
    from .fixture1 import Model2unique

    with sheraf.connection(commit=True) as conn:
        Model2unique.create(simple="simple1", str_indexed="str1")
        Model2unique.create(simple="simple1", str_indexed="str2")
        m = Model2unique.create(simple="simple2", str_indexed="str3")
        mmapping = sheraf.types.SmallDict(m.mapping)
        m.delete()
        index_table = conn.root()["model2unique_table"]["str_indexed"]
        index_table["str3"] = mmapping

    with sheraf.connection() as conn:
        kwargs = dict(model_checks=["index"],
                      instance_checks=[],
                      attribute_checks=[])

        assert "str1" in conn.root()["model2unique_table"]["str_indexed"]
        assert "str2" in conn.root()["model2unique_table"]["str_indexed"]
        health = check_health(fixture1, **kwargs)["check_model_index"]

        assert {
            "str_indexed": {
                "ok": 2,
                "ko": 1
            }
        } == health["tests.health.fixture1.Model2unique"]

        print_health(fixture1, **kwargs)
        stdout = capsys.readouterr().out
        assert re.search(r"tests.health.fixture1.Model2unique[^\n]*1[^\n]*2",
                         stdout)
Exemple #3
0
def test_healthcheck_attributes_index_with_key(sheraf_database, capsys):
    from .fixture1 import Model2kunique

    with sheraf.connection(commit=True) as conn:
        Model2kunique.create(simple="simple1", str_indexed="str1")
        Model2kunique.create(simple="simple2", str_indexed="str2")
        index_table = conn.root()["model2kunique_table"]["str"]
        del index_table["str1"]

    with sheraf.connection() as conn:
        kwargs = dict(instance_checks=[], attribute_checks=["index"])

        assert "str1" not in conn.root()["model2kunique_table"]["str"]
        assert "str2" in conn.root()["model2kunique_table"]["str"]
        health = check_health(fixture1, **kwargs)["check_attributes_index"]

        assert {
            "str": {
                "ok": 1,
                "ko": 1
            }
        } == health["tests.health.fixture1.Model2kunique"]

        print_health(fixture1, **kwargs)
        stdout = capsys.readouterr().out
        assert re.search(r"tests.health.fixture1.Model2kunique[^\n]*1[^\n]*1",
                         stdout)