From c6eaec4bb890488c646add9740ad450c326d6e1b Mon Sep 17 00:00:00 2001 From: makambo13 <205113041+makambo13@users.noreply.github.com> Date: Wed, 11 Nov 2026 16:21:35 -0800 Subject: [PATCH] Add CI, tests and an Excalidraw-style system design diagram - GitHub Actions runs pytest on Python 3.11, 3.12 and 3.13 - 6 tests using an in-memory SQLite database - create_app accepts test settings - docs/system-design.svg plus editable .excalidraw source - README: CI badge, system design and tests sections Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 21 + README.md | 17 + app/__init__.py | 6 +- docs/system-design.excalidraw | 1363 +++++++++++++++++++++++++++++++++ docs/system-design.svg | 74 ++ tests/__init__.py | 0 tests/conftest.py | 21 + tests/test_app.py | 42 + 8 files changed, 1543 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/ci.yml create mode 100644 docs/system-design.excalidraw create mode 100644 docs/system-design.svg create mode 100644 tests/__init__.py create mode 100644 tests/conftest.py create mode 100644 tests/test_app.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..c0f6829 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,21 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.11", "3.12", "3.13"] + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + cache: pip + - run: pip install -r requirements.txt pytest + - run: pytest -q diff --git a/README.md b/README.md index 422d4de..93975fb 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # UserTask +[![CI](https://github.com/makambo13/UserTask/actions/workflows/ci.yml/badge.svg)](https://github.com/makambo13/UserTask/actions/workflows/ci.yml) + A small Flask app for a personal task list. Add a task with a title, a description and a priority, and the list shows the newest first.

