Changed initial_weight to be net weight, not gross weight
This commit is contained in:
@@ -201,7 +201,7 @@ def test_add_spool_initial_weight(random_filament: dict[str, Any]):
|
||||
"""Test adding a spool to the database."""
|
||||
# Execute
|
||||
remaining_weight = 750
|
||||
initial_weight = 1245
|
||||
initial_weight = 1010
|
||||
location = "The Pantry"
|
||||
lot_nr = "123456789"
|
||||
comment = "abcdefghåäö"
|
||||
@@ -225,7 +225,7 @@ def test_add_spool_initial_weight(random_filament: dict[str, Any]):
|
||||
result.raise_for_status()
|
||||
|
||||
# Verify
|
||||
used_weight = initial_weight - random_filament["spool_weight"] - remaining_weight
|
||||
used_weight = initial_weight - remaining_weight
|
||||
used_length = length_from_weight(
|
||||
weight=used_weight,
|
||||
density=random_filament["density"],
|
||||
@@ -247,7 +247,7 @@ def test_add_spool_initial_weight(random_filament: dict[str, Any]):
|
||||
"last_used": "2023-01-02T11:00:00Z",
|
||||
"filament": random_filament,
|
||||
"initial_weight": pytest.approx(initial_weight),
|
||||
"empty_weight": pytest.approx(random_filament["spool_weight"]),
|
||||
"spool_weight": pytest.approx(random_filament["spool_weight"]),
|
||||
"remaining_weight": pytest.approx(remaining_weight),
|
||||
"used_weight": pytest.approx(used_weight),
|
||||
"remaining_length": pytest.approx(remaining_length),
|
||||
@@ -268,11 +268,11 @@ def test_add_spool_initial_weight(random_filament: dict[str, Any]):
|
||||
httpx.delete(f"{URL}/api/v1/spool/{spool['id']}").raise_for_status()
|
||||
|
||||
|
||||
def test_add_spool_empty_weight(random_filament: dict[str, Any]):
|
||||
def test_add_spool_spool_weight(random_filament: dict[str, Any]):
|
||||
"""Test adding a spool to the database."""
|
||||
# Execute
|
||||
remaining_weight = 750
|
||||
empty_weight = 200
|
||||
spool_weight = 200
|
||||
location = "The Pantry"
|
||||
lot_nr = "123456789"
|
||||
comment = "abcdefghåäö"
|
||||
@@ -285,7 +285,7 @@ def test_add_spool_empty_weight(random_filament: dict[str, Any]):
|
||||
"last_used": "2023-01-02T11:00:00Z",
|
||||
"filament_id": random_filament["id"],
|
||||
"remaining_weight": remaining_weight,
|
||||
"empty_weight": empty_weight,
|
||||
"spool_weight": spool_weight,
|
||||
"location": location,
|
||||
"lot_nr": lot_nr,
|
||||
"comment": comment,
|
||||
@@ -317,8 +317,8 @@ def test_add_spool_empty_weight(random_filament: dict[str, Any]):
|
||||
"first_used": "2023-01-02T11:00:00Z",
|
||||
"last_used": "2023-01-02T11:00:00Z",
|
||||
"filament": random_filament,
|
||||
"initial_weight": pytest.approx(random_filament["weight"] + empty_weight),
|
||||
"empty_weight": pytest.approx(empty_weight),
|
||||
"initial_weight": pytest.approx(random_filament["weight"]),
|
||||
"spool_weight": pytest.approx(spool_weight),
|
||||
"remaining_weight": pytest.approx(remaining_weight),
|
||||
"used_weight": pytest.approx(used_weight),
|
||||
"remaining_length": pytest.approx(remaining_length),
|
||||
|
||||
@@ -83,8 +83,8 @@ def test_get_spool_default_weights(random_filament: dict[str, Any]):
|
||||
|
||||
# Verify
|
||||
assert result_spool == spool
|
||||
assert result_spool["initial_weight"] == pytest.approx(random_filament["weight"] + random_filament["spool_weight"])
|
||||
assert result_spool["empty_weight"] == pytest.approx(random_filament["spool_weight"])
|
||||
assert result_spool["initial_weight"] == pytest.approx(random_filament["weight"])
|
||||
assert result_spool["spool_weight"] == pytest.approx(random_filament["spool_weight"])
|
||||
|
||||
# Clean up
|
||||
httpx.delete(f"{URL}/api/v1/spool/{spool['id']}").raise_for_status()
|
||||
@@ -97,7 +97,7 @@ def test_get_spool_weights(random_filament: dict[str, Any]):
|
||||
last_used = "2023-01-02T00:00:00"
|
||||
remaining_weight = 750
|
||||
initial_weight = 1255
|
||||
empty_weight = 246
|
||||
spool_weight = 246
|
||||
location = "The Pantry"
|
||||
lot_nr = "123456789"
|
||||
comment = "abcdefghåäö"
|
||||
@@ -111,7 +111,7 @@ def test_get_spool_weights(random_filament: dict[str, Any]):
|
||||
"filament_id": random_filament["id"],
|
||||
"remaining_weight": remaining_weight,
|
||||
"initial_weight": initial_weight,
|
||||
"empty_weight": empty_weight,
|
||||
"spool_weight": spool_weight,
|
||||
"location": location,
|
||||
"lot_nr": lot_nr,
|
||||
"comment": comment,
|
||||
|
||||
@@ -9,21 +9,20 @@ import pytest
|
||||
from ..conftest import URL
|
||||
|
||||
|
||||
@pytest.mark.parametrize("measurement", [0, 0.05, -0.05, 1000])
|
||||
@pytest.mark.parametrize("measurement", [246, 500, 600, 1000])
|
||||
def test_measure_spool(random_filament: dict[str, Any], measurement: float):
|
||||
"""Test using a spool in the database."""
|
||||
# Setup
|
||||
random_filament["weight"]
|
||||
initial_weight = 1255
|
||||
empty_weight = 246
|
||||
spool_weight = 246
|
||||
start_weight = 1000
|
||||
result = httpx.post(
|
||||
f"{URL}/api/v1/spool",
|
||||
json={
|
||||
"filament_id": random_filament["id"],
|
||||
"remaining_weight": start_weight,
|
||||
"initial_weight": initial_weight,
|
||||
"empty_weight": empty_weight,
|
||||
"initial_weight": start_weight,
|
||||
"spool_weight": spool_weight,
|
||||
},
|
||||
)
|
||||
result.raise_for_status()
|
||||
@@ -41,9 +40,9 @@ def test_measure_spool(random_filament: dict[str, Any], measurement: float):
|
||||
# Verify
|
||||
spool = result.json()
|
||||
# remaining_weight should be clamped so it's never negative, but used_weight should not be clamped to the net weight
|
||||
expected_use = min(initial_weight - measurement, initial_weight - empty_weight)
|
||||
expected_use = min(start_weight - (measurement - spool_weight), start_weight)
|
||||
assert spool["used_weight"] == pytest.approx(expected_use)
|
||||
expected_remaining = max(measurement - empty_weight, 0)
|
||||
expected_remaining = max(measurement - spool_weight, 0)
|
||||
assert spool["remaining_weight"] == pytest.approx(expected_remaining)
|
||||
# Verify that first_used has been updated
|
||||
diff = abs((datetime.now(tz=timezone.utc) - datetime.fromisoformat(spool["first_used"])).total_seconds())
|
||||
@@ -62,16 +61,15 @@ def test_measure_spool_invalid(random_filament: dict[str, Any], measurement: flo
|
||||
"""Test using a spool in the database."""
|
||||
# Setup
|
||||
random_filament["weight"]
|
||||
initial_weight = 1255
|
||||
empty_weight = 246
|
||||
spool_weight = 246
|
||||
start_weight = 1000
|
||||
result = httpx.post(
|
||||
f"{URL}/api/v1/spool",
|
||||
json={
|
||||
"filament_id": random_filament["id"],
|
||||
"remaining_weight": start_weight,
|
||||
"initial_weight": initial_weight,
|
||||
"empty_weight": empty_weight,
|
||||
"initial_weight": start_weight,
|
||||
"spool_weight": spool_weight,
|
||||
},
|
||||
)
|
||||
result.raise_for_status()
|
||||
@@ -96,17 +94,17 @@ def test_measure_spool_sequence(random_filament: dict[str, Any], measurements: l
|
||||
"""Test using a spool in the database."""
|
||||
# Setup
|
||||
random_filament["weight"]
|
||||
initial_weight = 1255
|
||||
spool_weight = 246
|
||||
start_weight = 1009
|
||||
initial_weight = start_weight + spool_weight
|
||||
current_weight = initial_weight
|
||||
empty_weight = 246
|
||||
start_weight = 1000
|
||||
result = httpx.post(
|
||||
f"{URL}/api/v1/spool",
|
||||
json={
|
||||
"filament_id": random_filament["id"],
|
||||
"remaining_weight": start_weight,
|
||||
"initial_weight": initial_weight,
|
||||
"empty_weight": empty_weight,
|
||||
"initial_weight": start_weight,
|
||||
"spool_weight": spool_weight,
|
||||
},
|
||||
)
|
||||
result.raise_for_status()
|
||||
@@ -126,9 +124,9 @@ def test_measure_spool_sequence(random_filament: dict[str, Any], measurements: l
|
||||
spool = result.json()
|
||||
# remaining_weight should be clamped so it's never negative,
|
||||
# but used_weight should not be clamped to the net weight
|
||||
expected_use = min(initial_weight - m, initial_weight - empty_weight)
|
||||
expected_use = min(initial_weight - m, initial_weight - spool_weight)
|
||||
assert spool["used_weight"] == pytest.approx(expected_use)
|
||||
expected_remaining = max(m - empty_weight, 0)
|
||||
expected_remaining = max(m - spool_weight, 0)
|
||||
assert spool["remaining_weight"] == pytest.approx(expected_remaining)
|
||||
# Verify that first_used has been updated
|
||||
diff = abs((datetime.now(tz=timezone.utc) - datetime.fromisoformat(spool["first_used"])).total_seconds())
|
||||
@@ -148,17 +146,17 @@ def test_measure_spool_sequence(random_filament: dict[str, Any], measurements: l
|
||||
def test_measure_spool_empty(random_empty_filament: dict[str, Any], measurements: list[float]):
|
||||
"""Test using a spool in the database."""
|
||||
# Setup
|
||||
initial_weight = 1255
|
||||
current_weight = initial_weight
|
||||
empty_weight = 246
|
||||
spool_weight = 246
|
||||
start_weight = 1000
|
||||
initial_weight = start_weight + spool_weight
|
||||
current_weight = initial_weight
|
||||
result = httpx.post(
|
||||
f"{URL}/api/v1/spool",
|
||||
json={
|
||||
"filament_id": random_empty_filament["id"],
|
||||
"remaining_weight": start_weight,
|
||||
"initial_weight": initial_weight,
|
||||
"empty_weight": empty_weight,
|
||||
"initial_weight": start_weight,
|
||||
"spool_weight": spool_weight,
|
||||
},
|
||||
)
|
||||
result.raise_for_status()
|
||||
@@ -178,9 +176,9 @@ def test_measure_spool_empty(random_empty_filament: dict[str, Any], measurements
|
||||
spool = result.json()
|
||||
# remaining_weight should be clamped so it's never negative,
|
||||
# but used_weight should not be clamped to the net weight
|
||||
expected_use = min(initial_weight - m, initial_weight - empty_weight)
|
||||
expected_use = min(initial_weight - m, initial_weight - spool_weight)
|
||||
assert spool["used_weight"] == pytest.approx(expected_use)
|
||||
expected_remaining = max(m - empty_weight, 0)
|
||||
expected_remaining = max(m - spool_weight, 0)
|
||||
assert spool["remaining_weight"] == pytest.approx(expected_remaining)
|
||||
# Verify that first_used has been updated
|
||||
diff = abs((datetime.now(tz=timezone.utc) - datetime.fromisoformat(spool["first_used"])).total_seconds())
|
||||
|
||||
@@ -86,7 +86,7 @@ def test_update_spool_weights(random_filament: dict[str, Any]):
|
||||
"filament_id": random_filament["id"],
|
||||
"remaining_weight": 1000,
|
||||
"initial_weight": 1255,
|
||||
"empty_weight": 246,
|
||||
"spool_weight": 246,
|
||||
"location": "The Pantry",
|
||||
"lot_nr": "123456789",
|
||||
},
|
||||
@@ -98,8 +98,8 @@ def test_update_spool_weights(random_filament: dict[str, Any]):
|
||||
first_used = "2023-01-01T12:00:00+02:00"
|
||||
last_used = "2023-01-02T12:00:00+02:00"
|
||||
remaining_weight = 750
|
||||
initial_weight = 1250
|
||||
empty_weight = 245
|
||||
initial_weight = 1005
|
||||
spool_weight = 245
|
||||
location = "Living Room"
|
||||
lot_nr = "987654321"
|
||||
comment = "abcdefghåäö"
|
||||
@@ -117,13 +117,13 @@ def test_update_spool_weights(random_filament: dict[str, Any]):
|
||||
"archived": archived,
|
||||
"price": price,
|
||||
"initial_weight": initial_weight,
|
||||
"empty_weight": empty_weight,
|
||||
"spool_weight": spool_weight,
|
||||
},
|
||||
)
|
||||
result.raise_for_status()
|
||||
|
||||
# Verify
|
||||
used_weight = initial_weight - empty_weight - remaining_weight
|
||||
used_weight = initial_weight - remaining_weight
|
||||
used_length = length_from_weight(
|
||||
weight=used_weight,
|
||||
density=random_filament["density"],
|
||||
@@ -139,7 +139,7 @@ def test_update_spool_weights(random_filament: dict[str, Any]):
|
||||
assert spool["first_used"] == "2023-01-01T10:00:00Z"
|
||||
assert spool["last_used"] == "2023-01-02T10:00:00Z"
|
||||
assert spool["initial_weight"] == pytest.approx(initial_weight)
|
||||
assert spool["empty_weight"] == pytest.approx(empty_weight)
|
||||
assert spool["spool_weight"] == pytest.approx(spool_weight)
|
||||
assert spool["remaining_weight"] == pytest.approx(remaining_weight)
|
||||
assert spool["used_weight"] == pytest.approx(used_weight)
|
||||
assert spool["remaining_length"] == pytest.approx(remaining_length)
|
||||
|
||||
Reference in New Issue
Block a user