diff --git a/app/__init__.py b/app/__init__.py index 864dbdf..64fbf94 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -10,13 +10,14 @@ def create_app(env=None): from app.routes import register_routes app = Flask(__name__) - app.config.from_object(config_by_name[env or 'test']) - api = Api(app, title='Flaskerific API', version='0.1.0') + app.config.from_object(config_by_name[env or "test"]) + api = Api(app, title="Flaskerific API", version="0.1.0") register_routes(api, app) db.init_app(app) - @app.route('/health') + @app.route("/health") def health(): - return jsonify('healthy') + return jsonify("healthy") + return app diff --git a/app/__init__test.py b/app/__init__test.py index 6ab181b..b83624f 100644 --- a/app/__init__test.py +++ b/app/__init__test.py @@ -7,7 +7,7 @@ def test_app_creates(app): # noqa def test_app_healthy(app, client): # noqa with client: - resp = client.get('/health') + resp = client.get("/health") assert resp.status_code == 200 assert resp.is_json - assert resp.json == 'healthy' + assert resp.json == "healthy" diff --git a/app/config.py b/app/config.py index 3217831..b4bb7a9 100644 --- a/app/config.py +++ b/app/config.py @@ -5,16 +5,17 @@ basedir = os.path.abspath(os.path.dirname(__file__)) class BaseConfig: - CONFIG_NAME = 'base' + CONFIG_NAME = "base" USE_MOCK_EQUIVALENCY = False DEBUG = False SQLALCHEMY_TRACK_MODIFICATIONS = False class DevelopmentConfig(BaseConfig): - CONFIG_NAME = 'dev' + CONFIG_NAME = "dev" SECRET_KEY = os.getenv( - "DEV_SECRET_KEY", "You can't see California without Marlon Widgeto's eyes") + "DEV_SECRET_KEY", "You can't see California without Marlon Widgeto's eyes" + ) DEBUG = True SQLALCHEMY_TRACK_MODIFICATIONS = False TESTING = False @@ -22,7 +23,7 @@ class DevelopmentConfig(BaseConfig): class TestingConfig(BaseConfig): - CONFIG_NAME = 'test' + CONFIG_NAME = "test" SECRET_KEY = os.getenv("TEST_SECRET_KEY", "Thanos did nothing wrong") DEBUG = True SQLALCHEMY_TRACK_MODIFICATIONS = False @@ -31,7 +32,7 @@ class TestingConfig(BaseConfig): class ProductionConfig(BaseConfig): - CONFIG_NAME = 'prod' + CONFIG_NAME = "prod" SECRET_KEY = os.getenv("PROD_SECRET_KEY", "I'm Ron Burgundy?") DEBUG = False SQLALCHEMY_TRACK_MODIFICATIONS = False @@ -40,5 +41,8 @@ class ProductionConfig(BaseConfig): EXPORT_CONFIGS: List[Type[BaseConfig]] = [ - DevelopmentConfig, TestingConfig, ProductionConfig] + DevelopmentConfig, + TestingConfig, + ProductionConfig, +] config_by_name = {cfg.CONFIG_NAME: cfg for cfg in EXPORT_CONFIGS} diff --git a/app/fizz/__init__.py b/app/fizz/__init__.py index 60ae9d0..8de367d 100644 --- a/app/fizz/__init__.py +++ b/app/fizz/__init__.py @@ -1,9 +1,9 @@ -BASE_ROUTE = 'fizz' +BASE_ROUTE = "fizz" -def register_routes(api, app, root='api'): +def register_routes(api, app, root="api"): from .fizzbar.controller import api as fizzbar_api from .fizzbaz.controller import api as fizzbaz_api - api.add_namespace(fizzbar_api, path=f'/{root}/{BASE_ROUTE}/fizzbar') - api.add_namespace(fizzbaz_api, path=f'/{root}/{BASE_ROUTE}/fizzbaz') + api.add_namespace(fizzbar_api, path=f"/{root}/{BASE_ROUTE}/fizzbar") + api.add_namespace(fizzbaz_api, path=f"/{root}/{BASE_ROUTE}/fizzbaz") diff --git a/app/fizz/fizzbar/controller.py b/app/fizz/fizzbar/controller.py index f52f4cd..dc3b379 100644 --- a/app/fizz/fizzbar/controller.py +++ b/app/fizz/fizzbar/controller.py @@ -9,47 +9,48 @@ from .service import FizzbarService from .model import Fizzbar from .interface import FizzbarInterface -api = Namespace('Fizzbar', description='A modular namespace within fizz') # noqa +api = Namespace("Fizzbar", description="A modular namespace within fizz") # noqa -@api.route('/') +@api.route("/") class FizzbarResource(Resource): - '''Fizzbars''' + """Fizzbars""" @responds(schema=FizzbarSchema, many=True) def get(self) -> List[Fizzbar]: - '''Get all Fizzbars''' + """Get all Fizzbars""" return FizzbarService.get_all() @accepts(schema=FizzbarSchema, api=api) @responds(schema=FizzbarSchema) def post(self) -> Fizzbar: - '''Create a Single Fizzbar''' + """Create a Single Fizzbar""" return FizzbarService.create(request.parsed_obj) -@api.route('/') -@api.param('fizzbarId', 'Fizzbar database ID') +@api.route("/") +@api.param("fizzbarId", "Fizzbar database ID") class FizzbarIdResource(Resource): @responds(schema=FizzbarSchema) def get(self, fizzbarId: int) -> Fizzbar: - '''Get Single Fizzbar''' + """Get Single Fizzbar""" return FizzbarService.get_by_id(fizzbarId) def delete(self, fizzbarId: int) -> Response: - '''Delete Single Fizzbar''' + """Delete Single Fizzbar""" from flask import jsonify - print('fizzbarId = ', fizzbarId) + + print("fizzbarId = ", fizzbarId) id = FizzbarService.delete_by_id(fizzbarId) - return jsonify(dict(status='Success', id=id)) + return jsonify(dict(status="Success", id=id)) @accepts(schema=FizzbarSchema, api=api) @responds(schema=FizzbarSchema) def put(self, fizzbarId: int) -> Fizzbar: - '''Update Single Fizzbar''' + """Update Single Fizzbar""" changes: FizzbarInterface = request.parsed_obj Fizzbar = FizzbarService.get_by_id(fizzbarId) diff --git a/app/fizz/fizzbar/controller_test.py b/app/fizz/fizzbar/controller_test.py index d195c74..e6359e3 100644 --- a/app/fizz/fizzbar/controller_test.py +++ b/app/fizz/fizzbar/controller_test.py @@ -1,4 +1,3 @@ - from unittest.mock import patch from flask.testing import FlaskClient @@ -10,75 +9,91 @@ from .interface import FizzbarInterface from .. import BASE_ROUTE -def make_fizzbar(id: int = 123, name: str = 'Test fizzbar', - purpose: str = 'Test purpose') -> Fizzbar: - return Fizzbar( - fizzbar_id=id, name=name, purpose=purpose - ) +def make_fizzbar( + id: int = 123, name: str = "Test fizzbar", purpose: str = "Test purpose" +) -> Fizzbar: + return Fizzbar(fizzbar_id=id, name=name, purpose=purpose) class TestFizzbarResource: - @patch.object(FizzbarService, 'get_all', - lambda: [make_fizzbar(123, name='Test Fizzbar 1'), - make_fizzbar(456, name='Test Fizzbar 2')]) + @patch.object( + FizzbarService, + "get_all", + lambda: [ + make_fizzbar(123, name="Test Fizzbar 1"), + make_fizzbar(456, name="Test Fizzbar 2"), + ], + ) def test_get(self, client: FlaskClient): # noqa with client: - results = client.get(f'/api/{BASE_ROUTE}/fizzbar', - follow_redirects=True).get_json() - expected = FizzbarSchema(many=True).dump( - [make_fizzbar(123, name='Test Fizzbar 1'), - make_fizzbar(456, name='Test Fizzbar 2')] - ).data + results = client.get( + f"/api/{BASE_ROUTE}/fizzbar", follow_redirects=True + ).get_json() + expected = ( + FizzbarSchema(many=True) + .dump( + [ + make_fizzbar(123, name="Test Fizzbar 1"), + make_fizzbar(456, name="Test Fizzbar 2"), + ] + ) + .data + ) for r in results: assert r in expected - @patch.object(FizzbarService, 'create', - lambda create_request: Fizzbar(**create_request)) + @patch.object( + FizzbarService, "create", lambda create_request: Fizzbar(**create_request) + ) def test_post(self, client: FlaskClient): # noqa with client: - payload = dict(name='Test fizzbar', purpose='Test purpose') - result = client.post(f'/api/{BASE_ROUTE}/fizzbar/', json=payload).get_json() - expected = FizzbarSchema().dump(Fizzbar( - name=payload['name'], - purpose=payload['purpose'], - )).data + payload = dict(name="Test fizzbar", purpose="Test purpose") + result = client.post(f"/api/{BASE_ROUTE}/fizzbar/", json=payload).get_json() + expected = ( + FizzbarSchema() + .dump(Fizzbar(name=payload["name"], purpose=payload["purpose"])) + .data + ) assert result == expected def fake_update(fizzbar: Fizzbar, changes: FizzbarInterface) -> Fizzbar: # To fake an update, just return a new object - updated_Fizzbar = Fizzbar(fizzbar_id=fizzbar.fizzbar_id, - name=changes['name'], - purpose=changes['purpose']) + updated_Fizzbar = Fizzbar( + fizzbar_id=fizzbar.fizzbar_id, name=changes["name"], purpose=changes["purpose"] + ) return updated_Fizzbar class TestFizzbarIdResource: - @patch.object(FizzbarService, 'get_by_id', - lambda id: make_fizzbar(id=id)) + @patch.object(FizzbarService, "get_by_id", lambda id: make_fizzbar(id=id)) def test_get(self, client: FlaskClient): # noqa with client: - result = client.get(f'/api/{BASE_ROUTE}/fizzbar/123').get_json() + result = client.get(f"/api/{BASE_ROUTE}/fizzbar/123").get_json() expected = Fizzbar(fizzbar_id=123) - assert result['fizzbarId'] == expected.fizzbar_id + assert result["fizzbarId"] == expected.fizzbar_id - @patch.object(FizzbarService, 'delete_by_id', - lambda id: [id]) + @patch.object(FizzbarService, "delete_by_id", lambda id: [id]) def test_delete(self, client: FlaskClient): # noqa with client: - result = client.delete(f'/api/{BASE_ROUTE}/fizzbar/123').get_json() - expected = dict(status='Success', id=[123]) + result = client.delete(f"/api/{BASE_ROUTE}/fizzbar/123").get_json() + expected = dict(status="Success", id=[123]) assert result == expected - @patch.object(FizzbarService, 'get_by_id', - lambda id: make_fizzbar(id=id)) - @patch.object(FizzbarService, 'update', fake_update) + @patch.object(FizzbarService, "get_by_id", lambda id: make_fizzbar(id=id)) + @patch.object(FizzbarService, "update", fake_update) def test_put(self, client: FlaskClient): # noqa with client: - result = client.put(f'/api/{BASE_ROUTE}/fizzbar/123', - json={'name': 'New Fizzbar', - 'purpose': 'New purpose'}).get_json() - expected = FizzbarSchema().dump( - Fizzbar(fizzbar_id=123, name='New Fizzbar', purpose='New purpose')).data + result = client.put( + f"/api/{BASE_ROUTE}/fizzbar/123", + json={"name": "New Fizzbar", "purpose": "New purpose"}, + ).get_json() + expected = ( + FizzbarSchema() + .dump( + Fizzbar(fizzbar_id=123, name="New Fizzbar", purpose="New purpose") + ) + .data + ) assert result == expected diff --git a/app/fizz/fizzbar/interface_test.py b/app/fizz/fizzbar/interface_test.py index 2986372..5ae1ca5 100644 --- a/app/fizz/fizzbar/interface_test.py +++ b/app/fizz/fizzbar/interface_test.py @@ -5,9 +5,7 @@ from .interface import FizzbarInterface @fixture def interface() -> FizzbarInterface: - return FizzbarInterface( - fizzbar_id=1, name='Test fizzbar', purpose='Test purpose' - ) + return FizzbarInterface(fizzbar_id=1, name="Test fizzbar", purpose="Test purpose") def test_FizzbarInterface_create(interface: FizzbarInterface): diff --git a/app/fizz/fizzbar/model.py b/app/fizz/fizzbar/model.py index b086921..fa3ae69 100644 --- a/app/fizz/fizzbar/model.py +++ b/app/fizz/fizzbar/model.py @@ -5,9 +5,9 @@ from typing import Any class Fizzbar(db.Model): # type: ignore - '''A snazzy Fizzbar''' + """A snazzy Fizzbar""" - __tablename__ = 'fizzbar' + __tablename__ = "fizzbar" fizzbar_id = Column(Integer(), primary_key=True) name = Column(String(255)) diff --git a/app/fizz/fizzbar/model_test.py b/app/fizz/fizzbar/model_test.py index defb472..669c4dd 100644 --- a/app/fizz/fizzbar/model_test.py +++ b/app/fizz/fizzbar/model_test.py @@ -6,9 +6,7 @@ from .model import Fizzbar @fixture def fizzbar() -> Fizzbar: - return Fizzbar( - fizzbar_id=1, name='Test fizzbar', purpose='Test purpose' - ) + return Fizzbar(fizzbar_id=1, name="Test fizzbar", purpose="Test purpose") def test_Fizzbar_create(fizzbar: Fizzbar): diff --git a/app/fizz/fizzbar/schema.py b/app/fizz/fizzbar/schema.py index 10d79a5..f940fd4 100644 --- a/app/fizz/fizzbar/schema.py +++ b/app/fizz/fizzbar/schema.py @@ -2,8 +2,8 @@ from marshmallow import fields, Schema class FizzbarSchema(Schema): - '''Fizzbar schema''' + """Fizzbar schema""" - fizzbarId = fields.Number(attribute='fizzbar_id') - name = fields.String(attribute='name') - purpose = fields.String(attribute='purpose') + fizzbarId = fields.Number(attribute="fizzbar_id") + name = fields.String(attribute="name") + purpose = fields.String(attribute="purpose") diff --git a/app/fizz/fizzbar/schema_test.py b/app/fizz/fizzbar/schema_test.py index 9a23404..87ca094 100644 --- a/app/fizz/fizzbar/schema_test.py +++ b/app/fizz/fizzbar/schema_test.py @@ -15,13 +15,11 @@ def test_FizzbarSchema_create(schema: FizzbarSchema): def test_FizzbarSchema_works(schema: FizzbarSchema): - params: FizzbarInterface = schema.load({ - 'fizzbarId': '123', - 'name': 'Test fizzbar', - 'purpose': 'Test purpose' - }).data + params: FizzbarInterface = schema.load( + {"fizzbarId": "123", "name": "Test fizzbar", "purpose": "Test purpose"} + ).data fizzbar = Fizzbar(**params) assert fizzbar.fizzbar_id == 123 - assert fizzbar.name == 'Test fizzbar' - assert fizzbar.purpose == 'Test purpose' + assert fizzbar.name == "Test fizzbar" + assert fizzbar.purpose == "Test purpose" diff --git a/app/fizz/fizzbar/service.py b/app/fizz/fizzbar/service.py index 28a799c..cc90311 100644 --- a/app/fizz/fizzbar/service.py +++ b/app/fizz/fizzbar/service.py @@ -4,7 +4,7 @@ from .model import Fizzbar from .interface import FizzbarInterface -class FizzbarService(): +class FizzbarService: @staticmethod def get_all() -> List[Fizzbar]: return Fizzbar.query.all() @@ -30,10 +30,7 @@ class FizzbarService(): @staticmethod def create(new_attrs: FizzbarInterface) -> Fizzbar: - new_fizzbar = Fizzbar( - name=new_attrs['name'], - purpose=new_attrs['purpose'] - ) + new_fizzbar = Fizzbar(name=new_attrs["name"], purpose=new_attrs["purpose"]) db.session.add(new_fizzbar) db.session.commit() diff --git a/app/fizz/fizzbar/service_test.py b/app/fizz/fizzbar/service_test.py index c3c4c76..d0e5e98 100644 --- a/app/fizz/fizzbar/service_test.py +++ b/app/fizz/fizzbar/service_test.py @@ -7,8 +7,8 @@ from .interface import FizzbarInterface def test_get_all(db: SQLAlchemy): # noqa - yin: Fizzbar = Fizzbar(fizzbar_id=1, name='Yin', purpose='thing 1') - yang: Fizzbar = Fizzbar(fizzbar_id=2, name='Yang', purpose='thing 2') + yin: Fizzbar = Fizzbar(fizzbar_id=1, name="Yin", purpose="thing 1") + yang: Fizzbar = Fizzbar(fizzbar_id=2, name="Yang", purpose="thing 2") db.session.add(yin) db.session.add(yang) db.session.commit() @@ -20,21 +20,21 @@ def test_get_all(db: SQLAlchemy): # noqa def test_update(db: SQLAlchemy): # noqa - yin: Fizzbar = Fizzbar(fizzbar_id=1, name='Yin', purpose='thing 1') + yin: Fizzbar = Fizzbar(fizzbar_id=1, name="Yin", purpose="thing 1") db.session.add(yin) db.session.commit() - updates: FizzbarInterface = dict(name='New Fizzbar name') + updates: FizzbarInterface = dict(name="New Fizzbar name") FizzbarService.update(yin, updates) result: Fizzbar = Fizzbar.query.get(yin.fizzbar_id) - assert result.name == 'New Fizzbar name' + assert result.name == "New Fizzbar name" def test_delete_by_id(db: SQLAlchemy): # noqa - yin: Fizzbar = Fizzbar(fizzbar_id=1, name='Yin', purpose='thing 1') - yang: Fizzbar = Fizzbar(fizzbar_id=2, name='Yang', purpose='thing 2') + yin: Fizzbar = Fizzbar(fizzbar_id=1, name="Yin", purpose="thing 1") + yang: Fizzbar = Fizzbar(fizzbar_id=2, name="Yang", purpose="thing 2") db.session.add(yin) db.session.add(yang) db.session.commit() @@ -50,7 +50,7 @@ def test_delete_by_id(db: SQLAlchemy): # noqa def test_create(db: SQLAlchemy): # noqa - yin: FizzbarInterface = dict(name='Fancy new fizzbar', purpose='Fancy new purpose') + yin: FizzbarInterface = dict(name="Fancy new fizzbar", purpose="Fancy new purpose") FizzbarService.create(yin) results: List[Fizzbar] = Fizzbar.query.all() diff --git a/app/fizz/fizzbaz/controller.py b/app/fizz/fizzbaz/controller.py index 9d4c606..62c0337 100644 --- a/app/fizz/fizzbaz/controller.py +++ b/app/fizz/fizzbaz/controller.py @@ -9,47 +9,47 @@ from .service import FizzbazService from .model import Fizzbaz from .interface import FizzbazInterface -api = Namespace('Fizzbaz', description='A modular namespace within fizz') # noqa +api = Namespace("Fizzbaz", description="A modular namespace within fizz") # noqa -@api.route('/') +@api.route("/") class FizzbazResource(Resource): - '''Fizzbazs''' + """Fizzbaz""" @responds(schema=FizzbazSchema, many=True) def get(self) -> List[Fizzbaz]: - '''Get all Fizzbazs''' + """Get all Fizzbaz""" return FizzbazService.get_all() @accepts(schema=FizzbazSchema, api=api) @responds(schema=FizzbazSchema) def post(self) -> Fizzbaz: - '''Create a Single Fizzbaz''' + """Create a Single Fizzbaz""" return FizzbazService.create(request.parsed_obj) -@api.route('/') -@api.param('fizzbazId', 'Fizzbaz database ID') +@api.route("/") +@api.param("fizzbazId", "Fizzbaz database ID") class FizzbazIdResource(Resource): @responds(schema=FizzbazSchema) def get(self, fizzbazId: int) -> Fizzbaz: - '''Get Single Fizzbaz''' + """Get Single Fizzbaz""" return FizzbazService.get_by_id(fizzbazId) def delete(self, fizzbazId: int) -> Response: - '''Delete Single Fizzbaz''' + """Delete Single Fizzbaz""" from flask import jsonify id = FizzbazService.delete_by_id(fizzbazId) - return jsonify(dict(status='Success', id=id)) + return jsonify(dict(status="Success", id=id)) @accepts(schema=FizzbazSchema, api=api) @responds(schema=FizzbazSchema) def put(self, fizzbazId: int) -> Fizzbaz: - '''Update Single Fizzbaz''' + """Update Single Fizzbaz""" changes: FizzbazInterface = request.parsed_obj Fizzbaz = FizzbazService.get_by_id(fizzbazId) diff --git a/app/fizz/fizzbaz/controller_test.py b/app/fizz/fizzbaz/controller_test.py index edccf2b..7228f4b 100644 --- a/app/fizz/fizzbaz/controller_test.py +++ b/app/fizz/fizzbaz/controller_test.py @@ -1,4 +1,3 @@ - from unittest.mock import patch from flask.testing import FlaskClient @@ -10,75 +9,91 @@ from .interface import FizzbazInterface from .. import BASE_ROUTE -def make_fizzbaz(id: int = 123, name: str = 'Test fizzbaz', - purpose: str = 'Test purpose') -> Fizzbaz: - return Fizzbaz( - fizzbaz_id=id, name=name, purpose=purpose - ) +def make_fizzbaz( + id: int = 123, name: str = "Test fizzbaz", purpose: str = "Test purpose" +) -> Fizzbaz: + return Fizzbaz(fizzbaz_id=id, name=name, purpose=purpose) class TestFizzbazResource: - @patch.object(FizzbazService, 'get_all', - lambda: [make_fizzbaz(123, name='Test Fizzbaz 1'), - make_fizzbaz(456, name='Test Fizzbaz 2')]) + @patch.object( + FizzbazService, + "get_all", + lambda: [ + make_fizzbaz(123, name="Test Fizzbaz 1"), + make_fizzbaz(456, name="Test Fizzbaz 2"), + ], + ) def test_get(self, client: FlaskClient): # noqa with client: - results = client.get(f'/api/{BASE_ROUTE}/fizzbaz', - follow_redirects=True).get_json() - expected = FizzbazSchema(many=True).dump( - [make_fizzbaz(123, name='Test Fizzbaz 1'), - make_fizzbaz(456, name='Test Fizzbaz 2')] - ).data + results = client.get( + f"/api/{BASE_ROUTE}/fizzbaz", follow_redirects=True + ).get_json() + expected = ( + FizzbazSchema(many=True) + .dump( + [ + make_fizzbaz(123, name="Test Fizzbaz 1"), + make_fizzbaz(456, name="Test Fizzbaz 2"), + ] + ) + .data + ) for r in results: assert r in expected - @patch.object(FizzbazService, 'create', - lambda create_request: Fizzbaz(**create_request)) + @patch.object( + FizzbazService, "create", lambda create_request: Fizzbaz(**create_request) + ) def test_post(self, client: FlaskClient): # noqa with client: - payload = dict(name='Test fizzbaz', purpose='Test purpose') - result = client.post(f'/api/{BASE_ROUTE}/fizzbaz/', json=payload).get_json() - expected = FizzbazSchema().dump(Fizzbaz( - name=payload['name'], - purpose=payload['purpose'], - )).data + payload = dict(name="Test fizzbaz", purpose="Test purpose") + result = client.post(f"/api/{BASE_ROUTE}/fizzbaz/", json=payload).get_json() + expected = ( + FizzbazSchema() + .dump(Fizzbaz(name=payload["name"], purpose=payload["purpose"])) + .data + ) assert result == expected def fake_update(fizzbaz: Fizzbaz, changes: FizzbazInterface) -> Fizzbaz: # To fake an update, just return a new object - updated_Fizzbaz = Fizzbaz(fizzbaz_id=fizzbaz.fizzbaz_id, - name=changes['name'], - purpose=changes['purpose']) + updated_Fizzbaz = Fizzbaz( + fizzbaz_id=fizzbaz.fizzbaz_id, name=changes["name"], purpose=changes["purpose"] + ) return updated_Fizzbaz class TestFizzbazIdResource: - @patch.object(FizzbazService, 'get_by_id', - lambda id: make_fizzbaz(id=id)) + @patch.object(FizzbazService, "get_by_id", lambda id: make_fizzbaz(id=id)) def test_get(self, client: FlaskClient): # noqa with client: - result = client.get(f'/api/{BASE_ROUTE}/fizzbaz/123').get_json() + result = client.get(f"/api/{BASE_ROUTE}/fizzbaz/123").get_json() expected = Fizzbaz(fizzbaz_id=123) - assert result['fizzbazId'] == expected.fizzbaz_id + assert result["fizzbazId"] == expected.fizzbaz_id - @patch.object(FizzbazService, 'delete_by_id', - lambda id: [id]) + @patch.object(FizzbazService, "delete_by_id", lambda id: [id]) def test_delete(self, client: FlaskClient): # noqa with client: - result = client.delete(f'/api/{BASE_ROUTE}/fizzbaz/123').get_json() - expected = dict(status='Success', id=[123]) + result = client.delete(f"/api/{BASE_ROUTE}/fizzbaz/123").get_json() + expected = dict(status="Success", id=[123]) assert result == expected - @patch.object(FizzbazService, 'get_by_id', - lambda id: make_fizzbaz(id=id)) - @patch.object(FizzbazService, 'update', fake_update) + @patch.object(FizzbazService, "get_by_id", lambda id: make_fizzbaz(id=id)) + @patch.object(FizzbazService, "update", fake_update) def test_put(self, client: FlaskClient): # noqa with client: - result = client.put(f'/api/{BASE_ROUTE}/fizzbaz/123', - json={'name': 'New Fizzbaz', - 'purpose': 'New purpose'}).get_json() - expected = FizzbazSchema().dump( - Fizzbaz(fizzbaz_id=123, name='New Fizzbaz', purpose='New purpose')).data + result = client.put( + f"/api/{BASE_ROUTE}/fizzbaz/123", + json={"name": "New Fizzbaz", "purpose": "New purpose"}, + ).get_json() + expected = ( + FizzbazSchema() + .dump( + Fizzbaz(fizzbaz_id=123, name="New Fizzbaz", purpose="New purpose") + ) + .data + ) assert result == expected diff --git a/app/fizz/fizzbaz/interface_test.py b/app/fizz/fizzbaz/interface_test.py index a2d06c9..359b56c 100644 --- a/app/fizz/fizzbaz/interface_test.py +++ b/app/fizz/fizzbaz/interface_test.py @@ -5,9 +5,7 @@ from .interface import FizzbazInterface @fixture def interface() -> FizzbazInterface: - return FizzbazInterface( - fizzbaz_id=1, name='Test fizzbaz', purpose='Test purpose' - ) + return FizzbazInterface(fizzbaz_id=1, name="Test fizzbaz", purpose="Test purpose") def test_FizzbazInterface_create(interface: FizzbazInterface): diff --git a/app/fizz/fizzbaz/model.py b/app/fizz/fizzbaz/model.py index e3d6142..231b231 100644 --- a/app/fizz/fizzbaz/model.py +++ b/app/fizz/fizzbaz/model.py @@ -5,9 +5,9 @@ from typing import Any class Fizzbaz(db.Model): # type: ignore - '''A snazzy Fizzbaz''' + """A snazzy Fizzbaz""" - __tablename__ = 'fizzbaz' + __tablename__ = "fizzbaz" fizzbaz_id = Column(Integer(), primary_key=True) name = Column(String(255)) diff --git a/app/fizz/fizzbaz/model_test.py b/app/fizz/fizzbaz/model_test.py index 7c0fd09..7ec05fd 100644 --- a/app/fizz/fizzbaz/model_test.py +++ b/app/fizz/fizzbaz/model_test.py @@ -6,9 +6,7 @@ from .model import Fizzbaz @fixture def fizzbaz() -> Fizzbaz: - return Fizzbaz( - fizzbaz_id=1, name='Test fizzbaz', purpose='Test purpose' - ) + return Fizzbaz(fizzbaz_id=1, name="Test fizzbaz", purpose="Test purpose") def test_Fizzbaz_create(fizzbaz: Fizzbaz): diff --git a/app/fizz/fizzbaz/schema.py b/app/fizz/fizzbaz/schema.py index 104ba35..e7cbc04 100644 --- a/app/fizz/fizzbaz/schema.py +++ b/app/fizz/fizzbaz/schema.py @@ -2,8 +2,8 @@ from marshmallow import fields, Schema class FizzbazSchema(Schema): - '''Fizzbaz schema''' + """Fizzbaz schema""" - fizzbazId = fields.Number(attribute='fizzbaz_id') - name = fields.String(attribute='name') - purpose = fields.String(attribute='purpose') + fizzbazId = fields.Number(attribute="fizzbaz_id") + name = fields.String(attribute="name") + purpose = fields.String(attribute="purpose") diff --git a/app/fizz/fizzbaz/schema_test.py b/app/fizz/fizzbaz/schema_test.py index 72f0bc0..c9eecf5 100644 --- a/app/fizz/fizzbaz/schema_test.py +++ b/app/fizz/fizzbaz/schema_test.py @@ -15,13 +15,11 @@ def test_FizzbazSchema_create(schema: FizzbazSchema): def test_FizzbazSchema_works(schema: FizzbazSchema): - params: FizzbazInterface = schema.load({ - 'fizzbazId': '123', - 'name': 'Test fizzbaz', - 'purpose': 'Test purpose' - }).data + params: FizzbazInterface = schema.load( + {"fizzbazId": "123", "name": "Test fizzbaz", "purpose": "Test purpose"} + ).data fizzbaz = Fizzbaz(**params) assert fizzbaz.fizzbaz_id == 123 - assert fizzbaz.name == 'Test fizzbaz' - assert fizzbaz.purpose == 'Test purpose' + assert fizzbaz.name == "Test fizzbaz" + assert fizzbaz.purpose == "Test purpose" diff --git a/app/other_api/__init__.py b/app/other_api/__init__.py index 38d0ef0..4312513 100644 --- a/app/other_api/__init__.py +++ b/app/other_api/__init__.py @@ -1,16 +1,16 @@ -BASE_ROUTE = 'other_api' +BASE_ROUTE = "other_api" -def register_routes(api, app, root='api'): +def register_routes(api, app, root="api"): from flask import Blueprint from flask_restplus import Api - bp = Blueprint('other_api', __name__) - api = Api(bp, title='Another API with separate Swagger docs', version='0.1.0') + bp = Blueprint("other_api", __name__) + api = Api(bp, title="Another API with separate Swagger docs", version="0.1.0") from .doodad.controller import api as doodad_api from .whatsit.controller import api as whatsit_api - api.add_namespace(doodad_api, path=f'/doodad') - api.add_namespace(whatsit_api, path=f'/whatsit') - app.register_blueprint(bp, url_prefix=f'/{root}/{BASE_ROUTE}') + api.add_namespace(doodad_api, path=f"/doodad") + api.add_namespace(whatsit_api, path=f"/whatsit") + app.register_blueprint(bp, url_prefix=f"/{root}/{BASE_ROUTE}") diff --git a/app/other_api/doodad/controller.py b/app/other_api/doodad/controller.py index fcf63ef..56e865d 100644 --- a/app/other_api/doodad/controller.py +++ b/app/other_api/doodad/controller.py @@ -9,47 +9,48 @@ from .service import DoodadService from .model import Doodad from .interface import DoodadInterface -api = Namespace('Doodad', description='A modular namespace within Other API') # noqa +api = Namespace("Doodad", description="A modular namespace within Other API") # noqa -@api.route('/') +@api.route("/") class DoodadResource(Resource): - '''Doodads''' + """Doodads""" @responds(schema=DoodadSchema, many=True) def get(self) -> List[Doodad]: - '''Get all Doodads''' + """Get all Doodads""" return DoodadService.get_all() @accepts(schema=DoodadSchema, api=api) @responds(schema=DoodadSchema) def post(self) -> Doodad: - '''Create a Single Doodad''' + """Create a Single Doodad""" return DoodadService.create(request.parsed_obj) -@api.route('/') -@api.param('doodadId', 'Doodad database ID') +@api.route("/") +@api.param("doodadId", "Doodad database ID") class DoodadIdResource(Resource): @responds(schema=DoodadSchema) def get(self, doodadId: int) -> Doodad: - '''Get Single Doodad''' + """Get Single Doodad""" return DoodadService.get_by_id(doodadId) def delete(self, doodadId: int) -> Response: - '''Delete Single Doodad''' + """Delete Single Doodad""" from flask import jsonify - print('doodadId = ', doodadId) + + print("doodadId = ", doodadId) id = DoodadService.delete_by_id(doodadId) - return jsonify(dict(status='Success', id=id)) + return jsonify(dict(status="Success", id=id)) @accepts(schema=DoodadSchema, api=api) @responds(schema=DoodadSchema) def put(self, doodadId: int) -> Doodad: - '''Update Single Doodad''' + """Update Single Doodad""" changes: DoodadInterface = request.parsed_obj Doodad = DoodadService.get_by_id(doodadId) diff --git a/app/other_api/doodad/controller_test.py b/app/other_api/doodad/controller_test.py index af331b9..d814a9f 100644 --- a/app/other_api/doodad/controller_test.py +++ b/app/other_api/doodad/controller_test.py @@ -1,4 +1,3 @@ - from unittest.mock import patch from flask.testing import FlaskClient @@ -10,75 +9,89 @@ from .interface import DoodadInterface from .. import BASE_ROUTE -def make_doodad(id: int = 123, name: str = 'Test doodad', - purpose: str = 'Test purpose') -> Doodad: - return Doodad( - doodad_id=id, name=name, purpose=purpose - ) +def make_doodad( + id: int = 123, name: str = "Test doodad", purpose: str = "Test purpose" +) -> Doodad: + return Doodad(doodad_id=id, name=name, purpose=purpose) class TestDoodadResource: - @patch.object(DoodadService, 'get_all', - lambda: [make_doodad(123, name='Test Doodad 1'), - make_doodad(456, name='Test Doodad 2')]) + @patch.object( + DoodadService, + "get_all", + lambda: [ + make_doodad(123, name="Test Doodad 1"), + make_doodad(456, name="Test Doodad 2"), + ], + ) def test_get(self, client: FlaskClient): # noqa with client: - results = client.get(f'/api/{BASE_ROUTE}/doodad', - follow_redirects=True).get_json() - expected = DoodadSchema(many=True).dump( - [make_doodad(123, name='Test Doodad 1'), - make_doodad(456, name='Test Doodad 2')] - ).data + results = client.get( + f"/api/{BASE_ROUTE}/doodad", follow_redirects=True + ).get_json() + expected = ( + DoodadSchema(many=True) + .dump( + [ + make_doodad(123, name="Test Doodad 1"), + make_doodad(456, name="Test Doodad 2"), + ] + ) + .data + ) for r in results: assert r in expected - @patch.object(DoodadService, 'create', - lambda create_request: Doodad(**create_request)) + @patch.object( + DoodadService, "create", lambda create_request: Doodad(**create_request) + ) def test_post(self, client: FlaskClient): # noqa with client: - payload = dict(name='Test doodad', purpose='Test purpose') - result = client.post(f'/api/{BASE_ROUTE}/doodad/', json=payload).get_json() - expected = DoodadSchema().dump(Doodad( - name=payload['name'], - purpose=payload['purpose'], - )).data + payload = dict(name="Test doodad", purpose="Test purpose") + result = client.post(f"/api/{BASE_ROUTE}/doodad/", json=payload).get_json() + expected = ( + DoodadSchema() + .dump(Doodad(name=payload["name"], purpose=payload["purpose"])) + .data + ) assert result == expected def fake_update(doodad: Doodad, changes: DoodadInterface) -> Doodad: # To fake an update, just return a new object - updated_Doodad = Doodad(doodad_id=doodad.doodad_id, - name=changes['name'], - purpose=changes['purpose']) + updated_Doodad = Doodad( + doodad_id=doodad.doodad_id, name=changes["name"], purpose=changes["purpose"] + ) return updated_Doodad class TestDoodadIdResource: - @patch.object(DoodadService, 'get_by_id', - lambda id: make_doodad(id=id)) + @patch.object(DoodadService, "get_by_id", lambda id: make_doodad(id=id)) def test_get(self, client: FlaskClient): # noqa with client: - result = client.get(f'/api/{BASE_ROUTE}/doodad/123').get_json() + result = client.get(f"/api/{BASE_ROUTE}/doodad/123").get_json() expected = Doodad(doodad_id=123) - assert result['doodadId'] == expected.doodad_id + assert result["doodadId"] == expected.doodad_id - @patch.object(DoodadService, 'delete_by_id', - lambda id: [id]) + @patch.object(DoodadService, "delete_by_id", lambda id: [id]) def test_delete(self, client: FlaskClient): # noqa with client: - result = client.delete(f'/api/{BASE_ROUTE}/doodad/123').get_json() - expected = dict(status='Success', id=[123]) + result = client.delete(f"/api/{BASE_ROUTE}/doodad/123").get_json() + expected = dict(status="Success", id=[123]) assert result == expected - @patch.object(DoodadService, 'get_by_id', - lambda id: make_doodad(id=id)) - @patch.object(DoodadService, 'update', fake_update) + @patch.object(DoodadService, "get_by_id", lambda id: make_doodad(id=id)) + @patch.object(DoodadService, "update", fake_update) def test_put(self, client: FlaskClient): # noqa with client: - result = client.put(f'/api/{BASE_ROUTE}/doodad/123', - json={'name': 'New Doodad', - 'purpose': 'New purpose'}).get_json() - expected = DoodadSchema().dump( - Doodad(doodad_id=123, name='New Doodad', purpose='New purpose')).data + result = client.put( + f"/api/{BASE_ROUTE}/doodad/123", + json={"name": "New Doodad", "purpose": "New purpose"}, + ).get_json() + expected = ( + DoodadSchema() + .dump(Doodad(doodad_id=123, name="New Doodad", purpose="New purpose")) + .data + ) assert result == expected diff --git a/app/other_api/doodad/interface_test.py b/app/other_api/doodad/interface_test.py index 7920dbe..079db6b 100644 --- a/app/other_api/doodad/interface_test.py +++ b/app/other_api/doodad/interface_test.py @@ -5,9 +5,7 @@ from .interface import DoodadInterface @fixture def interface() -> DoodadInterface: - return DoodadInterface( - doodad_id=1, name='Test doodad', purpose='Test purpose' - ) + return DoodadInterface(doodad_id=1, name="Test doodad", purpose="Test purpose") def test_DoodadInterface_create(interface: DoodadInterface): diff --git a/app/other_api/doodad/model.py b/app/other_api/doodad/model.py index b1558cb..0d14eb8 100644 --- a/app/other_api/doodad/model.py +++ b/app/other_api/doodad/model.py @@ -5,9 +5,9 @@ from typing import Any class Doodad(db.Model): # type: ignore - '''A snazzy Doodad''' + """A snazzy Doodad""" - __tablename__ = 'doodad' + __tablename__ = "doodad" doodad_id = Column(Integer(), primary_key=True) name = Column(String(255)) diff --git a/app/other_api/doodad/model_test.py b/app/other_api/doodad/model_test.py index a2e410b..d203a2a 100644 --- a/app/other_api/doodad/model_test.py +++ b/app/other_api/doodad/model_test.py @@ -6,9 +6,7 @@ from .model import Doodad @fixture def doodad() -> Doodad: - return Doodad( - doodad_id=1, name='Test doodad', purpose='Test purpose' - ) + return Doodad(doodad_id=1, name="Test doodad", purpose="Test purpose") def test_Doodad_create(doodad: Doodad): diff --git a/app/other_api/doodad/schema.py b/app/other_api/doodad/schema.py index 20e895e..5034ca7 100644 --- a/app/other_api/doodad/schema.py +++ b/app/other_api/doodad/schema.py @@ -2,8 +2,8 @@ from marshmallow import fields, Schema class DoodadSchema(Schema): - '''Doodad schema''' + """Doodad schema""" - doodadId = fields.Number(attribute='doodad_id') - name = fields.String(attribute='name') - purpose = fields.String(attribute='purpose') + doodadId = fields.Number(attribute="doodad_id") + name = fields.String(attribute="name") + purpose = fields.String(attribute="purpose") diff --git a/app/other_api/doodad/schema_test.py b/app/other_api/doodad/schema_test.py index 548cad4..02137bc 100644 --- a/app/other_api/doodad/schema_test.py +++ b/app/other_api/doodad/schema_test.py @@ -15,13 +15,11 @@ def test_DoodadSchema_create(schema: DoodadSchema): def test_DoodadSchema_works(schema: DoodadSchema): - params: DoodadInterface = schema.load({ - 'doodadId': '123', - 'name': 'Test doodad', - 'purpose': 'Test purpose' - }).data + params: DoodadInterface = schema.load( + {"doodadId": "123", "name": "Test doodad", "purpose": "Test purpose"} + ).data doodad = Doodad(**params) assert doodad.doodad_id == 123 - assert doodad.name == 'Test doodad' - assert doodad.purpose == 'Test purpose' + assert doodad.name == "Test doodad" + assert doodad.purpose == "Test purpose" diff --git a/app/other_api/doodad/service.py b/app/other_api/doodad/service.py index 41e12cc..9e42f3a 100644 --- a/app/other_api/doodad/service.py +++ b/app/other_api/doodad/service.py @@ -4,7 +4,7 @@ from .model import Doodad from .interface import DoodadInterface -class DoodadService(): +class DoodadService: @staticmethod def get_all() -> List[Doodad]: return Doodad.query.all() @@ -30,10 +30,7 @@ class DoodadService(): @staticmethod def create(new_attrs: DoodadInterface) -> Doodad: - new_doodad = Doodad( - name=new_attrs['name'], - purpose=new_attrs['purpose'] - ) + new_doodad = Doodad(name=new_attrs["name"], purpose=new_attrs["purpose"]) db.session.add(new_doodad) db.session.commit() diff --git a/app/other_api/doodad/service_test.py b/app/other_api/doodad/service_test.py index 8a1e277..921ca99 100644 --- a/app/other_api/doodad/service_test.py +++ b/app/other_api/doodad/service_test.py @@ -7,8 +7,8 @@ from .interface import DoodadInterface def test_get_all(db: SQLAlchemy): # noqa - yin: Doodad = Doodad(doodad_id=1, name='Yin', purpose='thing 1') - yang: Doodad = Doodad(doodad_id=2, name='Yang', purpose='thing 2') + yin: Doodad = Doodad(doodad_id=1, name="Yin", purpose="thing 1") + yang: Doodad = Doodad(doodad_id=2, name="Yang", purpose="thing 2") db.session.add(yin) db.session.add(yang) db.session.commit() @@ -20,21 +20,21 @@ def test_get_all(db: SQLAlchemy): # noqa def test_update(db: SQLAlchemy): # noqa - yin: Doodad = Doodad(doodad_id=1, name='Yin', purpose='thing 1') + yin: Doodad = Doodad(doodad_id=1, name="Yin", purpose="thing 1") db.session.add(yin) db.session.commit() - updates: DoodadInterface = dict(name='New Doodad name') + updates: DoodadInterface = dict(name="New Doodad name") DoodadService.update(yin, updates) result: Doodad = Doodad.query.get(yin.doodad_id) - assert result.name == 'New Doodad name' + assert result.name == "New Doodad name" def test_delete_by_id(db: SQLAlchemy): # noqa - yin: Doodad = Doodad(doodad_id=1, name='Yin', purpose='thing 1') - yang: Doodad = Doodad(doodad_id=2, name='Yang', purpose='thing 2') + yin: Doodad = Doodad(doodad_id=1, name="Yin", purpose="thing 1") + yang: Doodad = Doodad(doodad_id=2, name="Yang", purpose="thing 2") db.session.add(yin) db.session.add(yang) db.session.commit() @@ -50,7 +50,7 @@ def test_delete_by_id(db: SQLAlchemy): # noqa def test_create(db: SQLAlchemy): # noqa - yin: DoodadInterface = dict(name='Fancy new doodad', purpose='Fancy new purpose') + yin: DoodadInterface = dict(name="Fancy new doodad", purpose="Fancy new purpose") DoodadService.create(yin) results: List[Doodad] = Doodad.query.all() diff --git a/app/other_api/whatsit/controller_test.py b/app/other_api/whatsit/controller_test.py index 0c030cc..c43b6ad 100644 --- a/app/other_api/whatsit/controller_test.py +++ b/app/other_api/whatsit/controller_test.py @@ -1,4 +1,3 @@ - from unittest.mock import patch from flask.testing import FlaskClient @@ -10,75 +9,91 @@ from .interface import WhatsitInterface from .. import BASE_ROUTE -def make_whatsit(id: int = 123, name: str = 'Test whatsit', - purpose: str = 'Test purpose') -> Whatsit: - return Whatsit( - whatsit_id=id, name=name, purpose=purpose - ) +def make_whatsit( + id: int = 123, name: str = "Test whatsit", purpose: str = "Test purpose" +) -> Whatsit: + return Whatsit(whatsit_id=id, name=name, purpose=purpose) class TestWhatsitResource: - @patch.object(WhatsitService, 'get_all', - lambda: [make_whatsit(123, name='Test Whatsit 1'), - make_whatsit(456, name='Test Whatsit 2')]) + @patch.object( + WhatsitService, + "get_all", + lambda: [ + make_whatsit(123, name="Test Whatsit 1"), + make_whatsit(456, name="Test Whatsit 2"), + ], + ) def test_get(self, client: FlaskClient): # noqa with client: - results = client.get(f'/api/{BASE_ROUTE}/whatsit', - follow_redirects=True).get_json() - expected = WhatsitSchema(many=True).dump( - [make_whatsit(123, name='Test Whatsit 1'), - make_whatsit(456, name='Test Whatsit 2')] - ).data + results = client.get( + f"/api/{BASE_ROUTE}/whatsit", follow_redirects=True + ).get_json() + expected = ( + WhatsitSchema(many=True) + .dump( + [ + make_whatsit(123, name="Test Whatsit 1"), + make_whatsit(456, name="Test Whatsit 2"), + ] + ) + .data + ) for r in results: assert r in expected - @patch.object(WhatsitService, 'create', - lambda create_request: Whatsit(**create_request)) + @patch.object( + WhatsitService, "create", lambda create_request: Whatsit(**create_request) + ) def test_post(self, client: FlaskClient): # noqa with client: - payload = dict(name='Test whatsit', purpose='Test purpose') - result = client.post(f'/api/{BASE_ROUTE}/whatsit/', json=payload).get_json() - expected = WhatsitSchema().dump(Whatsit( - name=payload['name'], - purpose=payload['purpose'], - )).data + payload = dict(name="Test whatsit", purpose="Test purpose") + result = client.post(f"/api/{BASE_ROUTE}/whatsit/", json=payload).get_json() + expected = ( + WhatsitSchema() + .dump(Whatsit(name=payload["name"], purpose=payload["purpose"])) + .data + ) assert result == expected def fake_update(whatsit: Whatsit, changes: WhatsitInterface) -> Whatsit: # To fake an update, just return a new object - updated_Whatsit = Whatsit(whatsit_id=whatsit.whatsit_id, - name=changes['name'], - purpose=changes['purpose']) + updated_Whatsit = Whatsit( + whatsit_id=whatsit.whatsit_id, name=changes["name"], purpose=changes["purpose"] + ) return updated_Whatsit class TestWhatsitIdResource: - @patch.object(WhatsitService, 'get_by_id', - lambda id: make_whatsit(id=id)) + @patch.object(WhatsitService, "get_by_id", lambda id: make_whatsit(id=id)) def test_get(self, client: FlaskClient): # noqa with client: - result = client.get(f'/api/{BASE_ROUTE}/whatsit/123').get_json() + result = client.get(f"/api/{BASE_ROUTE}/whatsit/123").get_json() expected = Whatsit(whatsit_id=123) - assert result['whatsitId'] == expected.whatsit_id + assert result["whatsitId"] == expected.whatsit_id - @patch.object(WhatsitService, 'delete_by_id', - lambda id: [id]) + @patch.object(WhatsitService, "delete_by_id", lambda id: [id]) def test_delete(self, client: FlaskClient): # noqa with client: - result = client.delete(f'/api/{BASE_ROUTE}/whatsit/123').get_json() - expected = dict(status='Success', id=[123]) + result = client.delete(f"/api/{BASE_ROUTE}/whatsit/123").get_json() + expected = dict(status="Success", id=[123]) assert result == expected - @patch.object(WhatsitService, 'get_by_id', - lambda id: make_whatsit(id=id)) - @patch.object(WhatsitService, 'update', fake_update) + @patch.object(WhatsitService, "get_by_id", lambda id: make_whatsit(id=id)) + @patch.object(WhatsitService, "update", fake_update) def test_put(self, client: FlaskClient): # noqa with client: - result = client.put(f'/api/{BASE_ROUTE}/whatsit/123', - json={'name': 'New Whatsit', - 'purpose': 'New purpose'}).get_json() - expected = WhatsitSchema().dump( - Whatsit(whatsit_id=123, name='New Whatsit', purpose='New purpose')).data + result = client.put( + f"/api/{BASE_ROUTE}/whatsit/123", + json={"name": "New Whatsit", "purpose": "New purpose"}, + ).get_json() + expected = ( + WhatsitSchema() + .dump( + Whatsit(whatsit_id=123, name="New Whatsit", purpose="New purpose") + ) + .data + ) assert result == expected diff --git a/app/other_api/whatsit/interface_test.py b/app/other_api/whatsit/interface_test.py index b2e3ece..46baa40 100644 --- a/app/other_api/whatsit/interface_test.py +++ b/app/other_api/whatsit/interface_test.py @@ -5,9 +5,7 @@ from .interface import WhatsitInterface @fixture def interface() -> WhatsitInterface: - return WhatsitInterface( - whatsit_id=1, name='Test whatsit', purpose='Test purpose' - ) + return WhatsitInterface(whatsit_id=1, name="Test whatsit", purpose="Test purpose") def test_WhatsitInterface_create(interface: WhatsitInterface): diff --git a/app/other_api/whatsit/model.py b/app/other_api/whatsit/model.py index 439e514..a69ce94 100644 --- a/app/other_api/whatsit/model.py +++ b/app/other_api/whatsit/model.py @@ -5,9 +5,9 @@ from typing import Any class Whatsit(db.Model): # type: ignore - '''A snazzy Whatsit''' + """A snazzy Whatsit""" - __tablename__ = 'whatsit' + __tablename__ = "whatsit" whatsit_id = Column(Integer(), primary_key=True) name = Column(String(255)) diff --git a/app/other_api/whatsit/model_test.py b/app/other_api/whatsit/model_test.py index 2551ccc..f942b8c 100644 --- a/app/other_api/whatsit/model_test.py +++ b/app/other_api/whatsit/model_test.py @@ -6,9 +6,7 @@ from .model import Whatsit @fixture def whatsit() -> Whatsit: - return Whatsit( - whatsit_id=1, name='Test whatsit', purpose='Test purpose' - ) + return Whatsit(whatsit_id=1, name="Test whatsit", purpose="Test purpose") def test_Whatsit_create(whatsit: Whatsit): diff --git a/app/other_api/whatsit/schema.py b/app/other_api/whatsit/schema.py index c637bed..d3b307c 100644 --- a/app/other_api/whatsit/schema.py +++ b/app/other_api/whatsit/schema.py @@ -2,8 +2,8 @@ from marshmallow import fields, Schema class WhatsitSchema(Schema): - '''Whatsit schema''' + """Whatsit schema""" - whatsitId = fields.Number(attribute='whatsit_id') - name = fields.String(attribute='name') - purpose = fields.String(attribute='purpose') + whatsitId = fields.Number(attribute="whatsit_id") + name = fields.String(attribute="name") + purpose = fields.String(attribute="purpose") diff --git a/app/other_api/whatsit/schema_test.py b/app/other_api/whatsit/schema_test.py index 6927c23..0e1eca9 100644 --- a/app/other_api/whatsit/schema_test.py +++ b/app/other_api/whatsit/schema_test.py @@ -15,13 +15,11 @@ def test_WhatsitSchema_create(schema: WhatsitSchema): def test_WhatsitSchema_works(schema: WhatsitSchema): - params: WhatsitInterface = schema.load({ - 'whatsitId': '123', - 'name': 'Test whatsit', - 'purpose': 'Test purpose' - }).data + params: WhatsitInterface = schema.load( + {"whatsitId": "123", "name": "Test whatsit", "purpose": "Test purpose"} + ).data whatsit = Whatsit(**params) assert whatsit.whatsit_id == 123 - assert whatsit.name == 'Test whatsit' - assert whatsit.purpose == 'Test purpose' + assert whatsit.name == "Test whatsit" + assert whatsit.purpose == "Test purpose" diff --git a/app/other_api/whatsit/service.py b/app/other_api/whatsit/service.py index 9a0dfc3..231185f 100644 --- a/app/other_api/whatsit/service.py +++ b/app/other_api/whatsit/service.py @@ -4,7 +4,7 @@ from .model import Whatsit from .interface import WhatsitInterface -class WhatsitService(): +class WhatsitService: @staticmethod def get_all() -> List[Whatsit]: return Whatsit.query.all() @@ -30,10 +30,7 @@ class WhatsitService(): @staticmethod def create(new_attrs: WhatsitInterface) -> Whatsit: - new_whatsit = Whatsit( - name=new_attrs['name'], - purpose=new_attrs['purpose'] - ) + new_whatsit = Whatsit(name=new_attrs["name"], purpose=new_attrs["purpose"]) db.session.add(new_whatsit) db.session.commit() diff --git a/app/other_api/whatsit/service_test.py b/app/other_api/whatsit/service_test.py index f521f3d..f389d47 100644 --- a/app/other_api/whatsit/service_test.py +++ b/app/other_api/whatsit/service_test.py @@ -7,8 +7,8 @@ from .interface import WhatsitInterface def test_get_all(db: SQLAlchemy): # noqa - yin: Whatsit = Whatsit(whatsit_id=1, name='Yin', purpose='thing 1') - yang: Whatsit = Whatsit(whatsit_id=2, name='Yang', purpose='thing 2') + yin: Whatsit = Whatsit(whatsit_id=1, name="Yin", purpose="thing 1") + yang: Whatsit = Whatsit(whatsit_id=2, name="Yang", purpose="thing 2") db.session.add(yin) db.session.add(yang) db.session.commit() @@ -20,21 +20,21 @@ def test_get_all(db: SQLAlchemy): # noqa def test_update(db: SQLAlchemy): # noqa - yin: Whatsit = Whatsit(whatsit_id=1, name='Yin', purpose='thing 1') + yin: Whatsit = Whatsit(whatsit_id=1, name="Yin", purpose="thing 1") db.session.add(yin) db.session.commit() - updates: WhatsitInterface = dict(name='New Whatsit name') + updates: WhatsitInterface = dict(name="New Whatsit name") WhatsitService.update(yin, updates) result: Whatsit = Whatsit.query.get(yin.whatsit_id) - assert result.name == 'New Whatsit name' + assert result.name == "New Whatsit name" def test_delete_by_id(db: SQLAlchemy): # noqa - yin: Whatsit = Whatsit(whatsit_id=1, name='Yin', purpose='thing 1') - yang: Whatsit = Whatsit(whatsit_id=2, name='Yang', purpose='thing 2') + yin: Whatsit = Whatsit(whatsit_id=1, name="Yin", purpose="thing 1") + yang: Whatsit = Whatsit(whatsit_id=2, name="Yang", purpose="thing 2") db.session.add(yin) db.session.add(yang) db.session.commit() @@ -50,7 +50,7 @@ def test_delete_by_id(db: SQLAlchemy): # noqa def test_create(db: SQLAlchemy): # noqa - yin: WhatsitInterface = dict(name='Fancy new whatsit', purpose='Fancy new purpose') + yin: WhatsitInterface = dict(name="Fancy new whatsit", purpose="Fancy new purpose") WhatsitService.create(yin) results: List[Whatsit] = Whatsit.query.all() diff --git a/app/routes.py b/app/routes.py index 7252ac1..2c8afcb 100644 --- a/app/routes.py +++ b/app/routes.py @@ -1,4 +1,4 @@ -def register_routes(api, app, root='api'): +def register_routes(api, app, root="api"): from app.widget import register_routes as attach_widget from app.fizz import register_routes as attach_fizz from app.other_api import register_routes as attach_other_api @@ -8,4 +8,4 @@ def register_routes(api, app, root='api'): attach_widget(api, app) attach_fizz(api, app) attach_other_api(api, app) - app.register_blueprint(create_bp(), url_prefix='/third_party') + app.register_blueprint(create_bp(), url_prefix="/third_party") diff --git a/app/shared/query/service.py b/app/shared/query/service.py index d1e8645..454b257 100644 --- a/app/shared/query/service.py +++ b/app/shared/query/service.py @@ -1,6 +1,6 @@ class QueryService: - '''An example of a service that is shared''' + """An example of a service that is shared""" @staticmethod def execute(query): - return 'Success' + return "Success" diff --git a/app/shared/query/service_test.py b/app/shared/query/service_test.py index dc3c0ac..adec25d 100644 --- a/app/shared/query/service_test.py +++ b/app/shared/query/service_test.py @@ -2,6 +2,6 @@ from .service import QueryService def test_execute(): - result = QueryService.execute('a complicated query') + result = QueryService.execute("a complicated query") - assert result == 'Success' + assert result == "Success" diff --git a/app/test/fixtures.py b/app/test/fixtures.py index c6db006..d83bee5 100644 --- a/app/test/fixtures.py +++ b/app/test/fixtures.py @@ -5,7 +5,7 @@ from app import create_app @pytest.fixture def app(): - return create_app('test') + return create_app("test") @pytest.fixture @@ -16,6 +16,7 @@ def client(app): @pytest.fixture def db(app): from app import db + with app.app_context(): db.create_all() yield db diff --git a/app/third_party/app/__init__.py b/app/third_party/app/__init__.py index 37ebdc2..84a41ec 100644 --- a/app/third_party/app/__init__.py +++ b/app/third_party/app/__init__.py @@ -3,12 +3,14 @@ def create_bp(env=None): from flask_sqlalchemy import SQLAlchemy from flask_restplus import Api, Resource, Namespace - bp = Blueprint('Example third party API', __name__) - api = Api(bp, title='Flaskerific API', version='0.1.0') - ns = Namespace('Third party hello world API') - @ns.route('/') + bp = Blueprint("Example third party API", __name__) + api = Api(bp, title="Flaskerific API", version="0.1.0") + ns = Namespace("Third party hello world API") + + @ns.route("/") class ExampleResource(Resource): def get(self): return "I'm a third party API!" - api.add_namespace(ns, path='/hello_world') + + api.add_namespace(ns, path="/hello_world") return bp diff --git a/app/third_party/app/config.py b/app/third_party/app/config.py index 3217831..b4bb7a9 100644 --- a/app/third_party/app/config.py +++ b/app/third_party/app/config.py @@ -5,16 +5,17 @@ basedir = os.path.abspath(os.path.dirname(__file__)) class BaseConfig: - CONFIG_NAME = 'base' + CONFIG_NAME = "base" USE_MOCK_EQUIVALENCY = False DEBUG = False SQLALCHEMY_TRACK_MODIFICATIONS = False class DevelopmentConfig(BaseConfig): - CONFIG_NAME = 'dev' + CONFIG_NAME = "dev" SECRET_KEY = os.getenv( - "DEV_SECRET_KEY", "You can't see California without Marlon Widgeto's eyes") + "DEV_SECRET_KEY", "You can't see California without Marlon Widgeto's eyes" + ) DEBUG = True SQLALCHEMY_TRACK_MODIFICATIONS = False TESTING = False @@ -22,7 +23,7 @@ class DevelopmentConfig(BaseConfig): class TestingConfig(BaseConfig): - CONFIG_NAME = 'test' + CONFIG_NAME = "test" SECRET_KEY = os.getenv("TEST_SECRET_KEY", "Thanos did nothing wrong") DEBUG = True SQLALCHEMY_TRACK_MODIFICATIONS = False @@ -31,7 +32,7 @@ class TestingConfig(BaseConfig): class ProductionConfig(BaseConfig): - CONFIG_NAME = 'prod' + CONFIG_NAME = "prod" SECRET_KEY = os.getenv("PROD_SECRET_KEY", "I'm Ron Burgundy?") DEBUG = False SQLALCHEMY_TRACK_MODIFICATIONS = False @@ -40,5 +41,8 @@ class ProductionConfig(BaseConfig): EXPORT_CONFIGS: List[Type[BaseConfig]] = [ - DevelopmentConfig, TestingConfig, ProductionConfig] + DevelopmentConfig, + TestingConfig, + ProductionConfig, +] config_by_name = {cfg.CONFIG_NAME: cfg for cfg in EXPORT_CONFIGS} diff --git a/app/third_party/app/routes.py b/app/third_party/app/routes.py index ec82aac..57f3ceb 100644 --- a/app/third_party/app/routes.py +++ b/app/third_party/app/routes.py @@ -1,4 +1,4 @@ -def register_routes(api, app, root='api'): +def register_routes(api, app, root="api"): from app.widget import register_routes as attach_widget from app.fizz import register_routes as attach_fizz from app.other_api import register_routes as attach_other_api diff --git a/app/widget/__init__.py b/app/widget/__init__.py index ae0b1fa..a1fa546 100644 --- a/app/widget/__init__.py +++ b/app/widget/__init__.py @@ -1,9 +1,10 @@ from .model import Widget # noqa from .schema import WidgetSchema # noqa -BASE_ROUTE = 'widget' + +BASE_ROUTE = "widget" -def register_routes(api, app, root='api'): +def register_routes(api, app, root="api"): from .controller import api as widget_api - api.add_namespace(widget_api, path=f'/{root}/{BASE_ROUTE}') + api.add_namespace(widget_api, path=f"/{root}/{BASE_ROUTE}") diff --git a/app/widget/controller.py b/app/widget/controller.py index 9485ff7..364f0ee 100644 --- a/app/widget/controller.py +++ b/app/widget/controller.py @@ -9,47 +9,47 @@ from .service import WidgetService from .model import Widget from .interface import WidgetInterface -api = Namespace('Widget', description='Single namespace, single entity') # noqa +api = Namespace("Widget", description="Single namespace, single entity") # noqa -@api.route('/') +@api.route("/") class WidgetResource(Resource): - '''Widgets''' + """Widgets""" @responds(schema=WidgetSchema, many=True) def get(self) -> List[Widget]: - '''Get all Widgets''' + """Get all Widgets""" return WidgetService.get_all() @accepts(schema=WidgetSchema, api=api) @responds(schema=WidgetSchema) def post(self) -> Widget: - '''Create a Single Widget''' + """Create a Single Widget""" return WidgetService.create(request.parsed_obj) -@api.route('/') -@api.param('widgetId', 'Widget database ID') +@api.route("/") +@api.param("widgetId", "Widget database ID") class WidgetIdResource(Resource): @responds(schema=WidgetSchema) def get(self, widgetId: int) -> Widget: - '''Get Single Widget''' + """Get Single Widget""" return WidgetService.get_by_id(widgetId) def delete(self, widgetId: int) -> Response: - '''Delete Single Widget''' + """Delete Single Widget""" from flask import jsonify id = WidgetService.delete_by_id(widgetId) - return jsonify(dict(status='Success', id=id)) + return jsonify(dict(status="Success", id=id)) @accepts(schema=WidgetSchema, api=api) @responds(schema=WidgetSchema) def put(self, widgetId: int) -> Widget: - '''Update Single Widget''' + """Update Single Widget""" changes: WidgetInterface = request.parsed_obj Widget = WidgetService.get_by_id(widgetId) diff --git a/app/widget/controller_test.py b/app/widget/controller_test.py index cf5506e..cb62505 100644 --- a/app/widget/controller_test.py +++ b/app/widget/controller_test.py @@ -1,4 +1,3 @@ - from unittest.mock import patch from flask.testing import FlaskClient @@ -10,76 +9,88 @@ from .interface import WidgetInterface from . import BASE_ROUTE -def make_widget(id: int = 123, name: str = 'Test widget', - purpose: str = 'Test purpose') -> Widget: - return Widget( - widget_id=id, name=name, purpose=purpose - ) +def make_widget( + id: int = 123, name: str = "Test widget", purpose: str = "Test purpose" +) -> Widget: + return Widget(widget_id=id, name=name, purpose=purpose) class TestWidgetResource: - @patch.object(WidgetService, 'get_all', - lambda: [make_widget(123, name='Test Widget 1'), - make_widget(456, name='Test Widget 2')]) + @patch.object( + WidgetService, + "get_all", + lambda: [ + make_widget(123, name="Test Widget 1"), + make_widget(456, name="Test Widget 2"), + ], + ) def test_get(self, client: FlaskClient): # noqa with client: - results = client.get(f'/api/{BASE_ROUTE}', - follow_redirects=True).get_json() - expected = WidgetSchema(many=True).dump( - [make_widget(123, name='Test Widget 1'), - make_widget(456, name='Test Widget 2')] - ).data + results = client.get(f"/api/{BASE_ROUTE}", follow_redirects=True).get_json() + expected = ( + WidgetSchema(many=True) + .dump( + [ + make_widget(123, name="Test Widget 1"), + make_widget(456, name="Test Widget 2"), + ] + ) + .data + ) for r in results: assert r in expected - @patch.object(WidgetService, 'create', - lambda create_request: Widget(**create_request)) + @patch.object( + WidgetService, "create", lambda create_request: Widget(**create_request) + ) def test_post(self, client: FlaskClient): # noqa with client: - payload = dict(name='Test widget', purpose='Test purpose') - result = client.post(f'/api/{BASE_ROUTE}/', json=payload).get_json() - expected = WidgetSchema().dump(Widget( - name=payload['name'], - purpose=payload['purpose'], - )).data + payload = dict(name="Test widget", purpose="Test purpose") + result = client.post(f"/api/{BASE_ROUTE}/", json=payload).get_json() + expected = ( + WidgetSchema() + .dump(Widget(name=payload["name"], purpose=payload["purpose"])) + .data + ) assert result == expected def fake_update(widget: Widget, changes: WidgetInterface) -> Widget: # To fake an update, just return a new object - updated_Widget = Widget(widget_id=widget.widget_id, - name=changes['name'], - purpose=changes['purpose']) + updated_Widget = Widget( + widget_id=widget.widget_id, name=changes["name"], purpose=changes["purpose"] + ) return updated_Widget class TestWidgetIdResource: - @patch.object(WidgetService, 'get_by_id', - lambda id: make_widget(id=id)) + @patch.object(WidgetService, "get_by_id", lambda id: make_widget(id=id)) def test_get(self, client: FlaskClient): # noqa with client: - result = client.get(f'/api/{BASE_ROUTE}/123').get_json() + result = client.get(f"/api/{BASE_ROUTE}/123").get_json() expected = make_widget(id=123) - print(f'result = ', result) - assert result['widgetId'] == expected.widget_id + print(f"result = ", result) + assert result["widgetId"] == expected.widget_id - @patch.object(WidgetService, 'delete_by_id', - lambda id: id) + @patch.object(WidgetService, "delete_by_id", lambda id: id) def test_delete(self, client: FlaskClient): # noqa with client: - result = client.delete(f'/api/{BASE_ROUTE}/123').get_json() - expected = dict(status='Success', id=123) + result = client.delete(f"/api/{BASE_ROUTE}/123").get_json() + expected = dict(status="Success", id=123) assert result == expected - @patch.object(WidgetService, 'get_by_id', - lambda id: make_widget(id=id)) - @patch.object(WidgetService, 'update', fake_update) + @patch.object(WidgetService, "get_by_id", lambda id: make_widget(id=id)) + @patch.object(WidgetService, "update", fake_update) def test_put(self, client: FlaskClient): # noqa with client: - result = client.put(f'/api/{BASE_ROUTE}/123', - json={'name': 'New Widget', - 'purpose': 'New purpose'}).get_json() - expected = WidgetSchema().dump( - Widget(widget_id=123, name='New Widget', purpose='New purpose')).data + result = client.put( + f"/api/{BASE_ROUTE}/123", + json={"name": "New Widget", "purpose": "New purpose"}, + ).get_json() + expected = ( + WidgetSchema() + .dump(Widget(widget_id=123, name="New Widget", purpose="New purpose")) + .data + ) assert result == expected diff --git a/app/widget/interface_test.py b/app/widget/interface_test.py index da75bc8..3f11414 100644 --- a/app/widget/interface_test.py +++ b/app/widget/interface_test.py @@ -5,9 +5,7 @@ from .interface import WidgetInterface @fixture def interface() -> WidgetInterface: - return WidgetInterface( - widget_id=1, name='Test widget', purpose='Test purpose' - ) + return WidgetInterface(widget_id=1, name="Test widget", purpose="Test purpose") def test_WidgetInterface_create(interface: WidgetInterface): diff --git a/app/widget/model.py b/app/widget/model.py index 5707376..e11d3b5 100644 --- a/app/widget/model.py +++ b/app/widget/model.py @@ -4,9 +4,9 @@ from .interface import WidgetInterface class Widget(db.Model): # type: ignore - '''A snazzy Widget''' + """A snazzy Widget""" - __tablename__ = 'widget' + __tablename__ = "widget" widget_id = Column(Integer(), primary_key=True) name = Column(String(255)) diff --git a/app/widget/model_test.py b/app/widget/model_test.py index 5069d16..601bbd8 100644 --- a/app/widget/model_test.py +++ b/app/widget/model_test.py @@ -6,9 +6,7 @@ from .model import Widget @fixture def widget() -> Widget: - return Widget( - widget_id=1, name='Test widget', purpose='Test purpose' - ) + return Widget(widget_id=1, name="Test widget", purpose="Test purpose") def test_Widget_create(widget: Widget): diff --git a/app/widget/schema.py b/app/widget/schema.py index f576bd9..826bc80 100644 --- a/app/widget/schema.py +++ b/app/widget/schema.py @@ -2,8 +2,8 @@ from marshmallow import fields, Schema class WidgetSchema(Schema): - '''Widget schema''' + """Widget schema""" - widgetId = fields.Number(attribute='widget_id') - name = fields.String(attribute='name') - purpose = fields.String(attribute='purpose') + widgetId = fields.Number(attribute="widget_id") + name = fields.String(attribute="name") + purpose = fields.String(attribute="purpose") diff --git a/app/widget/schema_test.py b/app/widget/schema_test.py index 9f4f702..c349dca 100644 --- a/app/widget/schema_test.py +++ b/app/widget/schema_test.py @@ -15,13 +15,11 @@ def test_WidgetSchema_create(schema: WidgetSchema): def test_WidgetSchema_works(schema: WidgetSchema): - params: WidgetInterface = schema.load({ - 'widgetId': '123', - 'name': 'Test widget', - 'purpose': 'Test purpose' - }).data + params: WidgetInterface = schema.load( + {"widgetId": "123", "name": "Test widget", "purpose": "Test purpose"} + ).data widget = Widget(**params) assert widget.widget_id == 123 - assert widget.name == 'Test widget' - assert widget.purpose == 'Test purpose' + assert widget.name == "Test widget" + assert widget.purpose == "Test purpose" diff --git a/app/widget/service.py b/app/widget/service.py index ef50003..5c96849 100644 --- a/app/widget/service.py +++ b/app/widget/service.py @@ -4,7 +4,7 @@ from .model import Widget from .interface import WidgetInterface -class WidgetService(): +class WidgetService: @staticmethod def get_all() -> List[Widget]: return Widget.query.all() @@ -30,10 +30,7 @@ class WidgetService(): @staticmethod def create(new_attrs: WidgetInterface) -> Widget: - new_widget = Widget( - name=new_attrs['name'], - purpose=new_attrs['purpose'] - ) + new_widget = Widget(name=new_attrs["name"], purpose=new_attrs["purpose"]) db.session.add(new_widget) db.session.commit() diff --git a/app/widget/service_test.py b/app/widget/service_test.py index 1c180e2..13dc817 100644 --- a/app/widget/service_test.py +++ b/app/widget/service_test.py @@ -7,8 +7,8 @@ from .interface import WidgetInterface def test_get_all(db: SQLAlchemy): # noqa - yin: Widget = Widget(widget_id=1, name='Yin', purpose='thing 1') - yang: Widget = Widget(widget_id=2, name='Yang', purpose='thing 2') + yin: Widget = Widget(widget_id=1, name="Yin", purpose="thing 1") + yang: Widget = Widget(widget_id=2, name="Yang", purpose="thing 2") db.session.add(yin) db.session.add(yang) db.session.commit() @@ -20,21 +20,21 @@ def test_get_all(db: SQLAlchemy): # noqa def test_update(db: SQLAlchemy): # noqa - yin: Widget = Widget(widget_id=1, name='Yin', purpose='thing 1') + yin: Widget = Widget(widget_id=1, name="Yin", purpose="thing 1") db.session.add(yin) db.session.commit() - updates: WidgetInterface = dict(name='New Widget name') + updates: WidgetInterface = dict(name="New Widget name") WidgetService.update(yin, updates) result: Widget = Widget.query.get(yin.widget_id) - assert result.name == 'New Widget name' + assert result.name == "New Widget name" def test_delete_by_id(db: SQLAlchemy): # noqa - yin: Widget = Widget(widget_id=1, name='Yin', purpose='thing 1') - yang: Widget = Widget(widget_id=2, name='Yang', purpose='thing 2') + yin: Widget = Widget(widget_id=1, name="Yin", purpose="thing 1") + yang: Widget = Widget(widget_id=2, name="Yang", purpose="thing 2") db.session.add(yin) db.session.add(yang) db.session.commit() @@ -50,7 +50,7 @@ def test_delete_by_id(db: SQLAlchemy): # noqa def test_create(db: SQLAlchemy): # noqa - yin: WidgetInterface = dict(name='Fancy new widget', purpose='Fancy new purpose') + yin: WidgetInterface = dict(name="Fancy new widget", purpose="Fancy new purpose") WidgetService.create(yin) results: List[Widget] = Widget.query.all() diff --git a/commands/__init__.py b/commands/__init__.py index 7f4d264..bc608ab 100644 --- a/commands/__init__.py +++ b/commands/__init__.py @@ -1,3 +1 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- from .seed_command import SeedCommand diff --git a/commands/seed_command.py b/commands/seed_command.py index 037081f..2fdb433 100644 --- a/commands/seed_command.py +++ b/commands/seed_command.py @@ -19,30 +19,26 @@ def seed_things(): def seed_thing(cls): things = [ - { - 'name': 'Pizza Slicer', - 'purpose': 'Cut delicious pizza', - }, - { - 'name': 'Rolling Pin', - 'purpose': 'Roll delicious pizza', - }, - { - 'name': 'Pizza Oven', - 'purpose': 'Bake delicious pizza', - }, + {"name": "Pizza Slicer", "purpose": "Cut delicious pizza"}, + {"name": "Rolling Pin", "purpose": "Roll delicious pizza"}, + {"name": "Pizza Oven", "purpose": "Bake delicious pizza"}, ] db.session.bulk_insert_mappings(cls, things) + class SeedCommand(Command): """ Seed the DB.""" def run(self): - if input('Are you sure you want to drop all tables and recreate? (y/N)\n' - ).lower() == 'y': - print('Dropping tables...') + if ( + input( + "Are you sure you want to drop all tables and recreate? (y/N)\n" + ).lower() + == "y" + ): + print("Dropping tables...") db.drop_all() db.create_all() seed_things() db.session.commit() - print('DB successfully seeded.') + print("DB successfully seeded.") diff --git a/manage.py b/manage.py index 6812b64..e3cb6d1 100644 --- a/manage.py +++ b/manage.py @@ -4,13 +4,13 @@ from flask_script import Manager from app import create_app, db from commands.seed_command import SeedCommand -env = os.getenv('FLASK_ENV') or 'test' -print(f'Active environment: * {env} *') +env = os.getenv("FLASK_ENV") or "test" +print(f"Active environment: * {env} *") app = create_app(env) manager = Manager(app) app.app_context().push() -manager.add_command('seed_db', SeedCommand) +manager.add_command("seed_db", SeedCommand) @manager.command @@ -20,16 +20,16 @@ def run(): @manager.command def init_db(): - print('Creating all resources.') + print("Creating all resources.") db.create_all() @manager.command def drop_all(): - if input('Are you sure you want to drop all tables? (y/N)\n').lower() == 'y': - print('Dropping tables...') + if input("Are you sure you want to drop all tables? (y/N)\n").lower() == "y": + print("Dropping tables...") db.drop_all() -if __name__ == '__main__': +if __name__ == "__main__": manager.run() diff --git a/wsgi.py b/wsgi.py index 11fa653..63fc433 100644 --- a/wsgi.py +++ b/wsgi.py @@ -2,6 +2,6 @@ import os from app import create_app -app = create_app(os.getenv('FLASK_ENV') or 'test') -if __name__ == '__main__': +app = create_app(os.getenv("FLASK_ENV") or "test") +if __name__ == "__main__": app.run(debug=True)