Revert "Fixed test error that asserts 404 on create"
This reverts commit f13c61b9e9.
This commit is contained in:
@@ -187,65 +187,14 @@ 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_with_price(random_filament: dict[str, Any]):
|
def test_add_spool_price(random_filament: dict[str, Any]):
|
||||||
"""Test adding a spool to the database."""
|
"""Test adding a spool to the database."""
|
||||||
# Execute
|
# Execute
|
||||||
remaining_weight = 750
|
|
||||||
location = "The Pantry"
|
|
||||||
lot_nr = "123456789"
|
|
||||||
comment = "abcdefghåäö"
|
|
||||||
archived = True
|
|
||||||
price = 25
|
|
||||||
result = httpx.post(
|
result = httpx.post(
|
||||||
f"{URL}/api/v1/spool",
|
f"{URL}/api/v1/spool",
|
||||||
json={
|
json={
|
||||||
"first_used": "2023-01-02T12:00:00+01:00",
|
|
||||||
"last_used": "2023-01-02T11:00:00Z",
|
|
||||||
"filament_id": random_filament["id"],
|
"filament_id": random_filament["id"],
|
||||||
"remaining_weight": remaining_weight,
|
"price": 25,
|
||||||
"location": location,
|
|
||||||
"lot_nr": lot_nr,
|
|
||||||
"comment": comment,
|
|
||||||
"archived": archived,
|
|
||||||
"price": price,
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
result.raise_for_status()
|
assert result.status_code == 400 # Cannot set price
|
||||||
|
|
||||||
# Verify
|
|
||||||
used_weight = random_filament["weight"] - remaining_weight
|
|
||||||
used_length = length_from_weight(
|
|
||||||
weight=used_weight,
|
|
||||||
density=random_filament["density"],
|
|
||||||
diameter=random_filament["diameter"],
|
|
||||||
)
|
|
||||||
remaining_length = length_from_weight(
|
|
||||||
weight=remaining_weight,
|
|
||||||
density=random_filament["density"],
|
|
||||||
diameter=random_filament["diameter"],
|
|
||||||
)
|
|
||||||
|
|
||||||
spool = result.json()
|
|
||||||
assert spool == {
|
|
||||||
"id": spool["id"],
|
|
||||||
"registered": spool["registered"],
|
|
||||||
"first_used": "2023-01-02T11:00:00Z",
|
|
||||||
"last_used": "2023-01-02T11:00:00Z",
|
|
||||||
"filament": random_filament,
|
|
||||||
"remaining_weight": pytest.approx(remaining_weight),
|
|
||||||
"used_weight": pytest.approx(used_weight),
|
|
||||||
"remaining_length": pytest.approx(remaining_length),
|
|
||||||
"used_length": pytest.approx(used_length),
|
|
||||||
"location": location,
|
|
||||||
"lot_nr": lot_nr,
|
|
||||||
"comment": comment,
|
|
||||||
"archived": archived,
|
|
||||||
"price": price,
|
|
||||||
}
|
|
||||||
|
|
||||||
# Verify that registered happened almost now (within 1 minute)
|
|
||||||
diff = abs((datetime.now(tz=timezone.utc) - datetime.fromisoformat(spool["registered"])).total_seconds())
|
|
||||||
assert diff < 60
|
|
||||||
|
|
||||||
# Clean up
|
|
||||||
httpx.delete(f"{URL}/api/v1/spool/{spool['id']}").raise_for_status()
|
|
||||||
|
|||||||
Reference in New Issue
Block a user