Skip to content

Commit

Permalink
Add additional tests for the webserver's startup
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanscherzinger committed Jul 19, 2024
1 parent 7d6f2d9 commit 91aa53d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion schunk_egu_egk_gripper_dummy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pip install fastapi uvicorn
## Run tests locally

```bash
pip install pytest coverage
pip install pytest httpx coverage
```

```bash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

# Components
dummy = Dummy()
dummy.start()
server = FastAPI()
client = ["http://localhost:8001"]

Expand Down
2 changes: 2 additions & 0 deletions schunk_egu_egk_gripper_dummy/src/dummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ def get_info(self, query: dict[str, str]) -> dict:
return {"dataformat": 0} # 0: Little endian, 1: Big endian

def get_enum(self, query: dict[str, str]) -> list:
if "inst" not in query or "value" not in query:
return []
inst = query["inst"]
value = int(query["value"])
if inst in self.enum:
Expand Down
17 changes: 17 additions & 0 deletions schunk_egu_egk_gripper_dummy/tests/test_webserver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from schunk_egu_egk_gripper_dummy.main import server
from fastapi.testclient import TestClient


def test_info_route_is_available():
client = TestClient(server)
assert client.get("/adi/info.json").is_success


def test_enum_route_is_available():
client = TestClient(server)
assert client.get("/adi/enum.json").is_success


def test_data_route_is_available():
client = TestClient(server)
assert client.get("/adi/data.json").is_success

0 comments on commit 91aa53d

Please sign in to comment.