Improved tests for add in integration tests
This commit is contained in:
@@ -16,7 +16,7 @@ exclude = ["client"]
|
|||||||
|
|
||||||
[tool.ruff]
|
[tool.ruff]
|
||||||
select = ["ALL"]
|
select = ["ALL"]
|
||||||
ignore = ["A003", "D101", "D104", "D406", "D407", "S104", "TRY201", "TRY003", "EM101", "EM102", "DTZ003"]
|
ignore = ["A003", "D101", "D104", "D406", "D407", "S104", "TRY201", "TRY003", "EM101", "EM102", "DTZ003", "PLR0913"]
|
||||||
line-length = 120
|
line-length = 120
|
||||||
target-version = "py39"
|
target-version = "py39"
|
||||||
|
|
||||||
|
|||||||
@@ -6,4 +6,4 @@ WORKDIR /tester
|
|||||||
|
|
||||||
RUN pip install -r requirements.txt
|
RUN pip install -r requirements.txt
|
||||||
|
|
||||||
ENTRYPOINT [ "pytest", "tests" ]
|
ENTRYPOINT [ "pytest", "--exitfirst", "tests" ]
|
||||||
|
|||||||
@@ -38,16 +38,47 @@ def test_add_filament(random_vendor: dict[str, Any]):
|
|||||||
|
|
||||||
# Verify
|
# Verify
|
||||||
filament = result.json()
|
filament = result.json()
|
||||||
assert filament["name"] == name
|
assert filament == {
|
||||||
assert filament["vendor"] == random_vendor
|
"id": filament["id"],
|
||||||
assert filament["material"] == material
|
"registered": filament["registered"],
|
||||||
assert filament["price"] == price
|
"name": name,
|
||||||
assert filament["density"] == density
|
"vendor": random_vendor,
|
||||||
assert filament["diameter"] == diameter
|
"material": material,
|
||||||
assert filament["weight"] == weight
|
"price": price,
|
||||||
assert filament["spool_weight"] == spool_weight
|
"density": density,
|
||||||
assert filament["article_number"] == article_number
|
"diameter": diameter,
|
||||||
assert filament["comment"] == comment
|
"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
|
# Clean up
|
||||||
httpx.delete(f"{URL}/api/v1/filament/{filament['id']}").raise_for_status()
|
httpx.delete(f"{URL}/api/v1/filament/{filament['id']}").raise_for_status()
|
||||||
|
|||||||
@@ -34,14 +34,18 @@ def test_add_spool_remaining_weight(random_filament: dict[str, Any]):
|
|||||||
|
|
||||||
# Verify
|
# Verify
|
||||||
spool = result.json()
|
spool = result.json()
|
||||||
assert spool["first_used"] == first_used
|
assert spool == {
|
||||||
assert spool["last_used"] == last_used
|
"id": spool["id"],
|
||||||
assert spool["filament"] == random_filament
|
"registered": spool["registered"],
|
||||||
assert spool["remaining_weight"] == pytest.approx(remaining_weight)
|
"first_used": first_used,
|
||||||
assert spool["used_weight"] == pytest.approx(random_filament["weight"] - remaining_weight)
|
"last_used": last_used,
|
||||||
assert spool["location"] == location
|
"filament": random_filament,
|
||||||
assert spool["lot_nr"] == lot_nr
|
"remaining_weight": pytest.approx(remaining_weight),
|
||||||
assert spool["comment"] == comment
|
"used_weight": pytest.approx(random_filament["weight"] - remaining_weight),
|
||||||
|
"location": location,
|
||||||
|
"lot_nr": lot_nr,
|
||||||
|
"comment": comment,
|
||||||
|
}
|
||||||
|
|
||||||
# Clean up
|
# Clean up
|
||||||
httpx.delete(f"{URL}/api/v1/spool/{spool['id']}").raise_for_status()
|
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
|
# Verify
|
||||||
spool = result.json()
|
spool = result.json()
|
||||||
assert spool["first_used"] == first_used
|
assert spool == {
|
||||||
assert spool["last_used"] == last_used
|
"id": spool["id"],
|
||||||
assert spool["filament"] == random_filament
|
"registered": spool["registered"],
|
||||||
assert spool["remaining_weight"] == pytest.approx(random_filament["weight"] - used_weight)
|
"first_used": first_used,
|
||||||
assert spool["used_weight"] == pytest.approx(used_weight)
|
"last_used": last_used,
|
||||||
assert spool["location"] == location
|
"filament": random_filament,
|
||||||
assert spool["lot_nr"] == lot_nr
|
"remaining_weight": pytest.approx(random_filament["weight"] - used_weight),
|
||||||
assert spool["comment"] == comment
|
"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
|
# Clean up
|
||||||
httpx.delete(f"{URL}/api/v1/spool/{spool['id']}").raise_for_status()
|
httpx.delete(f"{URL}/api/v1/spool/{spool['id']}").raise_for_status()
|
||||||
|
|||||||
@@ -18,10 +18,34 @@ def test_add_vendor():
|
|||||||
|
|
||||||
# Verify
|
# Verify
|
||||||
vendor = result.json()
|
vendor = result.json()
|
||||||
assert vendor["name"] == name
|
assert vendor == {
|
||||||
assert vendor["comment"] == comment
|
"id": vendor["id"],
|
||||||
assert vendor["id"] is not None
|
"registered": vendor["registered"],
|
||||||
assert vendor["registered"] is not None
|
"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
|
# Clean up
|
||||||
httpx.delete(f"{URL}/api/v1/vendor/{vendor['id']}").raise_for_status()
|
httpx.delete(f"{URL}/api/v1/vendor/{vendor['id']}").raise_for_status()
|
||||||
|
|||||||
Reference in New Issue
Block a user