Пример #1
0
    def test_sanity_pass_relationship(self, engine):
        """See database sanity check understands about relationships and don't deem them as missing column."""

        conn = engine.connect()
        trans = conn.begin()

        Session = sessionmaker(bind=engine)
        session = Session()

        Base, RelationTestModel, RelationTestModel2 = gen_relation_models()
        try:
            Base.metadata.drop_all(engine,
                                   tables=[
                                       RelationTestModel.__table__,
                                       RelationTestModel2.__table__
                                   ])
        except sqlalchemy.exc.NoSuchTableError:
            pass

        Base.metadata.create_all(
            engine,
            tables=[RelationTestModel.__table__, RelationTestModel2.__table__])

        try:
            assert is_sane_database(Base, session) is True
        finally:
            Base.metadata.drop_all(engine)
Пример #2
0
    def test_sanity_table_missing(self, engine):
        """See check fails when there is a missing table"""

        conn = engine.connect()
        trans = conn.begin()

        Base, SaneTestModel = gen_test_model()
        Session = sessionmaker(bind=engine)
        session = Session()

        try:
            Base.metadata.drop_all(engine, tables=[SaneTestModel.__table__])
        except sqlalchemy.exc.NoSuchTableError:
            pass

        assert is_sane_database(Base, session) is False
Пример #3
0
    def test_sanity_column_missing(self, engine):
        """See check fails when there is a missing table"""

        conn = engine.connect()
        trans = conn.begin()

        Session = sessionmaker(bind=engine)
        session = Session()
        Base, SaneTestModel = gen_test_model()
        try:
            Base.metadata.drop_all(engine, tables=[SaneTestModel.__table__])
        except sqlalchemy.exc.NoSuchTableError:
            pass
        Base.metadata.create_all(engine, tables=[SaneTestModel.__table__])

        # Delete one of the columns
        engine.execute("ALTER TABLE sanity_check_test DROP COLUMN id")

        # engine.execute("""
        # BEGIN TRANSACTION;
        #
        # ALTER TABLE equipment RENAME TO temp_equipment;
        #
        # CREATE TABLE equipment (
        #  name text NOT NULL,
        #  model text NOT NULL,
        #  serial integer NOT NULL UNIQUE
        # );
        #
        # INSERT INTO equipment
        # SELECT
        #  name, model, serial
        # FROM
        #  temp_equipment;
        #
        # DROP TABLE temp_equipment;
        #
        # COMMIT;
        #
        # """)

        assert is_sane_database(Base, session) is False
Пример #4
0
    def test_sanity_pass(self, engine):
        """See database sanity check completes when tables and columns are created."""

        conn = engine.connect()
        trans = conn.begin()

        Base, SaneTestModel = gen_test_model()
        Session = sessionmaker(bind=engine)
        session = Session()
        try:
            Base.metadata.drop_all(engine, tables=[SaneTestModel.__table__])
        except sqlalchemy.exc.NoSuchTableError:
            pass

        Base.metadata.create_all(engine, tables=[SaneTestModel.__table__])

        try:
            assert is_sane_database(Base, session) is True
        finally:
            Base.metadata.drop_all(engine)