From c9a292e308ac506043a286774401641a93235549 Mon Sep 17 00:00:00 2001 From: Franco Colmenarez Date: Wed, 9 Mar 2022 11:47:35 -0500 Subject: [PATCH] WIP first test --- .gitignore | 16 +++++++++++++++- app/__init__.py | 26 ++++++++++++++++++++++++++ app/users/__init__.py | 0 app/users/api.py | 6 ++++++ start-dev.sh | 3 +++ tests/__init__.py | 0 tests/conftest.py | 25 +++++++++++++++++++++++++ tests/test_users.py | 4 ++++ 8 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 app/__init__.py create mode 100644 app/users/__init__.py create mode 100644 app/users/api.py create mode 100755 start-dev.sh create mode 100644 tests/__init__.py create mode 100644 tests/conftest.py create mode 100644 tests/test_users.py diff --git a/.gitignore b/.gitignore index 0540009..65650ee 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,16 @@ +venv/ + +*.pyc __pycache__/ -venv/ \ No newline at end of file + +instance/ + +.pytest_cache/ +.coverage +htmlcov/ + +dist/ +build/ +*.egg-info/ +*.sqlite +*.db \ No newline at end of file diff --git a/app/__init__.py b/app/__init__.py new file mode 100644 index 0000000..b74673c --- /dev/null +++ b/app/__init__.py @@ -0,0 +1,26 @@ +import os +from flask import Flask + +from app.users.api import bp as users_api_blueprint + +def create_app(test_config=None): + app = Flask(__name__, instance_relative_config=True) + app.config.from_mapping( + SECRET_KEY='dev', + DATABASE=os.path.join(app.instance_path, 'db.sqlite') + ) + + if test_config is None: + app.config.from_pyfile('config.py', silent=True) + else: + app.config.from_mapping(test_config) + + try: + os.makedirs(app.instance_path) + except OSError: + pass + + app.register_blueprint(users_api_blueprint) + + + return app diff --git a/app/users/__init__.py b/app/users/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/users/api.py b/app/users/api.py new file mode 100644 index 0000000..c34871c --- /dev/null +++ b/app/users/api.py @@ -0,0 +1,6 @@ +from flask import jsonify, Blueprint + +bp = Blueprint('users_api', __name__, url_prefix="/api/users") +@bp.route('', methods=['GET']) +def list(): + return jsonify([]) diff --git a/start-dev.sh b/start-dev.sh new file mode 100755 index 0000000..832804e --- /dev/null +++ b/start-dev.sh @@ -0,0 +1,3 @@ +export FLASK_APP=app +export FLASK_ENV=development +flask run diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..ae23ba3 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,25 @@ +import os +import tempfile + +import pytest +from app import create_app + +@pytest.fixture +def app(): + app = create_app({ + 'TESTING': True, + 'DATABASE': ':memory:', + }) + + with app.app_context(): + pass + + yield app + +@pytest.fixture +def client(app): + return app.test_client() + +@pytest.fixture +def runner(app): + return app.test_cli_runner() diff --git a/tests/test_users.py b/tests/test_users.py new file mode 100644 index 0000000..45b54c6 --- /dev/null +++ b/tests/test_users.py @@ -0,0 +1,4 @@ +def test_list_users(client): + response = client.get('/api/users') + assert response.status_code == 200 + assert response.json == [] -- 2.39.5