@@ -22,6 +24,12 @@ python run.py Open http://127.0.0.1:5000. The SQLite database is created in `instance/` the first time the app starts. +## System design + +![UserTask system design](docs/system-design.svg) + +A request goes from the browser to the routes. The routes check the form, call `TaskService` to read or save tasks, and render a Jinja template back to the browser. Flask-Migrate manages the database schema. To edit the diagram, open `docs/system-design.excalidraw` at [excalidraw.com](https://excalidraw.com). + ## How it works - `tasks/routes.py` handles requests @@ -30,3 +38,12 @@ Open http://127.0.0.1:5000. The SQLite database is created in `instance/` the fi - `tasks/forms.py` has the Flask-WTF form Not built yet: login, and editing, completing or deleting a task. Every task belongs to user 1. + +## Tests and CI + +```sh +pip install pytest +pytest -q +``` + +The 6 tests in `tests/` use an in-memory database, so they never touch `instance/tasks.db`. GitHub Actions runs them on Python 3.11, 3.12 and 3.13 for every push to `main` and every pull request. diff --git a/app/__init__.py b/app/__init__.py index 8ca72c3..02efe82 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -6,7 +6,7 @@ # Initialize the db db = SQLAlchemy() -def create_app(): +def create_app(test_config=None): app = Flask(__name__) # Ensure instance folder exists @@ -20,6 +20,10 @@ def create_app(): app.config['SQLALCHEMY_DATABASE_URI'] = f"sqlite:///{os.path.join(app.instance_path, 'tasks.db')}" app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False + # Tests pass their own settings, such as an in-memory database + if test_config: + app.config.update(test_config) + # Initialize Migrate with app and db migrate = Migrate(app, db) diff --git a/docs/system-design.excalidraw b/docs/system-design.excalidraw new file mode 100644 index 0000000..d13074e --- /dev/null +++ b/docs/system-design.excalidraw @@ -0,0 +1,1363 @@ +{ + "type": "excalidraw", + "version": 2, + "source": "https://excalidraw.com", + "elements": [ + { + "id": "b64ce4228c38fb29", + "type": "rectangle", + "x": 40, + "y": 100, + "width": 170, + "height": 70, + "angle": 0, + "strokeColor": "#1e1e1e", + "backgroundColor": "#a5d8ff", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "roundness": { + "type": 3 + }, + "seed": 269676600, + "version": 1, + "versionNonce": 255985077, + "isDeleted": false, + "groupIds": [], + "frameId": null, + "boundElements": [], + "updated": 1, + "link": null, + "locked": false + }, + { + "id": "34b9b5df9e7769b1", + "type": "text", + "x": 50, + "y": 115.0, + "width": 150, + "height": 40, + "angle": 0, + "strokeColor": "#1e1e1e", + "backgroundColor": "transparent", + "fillStyle": "solid", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "seed": 2132084005, + "version": 1, + "versionNonce": 1836494975, + "isDeleted": false, + "groupIds": [], + "frameId": null, + "boundElements": null, + "updated": 1, + "link": null, + "locked": false, + "text": "Browser\nGET / , POST /tasks/create", + "fontSize": 14, + "fontFamily": 1, + "textAlign": "center", + "verticalAlign": "middle", + "baseline": 30, + "containerId": null, + "originalText": "Browser\nGET / , POST /tasks/create", + "lineHeight": 1.25 + }, + { + "id": "0f88080b10a3d6b2", + "type": "rectangle", + "x": 300, + "y": 100, + "width": 190, + "height": 70, + "angle": 0, + "strokeColor": "#1e1e1e", + "backgroundColor": "#ffec99", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "roundness": { + "type": 3 + }, + "seed": 1329753548, + "version": 1, + "versionNonce": 1914012529, + "isDeleted": false, + "groupIds": [], + "frameId": null, + "boundElements": [], + "updated": 1, + "link": null, + "locked": false + }, + { + "id": "b774eb5248db40af", + "type": "text", + "x": 310, + "y": 115.0, + "width": 170, + "height": 40, + "angle": 0, + "strokeColor": "#1e1e1e", + "backgroundColor": "transparent", + "fillStyle": "solid", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "seed": 1656961616, + "version": 1, + "versionNonce": 1490376254, + "isDeleted": false, + "groupIds": [], + "frameId": null, + "boundElements": null, + "updated": 1, + "link": null, + "locked": false, + "text": "Routes\ntasks/routes.py (blueprint)", + "fontSize": 14, + "fontFamily": 1, + "textAlign": "center", + "verticalAlign": "middle", + "baseline": 30, + "containerId": null, + "originalText": "Routes\ntasks/routes.py (blueprint)", + "lineHeight": 1.25 + }, + { + "id": "20203626f3fe39c0", + "type": "rectangle", + "x": 580, + "y": 70, + "width": 170, + "height": 60, + "angle": 0, + "strokeColor": "#1e1e1e", + "backgroundColor": "#ffd8a8", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "roundness": { + "type": 3 + }, + "seed": 231897702, + "version": 1, + "versionNonce": 1961269854, + "isDeleted": false, + "groupIds": [], + "frameId": null, + "boundElements": [], + "updated": 1, + "link": null, + "locked": false + }, + { + "id": "def88334e647cb8f", + "type": "text", + "x": 590, + "y": 80.0, + "width": 150, + "height": 40, + "angle": 0, + "strokeColor": "#1e1e1e", + "backgroundColor": "transparent", + "fillStyle": "solid", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "seed": 1685254564, + "version": 1, + "versionNonce": 1709696036, + "isDeleted": false, + "groupIds": [], + "frameId": null, + "boundElements": null, + "updated": 1, + "link": null, + "locked": false, + "text": "TaskForm\nFlask-WTF validation", + "fontSize": 14, + "fontFamily": 1, + "textAlign": "center", + "verticalAlign": "middle", + "baseline": 30, + "containerId": null, + "originalText": "TaskForm\nFlask-WTF validation", + "lineHeight": 1.25 + }, + { + "id": "f3b7a50df373ca53", + "type": "rectangle", + "x": 580, + "y": 170, + "width": 170, + "height": 60, + "angle": 0, + "strokeColor": "#1e1e1e", + "backgroundColor": "#ffd8a8", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "roundness": { + "type": 3 + }, + "seed": 1553714998, + "version": 1, + "versionNonce": 629653100, + "isDeleted": false, + "groupIds": [], + "frameId": null, + "boundElements": [], + "updated": 1, + "link": null, + "locked": false + }, + { + "id": "8b0d590bb0a844e5", + "type": "text", + "x": 590, + "y": 180.0, + "width": 150, + "height": 40, + "angle": 0, + "strokeColor": "#1e1e1e", + "backgroundColor": "transparent", + "fillStyle": "solid", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "seed": 116146606, + "version": 1, + "versionNonce": 1280285447, + "isDeleted": false, + "groupIds": [], + "frameId": null, + "boundElements": null, + "updated": 1, + "link": null, + "locked": false, + "text": "Jinja templates\nlist / landing / error", + "fontSize": 14, + "fontFamily": 1, + "textAlign": "center", + "verticalAlign": "middle", + "baseline": 30, + "containerId": null, + "originalText": "Jinja templates\nlist / landing / error", + "lineHeight": 1.25 + }, + { + "id": "785729763a12917c", + "type": "rectangle", + "x": 300, + "y": 270, + "width": 190, + "height": 70, + "angle": 0, + "strokeColor": "#1e1e1e", + "backgroundColor": "#b2f2bb", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "roundness": { + "type": 3 + }, + "seed": 844846558, + "version": 1, + "versionNonce": 1450571438, + "isDeleted": false, + "groupIds": [], + "frameId": null, + "boundElements": [], + "updated": 1, + "link": null, + "locked": false + }, + { + "id": "7b8f2ab53451d013", + "type": "text", + "x": 310, + "y": 285.0, + "width": 170, + "height": 40, + "angle": 0, + "strokeColor": "#1e1e1e", + "backgroundColor": "transparent", + "fillStyle": "solid", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "seed": 8196149, + "version": 1, + "versionNonce": 2059322682, + "isDeleted": false, + "groupIds": [], + "frameId": null, + "boundElements": null, + "updated": 1, + "link": null, + "locked": false, + "text": "TaskService\ntasks/services.py", + "fontSize": 14, + "fontFamily": 1, + "textAlign": "center", + "verticalAlign": "middle", + "baseline": 30, + "containerId": null, + "originalText": "TaskService\ntasks/services.py", + "lineHeight": 1.25 + }, + { + "id": "86ce03f91a4f44f9", + "type": "rectangle", + "x": 300, + "y": 420, + "width": 190, + "height": 70, + "angle": 0, + "strokeColor": "#1e1e1e", + "backgroundColor": "#d0bfff", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "roundness": { + "type": 3 + }, + "seed": 598077321, + "version": 1, + "versionNonce": 1863197322, + "isDeleted": false, + "groupIds": [], + "frameId": null, + "boundElements": [], + "updated": 1, + "link": null, + "locked": false + }, + { + "id": "df2a8b79fc8e80b3", + "type": "text", + "x": 310, + "y": 435.0, + "width": 170, + "height": 40, + "angle": 0, + "strokeColor": "#1e1e1e", + "backgroundColor": "transparent", + "fillStyle": "solid", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "seed": 836682997, + "version": 1, + "versionNonce": 906419965, + "isDeleted": false, + "groupIds": [], + "frameId": null, + "boundElements": null, + "updated": 1, + "link": null, + "locked": false, + "text": "Models\nTask, User (SQLAlchemy)", + "fontSize": 14, + "fontFamily": 1, + "textAlign": "center", + "verticalAlign": "middle", + "baseline": 30, + "containerId": null, + "originalText": "Models\nTask, User (SQLAlchemy)", + "lineHeight": 1.25 + }, + { + "id": "3f9d52f90e8bec94", + "type": "rectangle", + "x": 300, + "y": 560, + "width": 190, + "height": 70, + "angle": 0, + "strokeColor": "#1e1e1e", + "backgroundColor": "#e9ecef", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "roundness": { + "type": 3 + }, + "seed": 821653593, + "version": 1, + "versionNonce": 1189349777, + "isDeleted": false, + "groupIds": [], + "frameId": null, + "boundElements": [], + "updated": 1, + "link": null, + "locked": false + }, + { + "id": "c5b2e75a0acd8be1", + "type": "text", + "x": 310, + "y": 575.0, + "width": 170, + "height": 40, + "angle": 0, + "strokeColor": "#1e1e1e", + "backgroundColor": "transparent", + "fillStyle": "solid", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "seed": 419812754, + "version": 1, + "versionNonce": 1942080813, + "isDeleted": false, + "groupIds": [], + "frameId": null, + "boundElements": null, + "updated": 1, + "link": null, + "locked": false, + "text": "SQLite\ninstance/tasks.db", + "fontSize": 14, + "fontFamily": 1, + "textAlign": "center", + "verticalAlign": "middle", + "baseline": 30, + "containerId": null, + "originalText": "SQLite\ninstance/tasks.db", + "lineHeight": 1.25 + }, + { + "id": "23231e1ee2015522", + "type": "rectangle", + "x": 40, + "y": 560, + "width": 170, + "height": 70, + "angle": 0, + "strokeColor": "#1e1e1e", + "backgroundColor": "#e9ecef", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "roundness": { + "type": 3 + }, + "seed": 2008910112, + "version": 1, + "versionNonce": 943122534, + "isDeleted": false, + "groupIds": [], + "frameId": null, + "boundElements": [], + "updated": 1, + "link": null, + "locked": false + }, + { + "id": "f3d74f82bf268ea0", + "type": "text", + "x": 50, + "y": 575.0, + "width": 150, + "height": 40, + "angle": 0, + "strokeColor": "#1e1e1e", + "backgroundColor": "transparent", + "fillStyle": "solid", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "seed": 404265717, + "version": 1, + "versionNonce": 1710500231, + "isDeleted": false, + "groupIds": [], + "frameId": null, + "boundElements": null, + "updated": 1, + "link": null, + "locked": false, + "text": "Flask-Migrate\nmigrations/ (Alembic)", + "fontSize": 14, + "fontFamily": 1, + "textAlign": "center", + "verticalAlign": "middle", + "baseline": 30, + "containerId": null, + "originalText": "Flask-Migrate\nmigrations/ (Alembic)", + "lineHeight": 1.25 + }, + { + "id": "eb4ed2e3895e8b6b", + "type": "rectangle", + "x": 640, + "y": 440, + "width": 290, + "height": 80, + "angle": 0, + "strokeColor": "#1e1e1e", + "backgroundColor": "#ffc9c9", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "roundness": { + "type": 3 + }, + "seed": 2124342558, + "version": 1, + "versionNonce": 1404662648, + "isDeleted": false, + "groupIds": [], + "frameId": null, + "boundElements": [], + "updated": 1, + "link": null, + "locked": false + }, + { + "id": "4770a08716e6fec3", + "type": "text", + "x": 650, + "y": 460.0, + "width": 270, + "height": 40, + "angle": 0, + "strokeColor": "#1e1e1e", + "backgroundColor": "transparent", + "fillStyle": "solid", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "seed": 247074473, + "version": 1, + "versionNonce": 787456634, + "isDeleted": false, + "groupIds": [], + "frameId": null, + "boundElements": null, + "updated": 1, + "link": null, + "locked": false, + "text": "GitHub Actions CI\npytest on Python 3.11, 3.12, 3.13", + "fontSize": 14, + "fontFamily": 1, + "textAlign": "center", + "verticalAlign": "middle", + "baseline": 30, + "containerId": null, + "originalText": "GitHub Actions CI\npytest on Python 3.11, 3.12, 3.13", + "lineHeight": 1.25 + }, + { + "id": "fa6197748d118e37", + "type": "rectangle", + "x": 640, + "y": 570, + "width": 290, + "height": 60, + "angle": 0, + "strokeColor": "#1e1e1e", + "backgroundColor": "#ffc9c9", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "roundness": { + "type": 3 + }, + "seed": 813709450, + "version": 1, + "versionNonce": 2039081425, + "isDeleted": false, + "groupIds": [], + "frameId": null, + "boundElements": [], + "updated": 1, + "link": null, + "locked": false + }, + { + "id": "ef44c0d53ee4da5a", + "type": "text", + "x": 650, + "y": 580.0, + "width": 270, + "height": 40, + "angle": 0, + "strokeColor": "#1e1e1e", + "backgroundColor": "transparent", + "fillStyle": "solid", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "seed": 1920088989, + "version": 1, + "versionNonce": 456474908, + "isDeleted": false, + "groupIds": [], + "frameId": null, + "boundElements": null, + "updated": 1, + "link": null, + "locked": false, + "text": "tests/\n6 tests, in-memory SQLite", + "fontSize": 14, + "fontFamily": 1, + "textAlign": "center", + "verticalAlign": "middle", + "baseline": 30, + "containerId": null, + "originalText": "tests/\n6 tests, in-memory SQLite", + "lineHeight": 1.25 + }, + { + "id": "7eb86c57a81100a1", + "type": "arrow", + "x": 210.0, + "y": 135.0, + "width": 90.0, + "height": 0.0, + "angle": 0, + "strokeColor": "#1e1e1e", + "backgroundColor": "transparent", + "fillStyle": "solid", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "roundness": { + "type": 2 + }, + "seed": 1688291830, + "version": 1, + "versionNonce": 1321918115, + "isDeleted": false, + "groupIds": [], + "frameId": null, + "boundElements": null, + "updated": 1, + "link": null, + "locked": false, + "points": [ + [ + 0, + 0 + ], + [ + 90.0, + 0.0 + ] + ], + "lastCommittedPoint": null, + "startBinding": null, + "endBinding": null, + "startArrowhead": null, + "endArrowhead": "arrow" + }, + { + "id": "37161c16b00fd7bb", + "type": "text", + "x": 264.8998438554037, + "y": 118.80127192427315, + "width": 90, + "height": 18, + "angle": 0, + "strokeColor": "#1971c2", + "backgroundColor": "transparent", + "fillStyle": "solid", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "seed": 985979547, + "version": 1, + "versionNonce": 1471905176, + "isDeleted": false, + "groupIds": [], + "frameId": null, + "boundElements": null, + "updated": 1, + "link": null, + "locked": false, + "text": "request", + "fontSize": 13, + "fontFamily": 1, + "textAlign": "left", + "verticalAlign": "top", + "baseline": 13, + "containerId": null, + "originalText": "request", + "lineHeight": 1.25 + }, + { + "id": "a2cf62baba958810", + "type": "arrow", + "x": 490.0, + "y": 122.68518518518519, + "width": 90.0, + "height": 11.666666666666671, + "angle": 0, + "strokeColor": "#1e1e1e", + "backgroundColor": "transparent", + "fillStyle": "solid", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "roundness": { + "type": 2 + }, + "seed": 600087727, + "version": 1, + "versionNonce": 1738163422, + "isDeleted": false, + "groupIds": [], + "frameId": null, + "boundElements": null, + "updated": 1, + "link": null, + "locked": false, + "points": [ + [ + 0, + 0 + ], + [ + 90.0, + -11.666666666666671 + ] + ], + "lastCommittedPoint": null, + "startBinding": null, + "endBinding": null, + "startArrowhead": null, + "endArrowhead": "arrow" + }, + { + "id": "58f92deafd4bd030", + "type": "text", + "x": 461.3834937958974, + "y": 101.43498939744273, + "width": 90, + "height": 18, + "angle": 0, + "strokeColor": "#1971c2", + "backgroundColor": "transparent", + "fillStyle": "solid", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "seed": 233596964, + "version": 1, + "versionNonce": 557566592, + "isDeleted": false, + "groupIds": [], + "frameId": null, + "boundElements": null, + "updated": 1, + "link": null, + "locked": false, + "text": "validate", + "fontSize": 13, + "fontFamily": 1, + "textAlign": "left", + "verticalAlign": "top", + "baseline": 13, + "containerId": null, + "originalText": "validate", + "lineHeight": 1.25 + }, + { + "id": "416e99b0e13e213e", + "type": "arrow", + "x": 490.0, + "y": 157.87037037037038, + "width": 90.0, + "height": 21.666666666666657, + "angle": 0, + "strokeColor": "#1e1e1e", + "backgroundColor": "transparent", + "fillStyle": "solid", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "roundness": { + "type": 2 + }, + "seed": 1850017270, + "version": 1, + "versionNonce": 701138478, + "isDeleted": false, + "groupIds": [], + "frameId": null, + "boundElements": null, + "updated": 1, + "link": null, + "locked": false, + "points": [ + [ + 0, + 0 + ], + [ + 90.0, + 21.666666666666657 + ] + ], + "lastCommittedPoint": null, + "startBinding": null, + "endBinding": null, + "startArrowhead": null, + "endArrowhead": "arrow" + }, + { + "id": "15a0cce60e2ec40a", + "type": "text", + "x": 537.1710615519336, + "y": 152.20908347656552, + "width": 90, + "height": 18, + "angle": 0, + "strokeColor": "#1971c2", + "backgroundColor": "transparent", + "fillStyle": "solid", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "seed": 1635874816, + "version": 1, + "versionNonce": 1210894223, + "isDeleted": false, + "groupIds": [], + "frameId": null, + "boundElements": null, + "updated": 1, + "link": null, + "locked": false, + "text": "render", + "fontSize": 13, + "fontFamily": 1, + "textAlign": "left", + "verticalAlign": "top", + "baseline": 13, + "containerId": null, + "originalText": "render", + "lineHeight": 1.25 + }, + { + "id": "759eb5590b94af3a", + "type": "arrow", + "x": 395.0, + "y": 170.0, + "width": 0.0, + "height": 100.0, + "angle": 0, + "strokeColor": "#1e1e1e", + "backgroundColor": "transparent", + "fillStyle": "solid", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "roundness": { + "type": 2 + }, + "seed": 796080902, + "version": 1, + "versionNonce": 676598821, + "isDeleted": false, + "groupIds": [], + "frameId": null, + "boundElements": null, + "updated": 1, + "link": null, + "locked": false, + "points": [ + [ + 0, + 0 + ], + [ + 0.0, + 100.0 + ] + ], + "lastCommittedPoint": null, + "startBinding": null, + "endBinding": null, + "startArrowhead": null, + "endArrowhead": "arrow" + }, + { + "id": "72218fdc44df96ff", + "type": "text", + "x": 404.1853409626078, + "y": 204.31222620246336, + "width": 90, + "height": 18, + "angle": 0, + "strokeColor": "#1971c2", + "backgroundColor": "transparent", + "fillStyle": "solid", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "seed": 15559427, + "version": 1, + "versionNonce": 1130620378, + "isDeleted": false, + "groupIds": [], + "frameId": null, + "boundElements": null, + "updated": 1, + "link": null, + "locked": false, + "text": "create / list", + "fontSize": 13, + "fontFamily": 1, + "textAlign": "left", + "verticalAlign": "top", + "baseline": 13, + "containerId": null, + "originalText": "create / list", + "lineHeight": 1.25 + }, + { + "id": "8c0d0033fc2325a9", + "type": "arrow", + "x": 395.0, + "y": 340.0, + "width": 0.0, + "height": 80.0, + "angle": 0, + "strokeColor": "#1e1e1e", + "backgroundColor": "transparent", + "fillStyle": "solid", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "roundness": { + "type": 2 + }, + "seed": 1389567516, + "version": 1, + "versionNonce": 1049889717, + "isDeleted": false, + "groupIds": [], + "frameId": null, + "boundElements": null, + "updated": 1, + "link": null, + "locked": false, + "points": [ + [ + 0, + 0 + ], + [ + 0.0, + 80.0 + ] + ], + "lastCommittedPoint": null, + "startBinding": null, + "endBinding": null, + "startArrowhead": null, + "endArrowhead": "arrow" + }, + { + "id": "f735efe608d18011", + "type": "text", + "x": 401.3696962262797, + "y": 359.94711401813834, + "width": 90, + "height": 18, + "angle": 0, + "strokeColor": "#1971c2", + "backgroundColor": "transparent", + "fillStyle": "solid", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "seed": 1329498207, + "version": 1, + "versionNonce": 935726745, + "isDeleted": false, + "groupIds": [], + "frameId": null, + "boundElements": null, + "updated": 1, + "link": null, + "locked": false, + "text": "query", + "fontSize": 13, + "fontFamily": 1, + "textAlign": "left", + "verticalAlign": "top", + "baseline": 13, + "containerId": null, + "originalText": "query", + "lineHeight": 1.25 + }, + { + "id": "1579da0a61b2480c", + "type": "arrow", + "x": 395.0, + "y": 490.0, + "width": 0.0, + "height": 70.0, + "angle": 0, + "strokeColor": "#1e1e1e", + "backgroundColor": "transparent", + "fillStyle": "solid", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "roundness": { + "type": 2 + }, + "seed": 2038578867, + "version": 1, + "versionNonce": 1197990395, + "isDeleted": false, + "groupIds": [], + "frameId": null, + "boundElements": null, + "updated": 1, + "link": null, + "locked": false, + "points": [ + [ + 0, + 0 + ], + [ + 0.0, + 70.0 + ] + ], + "lastCommittedPoint": null, + "startBinding": null, + "endBinding": null, + "startArrowhead": null, + "endArrowhead": "arrow" + }, + { + "id": "a7f0c99e80b5244a", + "type": "text", + "x": 401.27900700416785, + "y": 501.012826979339, + "width": 90, + "height": 18, + "angle": 0, + "strokeColor": "#1971c2", + "backgroundColor": "transparent", + "fillStyle": "solid", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "seed": 863202765, + "version": 1, + "versionNonce": 1065922394, + "isDeleted": false, + "groupIds": [], + "frameId": null, + "boundElements": null, + "updated": 1, + "link": null, + "locked": false, + "text": "read / write", + "fontSize": 13, + "fontFamily": 1, + "textAlign": "left", + "verticalAlign": "top", + "baseline": 13, + "containerId": null, + "originalText": "read / write", + "lineHeight": 1.25 + }, + { + "id": "d129d06743a08f06", + "type": "arrow", + "x": 210.0, + "y": 595.0, + "width": 90.0, + "height": 0.0, + "angle": 0, + "strokeColor": "#1e1e1e", + "backgroundColor": "transparent", + "fillStyle": "solid", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "roundness": { + "type": 2 + }, + "seed": 385487906, + "version": 1, + "versionNonce": 617896093, + "isDeleted": false, + "groupIds": [], + "frameId": null, + "boundElements": null, + "updated": 1, + "link": null, + "locked": false, + "points": [ + [ + 0, + 0 + ], + [ + 90.0, + 0.0 + ] + ], + "lastCommittedPoint": null, + "startBinding": null, + "endBinding": null, + "startArrowhead": null, + "endArrowhead": "arrow" + }, + { + "id": "963892a766465d28", + "type": "text", + "x": 263.05682767417176, + "y": 571.0594063780474, + "width": 90, + "height": 18, + "angle": 0, + "strokeColor": "#1971c2", + "backgroundColor": "transparent", + "fillStyle": "solid", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "seed": 178958210, + "version": 1, + "versionNonce": 1692125396, + "isDeleted": false, + "groupIds": [], + "frameId": null, + "boundElements": null, + "updated": 1, + "link": null, + "locked": false, + "text": "schema", + "fontSize": 13, + "fontFamily": 1, + "textAlign": "left", + "verticalAlign": "top", + "baseline": 13, + "containerId": null, + "originalText": "schema", + "lineHeight": 1.25 + }, + { + "id": "15a0a8ae3b996870", + "type": "arrow", + "x": 785.0, + "y": 520.0, + "width": 0.0, + "height": 50.0, + "angle": 0, + "strokeColor": "#1e1e1e", + "backgroundColor": "transparent", + "fillStyle": "solid", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "roundness": { + "type": 2 + }, + "seed": 666802866, + "version": 1, + "versionNonce": 1672960502, + "isDeleted": false, + "groupIds": [], + "frameId": null, + "boundElements": null, + "updated": 1, + "link": null, + "locked": false, + "points": [ + [ + 0, + 0 + ], + [ + 0.0, + 50.0 + ] + ], + "lastCommittedPoint": null, + "startBinding": null, + "endBinding": null, + "startArrowhead": null, + "endArrowhead": "arrow" + }, + { + "id": "537d9128c3a9e889", + "type": "text", + "x": 787.2699297636431, + "y": 524.6509347226921, + "width": 90, + "height": 18, + "angle": 0, + "strokeColor": "#1971c2", + "backgroundColor": "transparent", + "fillStyle": "solid", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "seed": 2122533125, + "version": 1, + "versionNonce": 641939353, + "isDeleted": false, + "groupIds": [], + "frameId": null, + "boundElements": null, + "updated": 1, + "link": null, + "locked": false, + "text": "runs", + "fontSize": 13, + "fontFamily": 1, + "textAlign": "left", + "verticalAlign": "top", + "baseline": 13, + "containerId": null, + "originalText": "runs", + "lineHeight": 1.25 + }, + { + "id": "b96245d348bfcbcf", + "type": "arrow", + "x": 580, + "y": 210, + "width": 455, + "height": 40, + "angle": 0, + "strokeColor": "#1e1e1e", + "backgroundColor": "transparent", + "fillStyle": "solid", + "strokeWidth": 1, + "strokeStyle": "dashed", + "roughness": 1, + "opacity": 100, + "roundness": { + "type": 2 + }, + "seed": 621706037, + "version": 1, + "versionNonce": 188068319, + "isDeleted": false, + "groupIds": [], + "frameId": null, + "boundElements": null, + "updated": 1, + "link": null, + "locked": false, + "points": [ + [ + 0, + 0 + ], + [ + -455, + -40 + ] + ], + "lastCommittedPoint": null, + "startBinding": null, + "endBinding": null, + "startArrowhead": null, + "endArrowhead": "arrow" + }, + { + "id": "d5d5891fd329d65c", + "type": "text", + "x": 250, + "y": 216, + "width": 90, + "height": 18, + "angle": 0, + "strokeColor": "#1971c2", + "backgroundColor": "transparent", + "fillStyle": "solid", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "seed": 1843591968, + "version": 1, + "versionNonce": 598321627, + "isDeleted": false, + "groupIds": [], + "frameId": null, + "boundElements": null, + "updated": 1, + "link": null, + "locked": false, + "text": "HTML", + "fontSize": 13, + "fontFamily": 1, + "textAlign": "left", + "verticalAlign": "top", + "baseline": 13, + "containerId": null, + "originalText": "HTML", + "lineHeight": 1.25 + } + ], + "appState": { + "viewBackgroundColor": "#ffffff", + "gridSize": null + }, + "files": {} +} \ No newline at end of file diff --git a/docs/system-design.svg b/docs/system-design.svg new file mode 100644 index 0000000..ea254aa --- /dev/null +++ b/docs/system-design.svg @@ -0,0 +1,74 @@ + + + + +UserTask: system design + + + +Browser +GET / , POST /tasks/create + + + +Routes +tasks/routes.py (blueprint) + + + +TaskForm +Flask-WTF validation + + + +Jinja templates +list / landing / error + + + +TaskService +tasks/services.py + + + +Models +Task, User (SQLAlchemy) + + + +SQLite +instance/tasks.db + + + +Flask-Migrate +migrations/ (Alembic) + + + +GitHub Actions CI +pytest on Python 3.11, 3.12, 3.13 + + + +tests/ +6 tests, in-memory SQLite + +request + +validate + +render + +create / list + +query + +read / write + +schema + +runs + +HTML + \ No newline at end of file diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..fc8f5be --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,21 @@ +import pytest + +from app import create_app, db + + +@pytest.fixture +def app(): + app = create_app({ + "TESTING": True, + "SQLALCHEMY_DATABASE_URI": "sqlite:///:memory:", + "WTF_CSRF_ENABLED": False, + }) + yield app + with app.app_context(): + db.session.remove() + db.drop_all() + + +@pytest.fixture +def client(app): + return app.test_client() diff --git a/tests/test_app.py b/tests/test_app.py new file mode 100644 index 0000000..814867b --- /dev/null +++ b/tests/test_app.py @@ -0,0 +1,42 @@ +from tasks.models import Task + + +def test_landing_page_loads(client): + assert client.get("/").status_code == 200 + + +def test_empty_list_shows_message(client): + res = client.get("/tasks/") + assert res.status_code == 200 + assert b"No tasks found" in res.data + + +def test_create_task(client, app): + res = client.post("/tasks/create", data={ + "title": "Write tests", "description": "pytest", "priority": "High", + }) + assert res.status_code == 302 + with app.app_context(): + task = Task.query.one() + assert task.title == "Write tests" + assert task.priority == "High" + assert task.user_id == 1 + + +def test_blank_title_is_rejected(client, app): + client.post("/tasks/create", data={"title": "", "priority": "Low"}) + with app.app_context(): + assert Task.query.count() == 0 + + +def test_list_is_newest_first(client): + client.post("/tasks/create", data={"title": "First", "priority": "Low"}) + client.post("/tasks/create", data={"title": "Second", "priority": "Low"}) + body = client.get("/tasks/").data + assert body.index(b"Second") < body.index(b"First") + + +def test_default_priority_is_medium(client, app): + client.post("/tasks/create", data={"title": "No priority"}) + with app.app_context(): + assert Task.query.one().priority == "Medium"