from flask import Flask, request, jsonify from db_config import db, ma from user import UserModel, UserSchema, UserCRUD import datetime from collections import defaultdict app = Flask(__name__) app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///example.db" app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = True app.config["SQLALCHEMY_ECHO"] = False app.config['JSON_AS_ASCII'] = False db.init_app(app) with app.app_context(): db.create_all() ma.init_app(app) @app.route("/") def hello_world(): return "Hello World" @app.route("/users", methods=["GET", "POST"]) def users(): method = request.method if method == "GET": page_size = request.args.get("page_size") page_number = request.args.get("page_number") list_user, total = UserCRUD().get_all(page_size=page_size,
import json import os import connexion import pytest from config import my_app from db_config import db flask_app = connexion.FlaskApp(__name__) # setting in memory database for testing SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(my_app.root_path, 'database/test.db') flask_app.app.config['SQLALCHEMY_DATABASE_URI'] = SQLALCHEMY_DATABASE_URI flask_app.app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db.init_app(flask_app.app) flask_app.add_api('../swagger/swagger.yml') @pytest.fixture(scope='module') def client(): with flask_app.app.test_client() as c: yield c @pytest.fixture(scope='module') def helper(json_info): for info in json_info: first_row = info.decode("utf-8") return str(json.loads(first_row)) def test_users_tc0001_get(client):