Esempio n. 1
0
    def test_not_initialized_teardown_connection(self):
        pg = PGEvents()
        pg._psycopg2_connection = 1

        pg._teardown_connection()

        assert pg._psycopg2_connection == 1
Esempio n. 2
0
    def test_teardown(self, app, db):
        pg = PGEvents(app)

        pg.teardown()

        assert pg._psycopg2_connection is None
        assert pg._connection is None
Esempio n. 3
0
    def test_init_app_no_sqlalchemy(self, app):
        pg = PGEvents()

        with raises(RuntimeError):
            pg.init_app(app)

        assert pg._app is not None
        assert not pg._initialized
Esempio n. 4
0
    def teardown_not_initialized(self):
        pg = PGEvents()

        pg._psycopg2_connection = 1

        pg.teardown()

        assert (pg._psycopg2_connection == 1)
class create_pgevents:
    def __init__(self, app=None):
        self.pgevents = PGEvents(app)

    def __enter__(self):
        return self.pgevents

    def __exit__(self, exc_type, exc_val, exc_tb):
        self.pgevents.teardown()
Esempio n. 6
0
    def test_teardown_connection(self, app, db):
        pg = PGEvents(app)

        pg._teardown_connection()

        assert pg._psycopg2_connection is None
        assert pg._connection is None

        # Set to False so that teardown() isn't called as part of cleanup
        pg._initialized = False
Esempio n. 7
0
    def test_init_app(self, app, db):
        pg = PGEvents()

        assert not pg._initialized

        pg.init_app(app)

        assert pg._app == app
        assert pg._connection is not None
        assert pg._psycopg2_connection is not None

        with create_connection(db, raw=True) as conn:
            trigger_function_installed_ = trigger_function_installed(conn)
            assert trigger_function_installed_

        assert app.extensions.get("pgevents", None) is not None
        assert pg._initialized
Esempio n. 8
0
    def test_init_app(self, app, db):
        pg = PGEvents()

        assert (pg._initialized == False)

        pg.init_app(app)

        assert (pg._app == app)
        assert (pg._connection is not None)
        assert (pg._psycopg2_connection is not None)

        with create_connection(db, raw=True) as conn:
            trigger_function_installed_ = trigger_function_installed(conn)
            assert (trigger_function_installed_ == True)

        assert (app.extensions.get('pgevents', None) is not None)
        assert (pg._initialized == True)
Esempio n. 9
0
    SQLALCHEMY_DATABASE_URI: str = environ.get("DATABASE_URL",
                                               "postgres:///postgres")
    SQLALCHEMY_TRACK_MODIFICATIONS: bool = False

    PSYCOPG2_PGEVENTS_DEBUG: bool = environ.get("PSYCOPG2_PGEVENTS_DEBUG",
                                                False)


# Create app
APP = Flask(__name__)
APP.config.from_object(Config)

# Create extensions
DB = SQLAlchemy()
PG = PGEvents()
HUEY = MiniHuey()

#
# Define Models
#


class UserAccount(DB.Model):
    """Model that represents a user accuont.

    Attributes
    ----------
    __tablename__: str
        Table name, as set by Heroku Connect
    id: DB.Integer
 def __init__(self, app=None):
     self.pgevents = PGEvents(app)
Esempio n. 11
0
    def test_init(self, app):
        pg = PGEvents()

        assert not pg._initialized
Esempio n. 12
0
    def test_init_w_app(self, app):
        with raises(RuntimeError):
            pg = PGEvents(app)

            assert pg._app is not None
            assert not pg._initialized
Esempio n. 13
0
    def test_init(self, app):
        pg = PGEvents()

        assert (pg._initialized == False)