WIP first test
This commit is contained in:
parent
5aa3c2b371
commit
c9a292e308
16
.gitignore
vendored
16
.gitignore
vendored
@ -1,2 +1,16 @@
|
|||||||
|
venv/
|
||||||
|
|
||||||
|
*.pyc
|
||||||
__pycache__/
|
__pycache__/
|
||||||
venv/
|
|
||||||
|
instance/
|
||||||
|
|
||||||
|
.pytest_cache/
|
||||||
|
.coverage
|
||||||
|
htmlcov/
|
||||||
|
|
||||||
|
dist/
|
||||||
|
build/
|
||||||
|
*.egg-info/
|
||||||
|
*.sqlite
|
||||||
|
*.db
|
26
app/__init__.py
Normal file
26
app/__init__.py
Normal 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
0
app/users/__init__.py
Normal file
6
app/users/api.py
Normal file
6
app/users/api.py
Normal 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
3
start-dev.sh
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
export FLASK_APP=app
|
||||||
|
export FLASK_ENV=development
|
||||||
|
flask run
|
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
25
tests/conftest.py
Normal file
25
tests/conftest.py
Normal 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
4
tests/test_users.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
def test_list_users(client):
|
||||||
|
response = client.get('/api/users')
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert response.json == []
|
Loading…
Reference in New Issue
Block a user