Skip to content

Commit

Permalink
Make client's python FastAPI connect endpoint (#5)
Browse files Browse the repository at this point in the history
* Adding the client FastAPI file
* Adding a simple "connect" endpoint
* Adding tests
* Adding github workflow to run the tests (copied from FL4Health)
* Adding info on how to start the client on README.md
  • Loading branch information
lotif authored Feb 22, 2024
1 parent 7535f0f commit 125d70e
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/static_code_checks.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
42 changes: 42 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -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/*
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Empty file added florist/__init__.py
Empty file.
Empty file added florist/api/__init__.py
Empty file.
14 changes: 14 additions & 0 deletions florist/api/client.py
Original file line number Diff line number Diff line change
@@ -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"})
Empty file added florist/tests/api/__init__.py
Empty file.
10 changes: 10 additions & 0 deletions florist/tests/api/test_client.py
Original file line number Diff line number Diff line change
@@ -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=(",", ":"))

0 comments on commit 125d70e

Please sign in to comment.