Compare commits

...

1 Commits

Author SHA1 Message Date
c9a292e308 WIP first test 2022-03-09 12:05:43 -05:00
8 changed files with 79 additions and 1 deletions

16
.gitignore vendored
View File

@ -1,2 +1,16 @@
__pycache__/
venv/
*.pyc
__pycache__/
instance/
.pytest_cache/
.coverage
htmlcov/
dist/
build/
*.egg-info/
*.sqlite
*.db

26
app/__init__.py Normal file
View File

@ -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

0
app/users/__init__.py Normal file
View File

6
app/users/api.py Normal file
View File

@ -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([])

3
start-dev.sh Executable file
View File

@ -0,0 +1,3 @@
export FLASK_APP=app
export FLASK_ENV=development
flask run

0
tests/__init__.py Normal file
View File

25
tests/conftest.py Normal file
View File

@ -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()

4
tests/test_users.py Normal file
View File

@ -0,0 +1,4 @@
def test_list_users(client):
response = client.get('/api/users')
assert response.status_code == 200
assert response.json == []