コード例 #1
0
ファイル: test_resource.py プロジェクト: eReuse/teal
def test_init_db(db: SQLAlchemy, config: Config):
    """Tests :meth:`teal.resource.Resource.init_db` with one inventory."""

    class Foo(db.Model):
        id = Column(db.Integer, primary_key=True)

    class FooDef(Resource):
        __type__ = 'Foo'

        def init_db(self, db: SQLAlchemy, exclude_schema=None):
            db.session.add(Foo())

    config.RESOURCE_DEFINITIONS = FooDef,
    app = Teal(config=config, db=db)
    with app.app_context():
        app.init_db()
    with app.app_context():
        # If no commit happened in init_db() or anything else
        # this would not exist
        assert Foo.query.filter_by(id=1).one()

    # Test again but executing init-db through the command-line
    runner = app.test_cli_runner()
    runner.invoke('init-db')
    with app.app_context():
        assert Foo.query.filter_by(id=2).one()

    # Test with --erase option
    runner.invoke('init-db', '--erase')
    with app.app_context():
        assert Foo.query.count() == 1
コード例 #2
0
ファイル: conftest.py プロジェクト: eReuse/teal
def runner(app: Teal) -> FlaskCliRunner:
    return app.test_cli_runner()