summaryrefslogtreecommitdiff
path: root/kicad_bom_cmd_test.py
diff options
context:
space:
mode:
Diffstat (limited to 'kicad_bom_cmd_test.py')
-rw-r--r--kicad_bom_cmd_test.py95
1 files changed, 95 insertions, 0 deletions
diff --git a/kicad_bom_cmd_test.py b/kicad_bom_cmd_test.py
new file mode 100644
index 0000000..93368a4
--- /dev/null
+++ b/kicad_bom_cmd_test.py
@@ -0,0 +1,95 @@
+import unittest
+from octopart import *
+from kicad_bom_cmd import *
+
+class TestBomOption(unittest.TestCase):
+
+ def _test_price(self):
+ s = 'hello world'
+ self.assertEqual(s.split(), ['hello', 'world'])
+ # check that s.split fails when the separator is not a string
+ with self.assertRaises(TypeError):
+ s.split(2)
+
+ def test_price(self):
+ part_offer = PartOffer(offer)
+ o = BomOption(Part(part), part_offer, part_offer.prices['NOK'])
+ self.assertEqual("49.22", "{0:.2f}".format(o.price_for_quantity(23)))
+
+import json
+
+part = json.loads('''{
+ "__class__": "Part",
+ "brand": {
+ "__class__": "Brand",
+ "homepage_url": "http://pewa.panasonic.com/",
+ "name": "Panasonic",
+ "uid": "bc357d3f904c6bf2"
+ },
+ "manufacturer": {
+ "__class__": "Manufacturer",
+ "homepage_url": "http://pewa.panasonic.com/",
+ "name": "Panasonic",
+ "uid": "0ccec9c424b7df09"
+ },
+ "mpn": "ERJP14F1001U",
+ "octopart_url": "http://octopart.com/erjp14f1001u-panasonic-11911978",
+ "offers": [ ],
+ "uid": "594990f6bf05868e"
+ }''')
+
+offer = json.loads('''{
+ "__class__": "PartOffer",
+ "_naive_id": "114db981bb037cd92e7082796607f6ba",
+ "eligible_region": "NO",
+ "factory_lead_days": null,
+ "factory_order_multiple": null,
+ "in_stock_quantity": 3448,
+ "is_authorized": true,
+ "is_realtime": false,
+ "last_updated": "2015-09-24T06:29:11Z",
+ "moq": 10,
+ "octopart_rfq_url": null,
+ "on_order_eta": null,
+ "on_order_quantity": null,
+ "order_multiple": null,
+ "packaging": "Cut Tape",
+ "prices": {
+ "NOK": [
+ [
+ 10,
+ "2.14000"
+ ],
+ [
+ 100,
+ "0.97700"
+ ],
+ [
+ 500,
+ "0.72700"
+ ],
+ [
+ 1000,
+ "0.57800"
+ ],
+ [
+ 5000,
+ "0.41100"
+ ]
+ ]
+ },
+ "product_url": "https://octopart-clicks.com/click/track?country=NO&ak=2452f140&sig=0d0964e&sid=819&ppid=11911978&vpid=146838441&ct=offers",
+ "seller": {
+ "__class__": "Seller",
+ "display_flag": "GB",
+ "has_ecommerce": true,
+ "homepage_url": "http://www.farnell.com/",
+ "id": "819",
+ "name": "Farnell",
+ "uid": "58989d9272cd8b5f"
+ },
+ "sku": "1750918RL"
+ }''')
+
+if __name__ == '__main__':
+ unittest.main()