Ejemplo n.º 1
0
    def setUpClass(cls):
        with app.app_context():
            db.drop_all()
            db.create_all()

            cls.test_client = app.test_client()
            cls.test_dao = UserDAO()
Ejemplo n.º 2
0
    def setUpClass(cls):
        with app.app_context():
            db.drop_all()
            db.create_all()

            cls.test_dao = UserDAO()

            test_user = User('*****@*****.**', 'testpw',
                             'test-{0}-username'.format(uuid.uuid4()))

            deleted_user = User('*****@*****.**', 'testpassword',
                                'test-{0}-username'.format(uuid.uuid4()))
            deleted_user.is_deleted = True

            user_to_delete = User('*****@*****.**', 'testpw',
                                  'test-{0}-username'.format(uuid.uuid4()))

            cls.test_uid = test_user.public_id
            cls.deleted_uid = deleted_user.public_id
            cls.to_delete_uid = user_to_delete.public_id

            db.session.add(test_user)
            db.session.add(deleted_user)
            db.session.add(user_to_delete)
            db.session.commit()
Ejemplo n.º 3
0
def create_app(config_file=None):
    """
    An application factory used to generate application contexts.

    :param config_file:
    :rtype: Flask
    :return: An application context which can be used for uwsgi runtimes or
    unit tests.
    """
    app = Flask(__name__)
    app.config.from_object('skael.config.Config')

    jwt = JWT(app, FlaskJWTWrapper.authenticate, FlaskJWTWrapper.identify)

    @jwt.jwt_payload_handler
    def jwt_handler(identity):
        iat = datetime.utcnow()
        exp = iat + app.config.get('JWT_EXPIRATION_DELTA')
        nbf = iat + app.config.get('JWT_NOT_BEFORE_DELTA')
        return {
            'exp': exp,
            'iat': iat,
            'nbf': nbf,
            'identity': identity.public_id,
            'jwt_claim': str(identity.jwt_claim)
        }

    logging.basicConfig(
        level=logging.DEBUG,
        format="[%(asctime)s] %(levelname)-8s [%(name)s] %(message)s",
        stream=(codecs.getwriter("utf-8")(sys.stdout.buffer, "replace")
                                if hasattr(sys.stdout, "buffer")
                                else None))

    with app.app_context():

        user_export_routes(app)
        verify_export_routes(app)
        reset_export_routes(app)

        # This is just a test will be removed in production
        # to follow best practises
        @app.route("/api/hello")
        def hello():
            print(list(app.url_map.iter_rules()))
            res = db.session.execute("select version()")
            postgres_version = list(res)[0][0]
            return jsonify(response="Hello, World!", postgres_version=postgres_version)
            

        register_error_handlers(app)

        db.init_app(app)
        app.db = db
        db.create_all()

    return app
    def setUpClass(cls):
        with app.app_context():
            db.drop_all()
            db.create_all()

            cls.test_client = app.test_client()
            cls.test_dao = UserDAO()

            test_user = User('*****@*****.**', 'testpw', 'test-verify')

            cls.test_user_token = test_user.verify_token
            cls.test_uid = test_user.public_id

            db.session.add(test_user)
            db.session.commit()