Skip to content

Commit

Permalink
Full API integration test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Donkie committed May 21, 2023
1 parent 1d87235 commit 5f639b7
Show file tree
Hide file tree
Showing 4 changed files with 935 additions and 6 deletions.
48 changes: 48 additions & 0 deletions tests_integration/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
"""Test fixtures for integration tests."""

import time
from typing import Any

import httpx
import pytest

TIMEOUT = 10

URL = "http://spoolman:8000"


@pytest.fixture(scope="session", autouse=True)
def _wait_for_server(): # noqa: ANN202
Expand All @@ -21,3 +24,48 @@ def _wait_for_server(): # noqa: ANN202
raise
else:
break


@pytest.fixture()
def random_vendor():
"""Return a random vendor."""
# Add vendor
result = httpx.post(
f"{URL}/api/v1/vendor",
json={"name": "John"},
)
result.raise_for_status()

vendor = result.json()
yield vendor

# Delete vendor
httpx.delete(f"{URL}/api/v1/vendor/{vendor['id']}").raise_for_status()


@pytest.fixture()
def random_filament(random_vendor: dict[str, Any]):
"""Return a random filament."""
# Add filament
result = httpx.post(
f"{URL}/api/v1/filament",
json={
"name": "Filament X",
"vendor_id": random_vendor["id"],
"material": "PLA",
"price": 100,
"density": 1.25,
"diameter": 1.75,
"weight": 1000,
"spool_weight": 250,
"article_number": "123456789",
"comment": "abcdefghåäö",
},
)
result.raise_for_status()

filament = result.json()
yield filament

# Delete filament
httpx.delete(f"{URL}/api/v1/filament/{filament['id']}").raise_for_status()
Loading

0 comments on commit 5f639b7

Please sign in to comment.