Compare commits

...

2 Commits

Author SHA1 Message Date
1e0ac60d1d API (#3)
Reviewed-on: #3
2022-03-09 17:09:56 +00:00
5aa3c2b371 Initialize repo (#2)
Closes #1

Reviewed-on: #2
2022-03-08 17:33:01 +00:00
11 changed files with 89 additions and 1 deletions

17
.gitignore vendored
View File

@ -1 +1,16 @@
venv 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([])

2
dev-requirements.txt Normal file
View File

@ -0,0 +1,2 @@
pytest==7.0.1
pytest-doc==0.0.1

6
main.py Normal file
View File

@ -0,0 +1,6 @@
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello_world():
return "<p>Hello, world!</p>"

1
requirements.txt Normal file
View File

@ -0,0 +1 @@
Flask==2.0.3

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 == []