Merged spool price testing into existing test methods

This commit is contained in:
pdsccode
2024-01-07 14:24:14 +01:00
parent 05dfb611cf
commit 28a70d5190
2 changed files with 6 additions and 44 deletions

View File

@@ -19,6 +19,7 @@ def test_add_spool_remaining_weight(random_filament: dict[str, Any]):
lot_nr = "123456789" lot_nr = "123456789"
comment = "abcdefghåäö" comment = "abcdefghåäö"
archived = True archived = True
price = 25
result = httpx.post( result = httpx.post(
f"{URL}/api/v1/spool", f"{URL}/api/v1/spool",
json={ json={
@@ -30,6 +31,7 @@ def test_add_spool_remaining_weight(random_filament: dict[str, Any]):
"lot_nr": lot_nr, "lot_nr": lot_nr,
"comment": comment, "comment": comment,
"archived": archived, "archived": archived,
"price": price,
}, },
) )
result.raise_for_status() result.raise_for_status()
@@ -62,6 +64,7 @@ def test_add_spool_remaining_weight(random_filament: dict[str, Any]):
"lot_nr": lot_nr, "lot_nr": lot_nr,
"comment": comment, "comment": comment,
"archived": archived, "archived": archived,
"price": price,
} }
# Verify that registered happened almost now (within 1 minute) # Verify that registered happened almost now (within 1 minute)
@@ -185,16 +188,3 @@ def test_add_spool_both_used_and_remaining_weight(random_filament: dict[str, Any
}, },
) )
assert result.status_code == 400 # Cannot set both used and remaining weight assert result.status_code == 400 # Cannot set both used and remaining weight
def test_add_spool_price(random_filament: dict[str, Any]):
"""Test adding a spool to the database."""
# Execute
result = httpx.post(
f"{URL}/api/v1/spool",
json={
"filament_id": random_filament["id"],
"price": 25,
},
)
assert result.status_code == 400 # Cannot set price

View File

@@ -33,6 +33,7 @@ def test_update_spool(random_filament: dict[str, Any]):
lot_nr = "987654321" lot_nr = "987654321"
comment = "abcdefghåäö" comment = "abcdefghåäö"
archived = True archived = True
price = 25
result = httpx.patch( result = httpx.patch(
f"{URL}/api/v1/spool/{spool['id']}", f"{URL}/api/v1/spool/{spool['id']}",
json={ json={
@@ -43,6 +44,7 @@ def test_update_spool(random_filament: dict[str, Any]):
"lot_nr": lot_nr, "lot_nr": lot_nr,
"comment": comment, "comment": comment,
"archived": archived, "archived": archived,
"price": price,
}, },
) )
result.raise_for_status() result.raise_for_status()
@@ -71,6 +73,7 @@ def test_update_spool(random_filament: dict[str, Any]):
assert spool["lot_nr"] == lot_nr assert spool["lot_nr"] == lot_nr
assert spool["comment"] == comment assert spool["comment"] == comment
assert spool["archived"] == archived assert spool["archived"] == archived
assert spool["price"] == price
# 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()
@@ -100,37 +103,6 @@ def test_update_spool_both_used_and_remaining_weight(random_filament: dict[str,
httpx.delete(f"{URL}/api/v1/spool/{spool['id']}").raise_for_status() httpx.delete(f"{URL}/api/v1/spool/{spool['id']}").raise_for_status()
def test_update_spool_price(random_filament: dict[str, Any]):
"""Test updating a spool in the database."""
# Setup
result = httpx.post(
f"{URL}/api/v1/spool",
json={
"filament_id": random_filament["id"],
"price": 50,
},
)
result.raise_for_status()
spool = result.json()
# Execute
price = 25
result = httpx.patch(
f"{URL}/api/v1/spool/{spool['id']}",
json={
"price": price,
},
)
result.raise_for_status()
# Verify
spool = result.json()
assert spool["price"] == 25
# Clean up
httpx.delete(f"{URL}/api/v1/spool/{spool['id']}").raise_for_status()
def test_update_spool_not_found(random_filament: dict[str, Any]): def test_update_spool_not_found(random_filament: dict[str, Any]):
"""Test updating a spool that does not exist.""" """Test updating a spool that does not exist."""
# Execute # Execute