Skip to content

Commit

Permalink
WireViz 0.3: Adjust BOM API and output
Browse files Browse the repository at this point in the history
1. The `bom_list()` function has to be used explicitly
2. The output gained another column "Id"
3. The output column "Item" was renamed to "Description"
4. Output items apparently get sorted now, so "Cable" goes first
  • Loading branch information
amotl committed Oct 22, 2021
1 parent 49cc0c8 commit e36587a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
22 changes: 12 additions & 10 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,13 @@ def test_bom_text(self, client):
assert response.status_code == 200
assert response.headers["Content-Type"] == "text/plain; charset=utf-8"
assert response.headers["Content-Disposition"] == "attachment; filename=test.bom.txt"
assert (
response.data == b"Item\tQty\tUnit\tDesignators\n"
b"Connector, D-Sub, female, 9 pins\t1\t\tX1\n"
b"Connector, Molex KK 254, female, 3 pins\t1\t\tX2\n"
b"Cable, 3 x 0.25 mm\xc2\xb2 shielded\t0.2\tm\tW1\n"
reference = (
b"Id\tDescription\tQty\tUnit\tDesignators\n"
b"1\tCable, 3 x 0.25 mm\xc2\xb2 shielded\t0.2\tm\tW1\n"
b"2\tConnector, D-Sub, female, 9 pins\t1\t\tX1\n"
b"3\tConnector, Molex KK 254, female, 3 pins\t1\t\tX2\n"
)
assert reference == response.data

def test_bom_json(self, client):
response = client.post(
Expand All @@ -97,12 +98,13 @@ def test_bom_json(self, client):
assert response.status_code == 200
assert response.headers["Content-Type"] == "application/json"
assert response.headers["Content-Disposition"] == "attachment; filename=test.bom.json"
assert response.json == [
["Item", "Qty", "Unit", "Designators"],
["Connector, D-Sub, female, 9 pins", 1, "", "X1"],
["Connector, Molex KK 254, female, 3 pins", 1, "", "X2"],
["Cable, 3 x 0.25 mm² shielded", 0.2, "m", "W1"],
reference = [
["Id", "Description", "Qty", "Unit", "Designators"],
["1", "Cable, 3 x 0.25 mm² shielded", "0.2", "m", "W1"],
["2", "Connector, D-Sub, female, 9 pins", "1", "", "X1"],
["3", "Connector, Molex KK 254, female, 3 pins", "1", "", "X2"],
]
assert reference == response.json

def test_error_no_accept(self, client):
response = client.post(
Expand Down
9 changes: 5 additions & 4 deletions wireviz_web/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from werkzeug.exceptions import BadRequest, NotAcceptable
from wireviz import wireviz
from wireviz.Harness import Harness
from wireviz.wv_bom import bom_list
from wireviz.wv_helper import tuplelist2tsv

from wireviz_web.plantuml import plantuml_decode
Expand Down Expand Up @@ -157,13 +158,13 @@ def wireviz_render(input_yaml: str, output_mimetype: str, output_filename: str)

elif return_type == "bom.txt":
harness.create_graph()
bom_list = harness.bom_list()
payload = tuplelist2tsv(bom_list).encode("utf-8")
bomlist = bom_list(harness.bom())
payload = tuplelist2tsv(bomlist).encode("utf-8")

elif return_type == "bom.json":
harness.create_graph()
bom_list = harness.bom_list()
payload = json.dumps(bom_list, indent=2).encode("utf-8")
bomlist = bom_list(harness.bom())
payload = json.dumps(bomlist, indent=2).encode("utf-8")

# Respond with rendered image.
return send_file(
Expand Down

0 comments on commit e36587a

Please sign in to comment.