diff --git a/.github/workflows/static_code_checks.yaml b/.github/workflows/static_code_checks.yaml index 71a2a187..4ce815cd 100644 --- a/.github/workflows/static_code_checks.yaml +++ b/.github/workflows/static_code_checks.yaml @@ -1,4 +1,4 @@ -# only has to pass for python 3.8 +# only has to pass for python 3.9 name: Static code checks on: @@ -23,4 +23,4 @@ jobs: python-version: 3.9 - name: precommit checker - uses: pre-commit/action@v2.0.3 + uses: pre-commit/action@v3.0.1 diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml new file mode 100644 index 00000000..442c8b60 --- /dev/null +++ b/.github/workflows/tests.yaml @@ -0,0 +1,42 @@ +# only has to pass for python 3.9 +name: PyTest Unit Tests + +on: + push: + branches: + main + pull_request: + branches: + main + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + - name: Set up Python 3.9 + uses: actions/setup-python@v3 + with: + python-version: 3.9 + # Display the Python version being used + - name: Display Python version + run: python -c "import sys; print(sys.version)" + - name: Install and configure Poetry + uses: snok/install-poetry@v1 + with: + virtualenvs-create: true + virtualenvs-in-project: true + - name: Set up cache + uses: actions/cache@v2 + id: cached-poetry-dependencies + with: + path: .venv + key: venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('**/poetry.lock') }} + - name: Install dependencies + run: poetry install --with "dev, test" + if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' + - name: Run Tests + run: | + source .venv/bin/activate + pytest florist/tests/* diff --git a/README.md b/README.md index cefd77e7..26aad9a8 100644 --- a/README.md +++ b/README.md @@ -46,4 +46,10 @@ back-end APIs individually, they will be available at `https://localhost:8000`. ### Running the client -Coming up. +To start the client back-end service: + +```shell +uvicorn florist.api.client:app --reload --port 8001 +``` + +The service will be available at `http://localhost:8001`. diff --git a/florist/__init__.py b/florist/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/florist/api/__init__.py b/florist/api/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/florist/api/client.py b/florist/api/client.py new file mode 100644 index 00000000..56d01833 --- /dev/null +++ b/florist/api/client.py @@ -0,0 +1,14 @@ +from fastapi import FastAPI +from fastapi.responses import JSONResponse + +app = FastAPI() + + +@app.get("/api/client/connect") +def connect() -> JSONResponse: + """ + Confirms the client is up and ready to accept instructions. + + :return: JSON `{"status": "ok"}` + """ + return JSONResponse({"status": "ok"}) diff --git a/florist/tests/api/__init__.py b/florist/tests/api/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/florist/tests/api/test_client.py b/florist/tests/api/test_client.py new file mode 100644 index 00000000..7f7a5ea1 --- /dev/null +++ b/florist/tests/api/test_client.py @@ -0,0 +1,10 @@ +import json + +from florist.api import client + + +def test_connect() -> None: + response = client.connect() + + assert response.status_code == 200 + assert response.body.decode() == json.dumps({"status": "ok"}, separators=(",", ":"))