mirror of
https://github.com/almet/copanier.git
synced 2025-04-28 19:42:37 +02:00
Start fixing the tests.
This commit is contained in:
parent
c0e30927f7
commit
1039198a6d
3 changed files with 11 additions and 37 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -5,3 +5,4 @@ db/
|
|||
venv
|
||||
.env
|
||||
.vscode
|
||||
.pytest_cache
|
|
@ -423,9 +423,7 @@ hr {
|
|||
text-align: center;
|
||||
padding: 5px;
|
||||
}
|
||||
.carrelage li input {
|
||||
/*max-width: 80%;*/
|
||||
}
|
||||
|
||||
.carrelage li img {
|
||||
width: 50%;
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ def workbook():
|
|||
|
||||
def test_mandatory_headers_with_xlsx(delivery, workbook):
|
||||
with pytest.raises(ValueError):
|
||||
imports.products_from_xlsx(
|
||||
imports.products_and_producers_from_xlsx(
|
||||
delivery,
|
||||
workbook([("123", "Chocolat", "2.3")], headers=["ref", "nom", "prix"]),
|
||||
)
|
||||
|
@ -30,13 +30,15 @@ def test_mandatory_headers_with_xlsx(delivery, workbook):
|
|||
|
||||
def test_bad_xlsx_file(delivery, workbook):
|
||||
with pytest.raises(ValueError):
|
||||
imports.products_from_xlsx(delivery, BytesIO(b"pouet"))
|
||||
imports.products_and_producers_from_xlsx(delivery, BytesIO(b"pouet"))
|
||||
|
||||
|
||||
def test_simple_xlsx_import(delivery, workbook):
|
||||
delivery.persist()
|
||||
assert delivery.products == [Product(ref="123", name="Lait", price=1.5)]
|
||||
imports.products_from_xlsx(delivery, workbook([("123", "Lait cru", 1.3)]))
|
||||
imports.products_and_producers_from_xlsx(
|
||||
delivery, workbook([("123", "Lait cru", 1.3)])
|
||||
)
|
||||
assert Delivery.load(delivery.id).products == [
|
||||
Product(ref="123", name="Lait cru", price=1.3)
|
||||
]
|
||||
|
@ -46,36 +48,9 @@ def test_simple_xlsx_import_invalid_price(delivery, workbook):
|
|||
delivery.persist()
|
||||
assert delivery.products == [Product(ref="123", name="Lait", price=1.5)]
|
||||
with pytest.raises(ValueError):
|
||||
imports.products_from_xlsx(delivery, workbook([("123", "Lait cru", "invalid")]))
|
||||
assert Delivery.load(delivery.id).products == [
|
||||
Product(ref="123", name="Lait", price=1.5)
|
||||
]
|
||||
|
||||
|
||||
def test_mandatory_headers_with_csv(delivery):
|
||||
with pytest.raises(ValueError):
|
||||
imports.products_from_csv(delivery, "ref;nom;prix\n123;Chocolat;2.3")
|
||||
|
||||
|
||||
def test_bad_csv_file(delivery):
|
||||
with pytest.raises(ValueError):
|
||||
imports.products_from_csv(delivery, "pouet")
|
||||
|
||||
|
||||
def test_simple_csv_import(delivery):
|
||||
delivery.persist()
|
||||
assert delivery.products == [Product(ref="123", name="Lait", price=1.5)]
|
||||
imports.products_from_csv(delivery, "ref;name;price\n123;Lait cru;1.3")
|
||||
assert Delivery.load(delivery.id).products == [
|
||||
Product(ref="123", name="Lait cru", price=1.3)
|
||||
]
|
||||
|
||||
|
||||
def test_simple_csv_import_invalid_price(delivery):
|
||||
delivery.persist()
|
||||
assert delivery.products == [Product(ref="123", name="Lait", price=1.5)]
|
||||
with pytest.raises(ValueError):
|
||||
imports.products_from_csv(delivery, "ref;name;price\n123;Lait cru;invalid")
|
||||
imports.products_and_producers_from_xlsx(
|
||||
delivery, workbook([("123", "Lait cru", "invalid")])
|
||||
)
|
||||
assert Delivery.load(delivery.id).products == [
|
||||
Product(ref="123", name="Lait", price=1.5)
|
||||
]
|
||||
|
|
Loading…
Reference in a new issue