Improved tests for add in integration tests

This commit is contained in:
Donkie
2023-05-28 21:40:17 +02:00
parent de1bf05922
commit 424856c710
5 changed files with 122 additions and 32 deletions

View File

@@ -38,16 +38,47 @@ def test_add_filament(random_vendor: dict[str, Any]):
# Verify
filament = result.json()
assert filament["name"] == name
assert filament["vendor"] == random_vendor
assert filament["material"] == material
assert filament["price"] == price
assert filament["density"] == density
assert filament["diameter"] == diameter
assert filament["weight"] == weight
assert filament["spool_weight"] == spool_weight
assert filament["article_number"] == article_number
assert filament["comment"] == comment
assert filament == {
"id": filament["id"],
"registered": filament["registered"],
"name": name,
"vendor": random_vendor,
"material": material,
"price": price,
"density": density,
"diameter": diameter,
"weight": weight,
"spool_weight": spool_weight,
"article_number": article_number,
"comment": comment,
}
# Clean up
httpx.delete(f"{URL}/api/v1/filament/{filament['id']}").raise_for_status()
def test_add_filament_required():
"""Test adding a filament with only the required fields to the database."""
# Execute
density = 1.25
diameter = 1.75
result = httpx.post(
f"{URL}/api/v1/filament",
json={
"density": density,
"diameter": diameter,
},
)
result.raise_for_status()
# Verify
filament = result.json()
assert filament == {
"id": filament["id"],
"registered": filament["registered"],
"density": density,
"diameter": diameter,
}
# Clean up
httpx.delete(f"{URL}/api/v1/filament/{filament['id']}").raise_for_status()

View File

@@ -34,14 +34,18 @@ def test_add_spool_remaining_weight(random_filament: dict[str, Any]):
# Verify
spool = result.json()
assert spool["first_used"] == first_used
assert spool["last_used"] == last_used
assert spool["filament"] == random_filament
assert spool["remaining_weight"] == pytest.approx(remaining_weight)
assert spool["used_weight"] == pytest.approx(random_filament["weight"] - remaining_weight)
assert spool["location"] == location
assert spool["lot_nr"] == lot_nr
assert spool["comment"] == comment
assert spool == {
"id": spool["id"],
"registered": spool["registered"],
"first_used": first_used,
"last_used": last_used,
"filament": random_filament,
"remaining_weight": pytest.approx(remaining_weight),
"used_weight": pytest.approx(random_filament["weight"] - remaining_weight),
"location": location,
"lot_nr": lot_nr,
"comment": comment,
}
# Clean up
httpx.delete(f"{URL}/api/v1/spool/{spool['id']}").raise_for_status()
@@ -72,14 +76,45 @@ def test_add_spool_used_weight(random_filament: dict[str, Any]):
# Verify
spool = result.json()
assert spool["first_used"] == first_used
assert spool["last_used"] == last_used
assert spool["filament"] == random_filament
assert spool["remaining_weight"] == pytest.approx(random_filament["weight"] - used_weight)
assert spool["used_weight"] == pytest.approx(used_weight)
assert spool["location"] == location
assert spool["lot_nr"] == lot_nr
assert spool["comment"] == comment
assert spool == {
"id": spool["id"],
"registered": spool["registered"],
"first_used": first_used,
"last_used": last_used,
"filament": random_filament,
"remaining_weight": pytest.approx(random_filament["weight"] - used_weight),
"used_weight": pytest.approx(used_weight),
"location": location,
"lot_nr": lot_nr,
"comment": comment,
}
# Clean up
httpx.delete(f"{URL}/api/v1/spool/{spool['id']}").raise_for_status()
def test_add_spool_required(random_filament: dict[str, Any]):
"""Test adding a spool with only the required fields to the database."""
# Execute
used_weight = 250
result = httpx.post(
f"{URL}/api/v1/spool",
json={
"filament_id": random_filament["id"],
"used_weight": used_weight,
},
)
result.raise_for_status()
# Verify
spool = result.json()
assert spool == {
"id": spool["id"],
"registered": spool["registered"],
"filament": random_filament,
"used_weight": pytest.approx(used_weight),
"remaining_weight": pytest.approx(random_filament["weight"] - used_weight),
}
# Clean up
httpx.delete(f"{URL}/api/v1/spool/{spool['id']}").raise_for_status()

View File

@@ -18,10 +18,34 @@ def test_add_vendor():
# Verify
vendor = result.json()
assert vendor["name"] == name
assert vendor["comment"] == comment
assert vendor["id"] is not None
assert vendor["registered"] is not None
assert vendor == {
"id": vendor["id"],
"registered": vendor["registered"],
"name": name,
"comment": comment,
}
# Clean up
httpx.delete(f"{URL}/api/v1/vendor/{vendor['id']}").raise_for_status()
def test_add_vendor_required():
"""Test adding a vendor with only the required fields to the database."""
# Execute
name = "John"
result = httpx.post(
f"{URL}/api/v1/vendor",
json={"name": name},
)
result.raise_for_status()
# Verify
vendor = result.json()
assert vendor == {
"id": vendor["id"],
"registered": vendor["registered"],
"name": name,
}
# Clean up
httpx.delete(f"{URL}/api/v1/vendor/{vendor['id']}").raise_for_status()