API refactor and front-end tests#95
Merged
Merged
Conversation
Add a committable, anonymized test dataset (real coverage/fiber geometry affine-transformed onto a synthetic fabric footprint) plus an end-to-end test that runs the coverage pipeline over it and pins the resulting served-location counts. Mount the fixture into the test container so the e2e runs in CI.
Break the single large routes.py into a routes/ package of Flask blueprints grouped by domain (auth, users, organizations, filings, files, edit, tiles, export, wireless, tasks, challenge, admin), with shared email helpers in routes/_email.py. routes/__init__.py registers the blueprints on the app and re-exposes `app` so `gunicorn routes:app` is unchanged; `python -m routes` runs the dev server. All endpoint paths are unchanged.
Add get_session() backed by a scoped_session and a teardown_appcontext that rolls it back and closes it at the end of each request, replacing the per-handler Session() + try/finally/close boilerplate in the route handlers. Also fix fabric_ops.write_to_db, which acquired and closed the scoped session: harmless across processes, but under eager task execution it runs on the web request's thread and would detach that request's in-flight ORM objects. It now uses its own Session().
Add indexes on the columns behind the heaviest queries: kml_data and fabric_data (file_id, location_id), celerytaskinfo (organization_id), and a composite index on vector_tiles (mbtiles_id, zoom_level, tile_column, tile_row). Declared on the models and created by an alembic migration; a test pins the expected index set.
Move the filing-delete, upload-dispatch (create/import), export, and edit-apply logic out of the route handlers into a services/ package. Service functions take plain arguments and a database session and return plain data, so they are testable without Flask; they raise ServiceError(message, status) for expected failures, which the handlers translate into responses. Handlers become thin request-parse-and-delegate wrappers. Adds unit tests for each flow.
Configure Jest via next/jest (jsdom environment, no browser) with an `npm test` script and a CI job, and add initial component tests that pin how components read API response shapes.
Return all error responses in a consistent {status: 'error', message} shape,
give failures proper HTTP status codes (several previously returned 200), and add
a global handler so unexpected exceptions return a clean JSON 500 instead of an
HTML error page. Update the one frontend component that read the previous error
key.
os.getenv returns a string and a non-empty value such as "0" is truthy in
Python, so a dev setting of IN_PRODUCTION=0 silently enabled production behavior
(Secure auth cookies). Interpret only explicit truthy strings ("1", "true", ...)
as production.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Big refactor of the main API router into blueprints to avoid one giant routes file. Adds a synthetic end-to-end test and fake data fixture. Adds first front-end tests and standardizes front-end response format (previously, these varied by API endpoint).