test: add manabox parser tests
This commit is contained in:
@@ -0,0 +1,76 @@
|
|||||||
|
"""
|
||||||
|
Tests for manabox.py — CSV parsing with foil/non-foil merging.
|
||||||
|
"""
|
||||||
|
import pytest
|
||||||
|
from app.services.imports.manabox import parse
|
||||||
|
|
||||||
|
|
||||||
|
class TestManaboxCSV:
|
||||||
|
def _csv(self, header, rows):
|
||||||
|
lines = [header] + rows
|
||||||
|
return "\n".join(lines).encode("utf-8")
|
||||||
|
|
||||||
|
def test_standard_columns(self):
|
||||||
|
data = self._csv(
|
||||||
|
"Name,Set code,Collector number,Foil,Quantity",
|
||||||
|
["Sol Ring,cmm,1,No,2"]
|
||||||
|
)
|
||||||
|
result = parse(data)
|
||||||
|
assert len(result) == 1
|
||||||
|
assert result[0].card_name == "Sol Ring"
|
||||||
|
assert result[0].quantity == 2
|
||||||
|
assert result[0].foil_quantity == 0
|
||||||
|
|
||||||
|
def test_foil_row(self):
|
||||||
|
data = self._csv(
|
||||||
|
"Name,Set code,Collector number,Foil,Quantity",
|
||||||
|
["Sol Ring,cmm,1,Yes,1"]
|
||||||
|
)
|
||||||
|
result = parse(data)
|
||||||
|
assert result[0].quantity == 0
|
||||||
|
assert result[0].foil_quantity == 1
|
||||||
|
|
||||||
|
def test_foil_and_nonfoil_merged(self):
|
||||||
|
data = self._csv(
|
||||||
|
"Name,Set code,Collector number,Foil,Quantity",
|
||||||
|
[
|
||||||
|
"Sol Ring,cmm,1,No,2",
|
||||||
|
"Sol Ring,cmm,1,Yes,1"
|
||||||
|
]
|
||||||
|
)
|
||||||
|
result = parse(data)
|
||||||
|
assert len(result) == 1
|
||||||
|
assert result[0].quantity == 2
|
||||||
|
assert result[0].foil_quantity == 1
|
||||||
|
|
||||||
|
def test_different_cards_not_merged(self):
|
||||||
|
data = self._csv(
|
||||||
|
"Name,Set code,Collector number,Foil,Quantity",
|
||||||
|
[
|
||||||
|
"Sol Ring,cmm,1,No,1",
|
||||||
|
"Command Tower,cmm,2,No,1"
|
||||||
|
]
|
||||||
|
)
|
||||||
|
result = parse(data)
|
||||||
|
assert len(result) == 2
|
||||||
|
|
||||||
|
def test_foil_bool_variations(self):
|
||||||
|
for foil_val in ["Yes", "yes", "1", "true", "True", "y"]:
|
||||||
|
data = self._csv(
|
||||||
|
"Name,Set code,Collector number,Foil,Quantity",
|
||||||
|
[f"Sol Ring,cmm,1,{foil_val},1"]
|
||||||
|
)
|
||||||
|
result = parse(data)
|
||||||
|
assert result[0].foil_quantity == 1, f"Failed for foil value: {foil_val}"
|
||||||
|
|
||||||
|
def test_empty_csv_raises(self):
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
parse(b"")
|
||||||
|
|
||||||
|
def test_set_code_lowercased(self):
|
||||||
|
data = self._csv(
|
||||||
|
"Name,Set code,Collector number,Foil,Quantity",
|
||||||
|
["Sol Ring,CMM,1,No,1"]
|
||||||
|
)
|
||||||
|
result = parse(data)
|
||||||
|
assert result[0].set_code == "cmm"
|
||||||
Reference in New Issue
Block a user