From 6b0796378382d2ebeb016d11942a2e6f8584a583 Mon Sep 17 00:00:00 2001 From: Viggo de Vries Date: Fri, 15 Dec 2023 14:57:11 +0100 Subject: [PATCH] Add reallife testcase --- Makefile | 2 +- .../fixtures/oscar_odin/csv/products.csv | 60 ++++++ oscar_odin/mappings/context.py | 8 - oscar_odin/resources/catalogue.py | 1 + tests/reverse/test_reallifecase.py | 203 ++++++++++++++++++ 5 files changed, 265 insertions(+), 9 deletions(-) create mode 100644 oscar_odin/fixtures/oscar_odin/csv/products.csv create mode 100644 tests/reverse/test_reallifecase.py diff --git a/Makefile b/Makefile index a67d517..88d570e 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ lint: fail-if-no-virtualenv pylint oscar_odin/ test: fail-if-no-virtualenv - python3 runtests.py test tests/ + python3 runtests.py test tests.reverse.test_reallifecase black: @black oscar_odin/ diff --git a/oscar_odin/fixtures/oscar_odin/csv/products.csv b/oscar_odin/fixtures/oscar_odin/csv/products.csv new file mode 100644 index 0000000..531f282 --- /dev/null +++ b/oscar_odin/fixtures/oscar_odin/csv/products.csv @@ -0,0 +1,60 @@ +id,name,category_id,weight,weight_type,price,weight_price,image,app_image,description,EAN,number,VAT,supplier_id,active,anonymous,quantity,unit,admin_approved,is_new_introduction,tags,brand_id,stock_manager,is_deleted,is_weightedproduct,storage_type,psinfood_id,package_ean,warehouse_id,assortmentclass,package,package_quantity,package_unit,Supplier,WareHouse,ProductInvitations +19860,RAW CAKES VANILLE,101,1,kilo,41.85,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1698660334306_449650113_e2%20(Middel).jpg?alt=media&token=f51d26f5-18f6-46b5-bd12-a68d4a15fcc0,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1698660334306_449650113_e2%20(Middel).jpg?alt=media&token=f51d26f5-18f6-46b5-bd12-a68d4a15fcc0,,5407005642115,,9,1049,true,,,doos,true,,,,,,,frozen,,,2,franchise,,,,[object Object],[object Object], +19823,MACARON PEACH-MANGO 50ST,213,1,kilo,49.5,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1696026421065_825167321_PEACH%20MANGO.png?alt=media&token=0a318299-bfe6-425b-83c5-4516eeee7cac,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1696026421065_825167321_PEACH%20MANGO.png?alt=media&token=0a318299-bfe6-425b-83c5-4516eeee7cac,,2100140000002,111111,9,1052,true,,,doos,true,,,,,,,frozen,,,2,normal,,,,[object Object],[object Object],[object Object] +19806,White Chocolate Tray Brownie Pre-Cut(6x6),213,1,kilo,28.11,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1695375582459_129911926_t%2010.57.14.jpeg?alt=media&token=9d22dd54-48eb-403c-b006-8311eb5bbe6f,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1695375582459_129911926_t%2010.57.14.jpeg?alt=media&token=9d22dd54-48eb-403c-b006-8311eb5bbe6f,,8683880757695,BR9021,9,1053,true,,,stuk,true,,,,,,,frozen,,,2,franchise,,,,[object Object],[object Object], +19805,Hazelnut Tray Brownie Pre-Cut(6x6),213,1,kilo,24.64,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1695370950969_911725953_.10.52%20(5).jpeg?alt=media&token=d35cd705-9242-484d-b900-151530166457,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1695370950969_911725953_.10.52%20(5).jpeg?alt=media&token=d35cd705-9242-484d-b900-151530166457,,8683880757657,BRTP0008,9,1053,true,,,stuk,true,,,,,,,frozen,,,2,franchise,,,,[object Object],[object Object], +19804,Orange Tray Brownie Pre-Cut(6x6),213,1,kilo,21.45,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1695370852426_965127482_.10.51%20(1).jpeg?alt=media&token=a2a16af9-1e0f-4f23-b892-adc5660dfd4b,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1695370852426_965127482_.10.51%20(1).jpeg?alt=media&token=a2a16af9-1e0f-4f23-b892-adc5660dfd4b,,8683880757558,BRTP0004,9,1053,true,,,stuk,true,,,,,,,frozen,,,2,franchise,,,,[object Object],[object Object], +19803,Lemon Tray Brownie Pre-Cut(6x6),213,1,kilo,21.45,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1695370710042_594397468_.16.35%20(1).jpeg?alt=media&token=956723d3-bf17-443a-bf00-8d8509ace496,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1695370710042_594397468_.16.35%20(1).jpeg?alt=media&token=956723d3-bf17-443a-bf00-8d8509ace496,,8683880757619,BRTP0013,9,1053,true,,,stuk,true,,,,,,,frozen,,,2,franchise,,,,[object Object],[object Object], +19802,Classic Tray Brownie Pre-Cut(6x6),213,1,kilo,19.91,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1695370573220_373873097_.10.52%20(8).jpeg?alt=media&token=192bbbb5-ac35-4405-85c9-882b0cedc1c7,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1695370573220_373873097_.10.52%20(8).jpeg?alt=media&token=192bbbb5-ac35-4405-85c9-882b0cedc1c7,,8683752709159,BR9026,9,1053,true,,,stuk,true,,,,,,,frozen,,,2,franchise,,,,[object Object],[object Object], +19801,Peanut Butter Tray Brownie Pre-Cut(6x6),213,1,kilo,24.64,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1695370198571_331792047_.10.52%20(1).jpeg?alt=media&token=4c09970c-724d-4d35-b9ba-75d6d2260078,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1695370198571_331792047_.10.52%20(1).jpeg?alt=media&token=4c09970c-724d-4d35-b9ba-75d6d2260078,,8683880757534,BR9020,9,1053,true,,,stuk,true,,,,,,,frozen,,,2,franchise,,,,[object Object],[object Object], +18835,MACARON VANILLE 50ST,213,1,doos,49.5,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688642229370_393196562_Vanilla.jpg?alt=media&token=c52947a4-f9fa-42a6-ae1b-3751d1e70f90,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688642229370_393196562_Vanilla.jpg?alt=media&token=c52947a4-f9fa-42a6-ae1b-3751d1e70f90,,2100030000006,391735,9,1052,true,,,doos,true,,,,0,,,frozen,,NaN,2,normal,,,,[object Object],[object Object],[object Object] +18834,MACARON TIRAMISU 50ST,213,1,doos,49.5,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688642221134_852498327_Tiramisu.jpg?alt=media&token=25ba641d-b735-4f0c-8918-8efe2c3c5c7e,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688642221134_852498327_Tiramisu.jpg?alt=media&token=25ba641d-b735-4f0c-8918-8efe2c3c5c7e,,2100200000003,391794,9,1052,true,,,doos,true,,,,0,,,frozen,,NaN,2,normal,,,,[object Object],[object Object],[object Object] +18833,MACARON STRAWBERRY 50ST,213,1,doos,49.5,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688642212528_73755141_Strawberry.jpg?alt=media&token=65fe8350-e2b3-410b-afe4-bf4c3e79968a,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688642212528_73755141_Strawberry.jpg?alt=media&token=65fe8350-e2b3-410b-afe4-bf4c3e79968a,,2100120000008,391875,9,1052,true,,,doos,true,,,,0,,,frozen,,NaN,2,normal,,,,[object Object],[object Object],[object Object] +18832,MACARON SPECULOOS 50ST,213,1,doos,49.5,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688642202084_244631676_Speculoos.jpg?alt=media&token=13e85485-48ed-40fd-95ee-cac8c2f0a71d,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688642202084_244631676_Speculoos.jpg?alt=media&token=13e85485-48ed-40fd-95ee-cac8c2f0a71d,,2100210000000,391840,9,1052,true,,,doos,true,,,,0,,,frozen,,NaN,2,normal,,,,[object Object],[object Object],[object Object] +18831,MACARON REDVELVET 50ST,213,1,doos,49.5,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688642190061_570396783_Red%20Velvet.jpg?alt=media&token=bae77b87-d6ac-4a88-aa97-a24c96b94f4c,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688642190061_570396783_Red%20Velvet.jpg?alt=media&token=bae77b87-d6ac-4a88-aa97-a24c96b94f4c,,2100180000000,391743,9,1052,true,,,doos,true,,,,0,,,frozen,,NaN,2,normal,,,,[object Object],[object Object],[object Object] +18830,MACARON RASPBERRY 50ST,213,1,doos,49.5,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688642180800_193302737_Raspberry.jpg?alt=media&token=1d1c2463-e267-44f0-85be-f1d1011bff47,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688642180800_193302737_Raspberry.jpg?alt=media&token=1d1c2463-e267-44f0-85be-f1d1011bff47,,2100170000003,391891,9,1052,true,,,doos,true,,,,0,,,frozen,,NaN,2,normal,,,,[object Object],[object Object],[object Object] +18829,MACARON PISTACHIO 50ST,213,1,doos,49.5,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688642169437_570501660_Pistachio%20Nuts.jpg?alt=media&token=97b60c04-7c25-4363-bcaa-340f21f1f538,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688642169437_570501660_Pistachio%20Nuts.jpg?alt=media&token=97b60c04-7c25-4363-bcaa-340f21f1f538,,2100040000003,391808,9,1052,true,,,doos,true,,,,0,,,frozen,,NaN,2,normal,,,,[object Object],[object Object],[object Object] +18828,MACARON PEANUT BUTTER 50ST,213,1,doos,49.5,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688642245865_516395100_Peanut%20Buttercup.jpg?alt=media&token=e840b802-3b43-49a3-83cf-e78cc67562b0,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688642245865_516395100_Peanut%20Buttercup.jpg?alt=media&token=e840b802-3b43-49a3-83cf-e78cc67562b0,,2100220000007,391883,9,1052,true,,,doos,true,,,,0,,,frozen,,NaN,2,normal,,,,[object Object],[object Object],[object Object] +18827,MACARON PASSION FRUIT 50ST,213,1,doos,49.5,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688642155707_910558237_Passion%20Fruit.jpg?alt=media&token=a1fb1def-b769-4f54-97db-e125c0a2fbe9,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688642155707_910558237_Passion%20Fruit.jpg?alt=media&token=a1fb1def-b769-4f54-97db-e125c0a2fbe9,,2100160000006,391956,9,1052,true,,,doos,true,,,,0,,,frozen,,NaN,2,normal,,,,[object Object],[object Object],[object Object] +18826,MACARON OREO 50ST,213,1,doos,49.5,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688642062663_588874497_eo%20High%20Res.jpg?alt=media&token=96d29888-e8c9-4957-a407-e3b2adb7c95e,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688642062663_588874497_eo%20High%20Res.jpg?alt=media&token=96d29888-e8c9-4957-a407-e3b2adb7c95e,,2100240000001,399981,9,1052,true,,,doos,true,,,,0,,,frozen,,NaN,2,normal,,,,[object Object],[object Object],[object Object] +18825,MACARON LEMON 50ST,213,1,doos,49.5,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688642050668_449052725_Lemon.jpg?alt=media&token=1ce2d574-ae7c-4161-a443-25a4bdcd457c,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688642050668_449052725_Lemon.jpg?alt=media&token=1ce2d574-ae7c-4161-a443-25a4bdcd457c,,2100110000001,391867,9,1052,true,,,doos,true,,,,0,,,frozen,,NaN,2,normal,,,,[object Object],[object Object],[object Object] +18824,MACARON ITALIAN COOKIE 50ST,213,1,doos,49.5,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688642039711_303946959_Italian%20Cookie.jpg?alt=media&token=f3c9dcc2-f363-4289-ae59-8ebd7f7124c4,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688642039711_303946959_Italian%20Cookie.jpg?alt=media&token=f3c9dcc2-f363-4289-ae59-8ebd7f7124c4,,2100190000007,391905,9,1052,true,,,doos,true,,,,0,,,frozen,,NaN,2,normal,,,,[object Object],[object Object],[object Object] +18823,MACARON HAZELNUT NUTELLA 50ST,213,1,doos,49.5,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688642002722_466408713_ut%20%20Nutella.jpg?alt=media&token=b807df54-86f0-44df-a739-e7db386cf0cb,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688642002722_466408713_ut%20%20Nutella.jpg?alt=media&token=b807df54-86f0-44df-a739-e7db386cf0cb,,2100070000004,391824,9,1052,true,,,doos,true,,,,0,,,frozen,,NaN,2,normal,,,,[object Object],[object Object],[object Object] +18822,MACARON FROZEN YOGHURT 50ST,213,1,doos,49.5,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688641988355_59300671_Frozen%20Yoghurt.jpg?alt=media&token=b56a6ec7-bfb4-44ea-82c0-216a2d75d8c8,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688641988355_59300671_Frozen%20Yoghurt.jpg?alt=media&token=b56a6ec7-bfb4-44ea-82c0-216a2d75d8c8,,2100090000008,391859,9,1052,true,,,doos,true,,,,0,,,frozen,,NaN,2,normal,,,,[object Object],[object Object],[object Object] +18821,MACARON MOJITO 50ST,213,1,doos,49.5,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688641979086_125362894_Fresh%20Mint.jpg?alt=media&token=254fc275-776c-4bfa-b76a-df54ac1fae59,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688641979086_125362894_Fresh%20Mint.jpg?alt=media&token=254fc275-776c-4bfa-b76a-df54ac1fae59,,2100140000002,391972,9,1052,true,,,doos,true,,,,0,,,frozen,,NaN,2,normal,,,,[object Object],[object Object],[object Object] +18820,MACARON DUTCH COOKIE 50ST,213,1,doos,49.5,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688641969573_715256835_kie%20%26%20Cream.jpg?alt=media&token=d65e3d7e-bcbd-450b-8001-3454dbcde120,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688641969573_715256835_kie%20%26%20Cream.jpg?alt=media&token=d65e3d7e-bcbd-450b-8001-3454dbcde120,,2100080000001,391786,9,1052,true,,,doos,true,,,,0,,,frozen,,NaN,2,normal,,,,[object Object],[object Object],[object Object] +18819,MACARON COFFEE/CARAMEL MACCHIATO 50ST,213,1,doos,49.5,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688641955426_899604401_Coffee.jpg?alt=media&token=b8dceb37-9229-4c80-bd03-ac357330d6cd,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688641955426_899604401_Coffee.jpg?alt=media&token=b8dceb37-9229-4c80-bd03-ac357330d6cd,,2100050000000,391913,9,1052,true,,,doos,true,,,,0,,,frozen,,NaN,2,normal,,,,[object Object],[object Object],[object Object] +18817,MACARON CHOCOLATE 50ST,213,1,doos,49.5,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688641942312_728997024_Chocolate.jpg?alt=media&token=ef53bb26-d1f3-4ebd-a4dd-30df5fc31261,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688641942312_728997024_Chocolate.jpg?alt=media&token=ef53bb26-d1f3-4ebd-a4dd-30df5fc31261,,2100010000002,391832,9,1052,true,,,doos,true,,,,0,,,frozen,,NaN,2,normal,,,,[object Object],[object Object],[object Object] +18816,MACARON CHEESECAKE 50ST,213,1,doos,49.5,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688641931902_175491984_%20Cheesecake.jpg?alt=media&token=4b4d9b3e-cdc1-4a83-9a98-6ca2190feb6b,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688641931902_175491984_%20Cheesecake.jpg?alt=media&token=4b4d9b3e-cdc1-4a83-9a98-6ca2190feb6b,,2100020000009,391778,9,1052,true,,,doos,true,,,,0,,,frozen,,NaN,2,normal,,,,[object Object],[object Object],[object Object] +18815,MACARON CARAMEL SALTED 50ST,213,1,doos,49.5,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688641919722_526344378_Salted%20Caramel.jpg?alt=media&token=ca6b744f-e2e8-4823-9970-11f0aa4862b0,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688641919722_526344378_Salted%20Caramel.jpg?alt=media&token=ca6b744f-e2e8-4823-9970-11f0aa4862b0,,2100230000004,391751,9,1052,true,,,doos,true,,,,0,,,frozen,,NaN,2,normal,,,,[object Object],[object Object],[object Object] +18814,MACARON BUBBLEGUM 50ST,213,1,doos,49.5,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688641906499_813456162_Bubble%20Gum.jpg?alt=media&token=f0b8ade1-1e4f-4ee7-a4ee-adfbbb0cb188,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688641906499_813456162_Bubble%20Gum.jpg?alt=media&token=f0b8ade1-1e4f-4ee7-a4ee-adfbbb0cb188,,2100130000005,391921,9,1052,true,,,doos,true,,,,0,,,frozen,,NaN,2,normal,,,,[object Object],[object Object],[object Object] +18813,MACARON BLACK CHERRY PIE 50ST,213,1,doos,49.5,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688641892658_372017613_Black%20Cherry%20Pie.jpg?alt=media&token=3f80e00a-5700-45f0-961d-da2b14f129d6,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688641892658_372017613_Black%20Cherry%20Pie.jpg?alt=media&token=3f80e00a-5700-45f0-961d-da2b14f129d6,,2100150000009,391816,9,1052,true,,,doos,true,,,,0,,,frozen,,NaN,2,normal,,,,[object Object],[object Object],[object Object] +18812,MACARON BANANA 50ST,213,1,doos,49.5,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688641879136_856647310_Banana.jpg?alt=media&token=ec620157-c8bd-4d34-aec2-389db2bfae6d,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688641879136_856647310_Banana.jpg?alt=media&token=ec620157-c8bd-4d34-aec2-389db2bfae6d,,2100100000004,391948,9,1052,true,,,doos,true,,,,0,,,frozen,,NaN,2,normal,,,,[object Object],[object Object],[object Object] +18809,MACARON TASJES MED 250ST,264,1,kilo,97.5,,,,,8716739157190,53333,9,1052,true,,,doos,true,,,,,,,ambient,,,2,normal,,,,[object Object],[object Object],[object Object] +18808,MACARON 6-PACK DHM DOOSJE,264,1,kilo,81.9,,,,,8716739157176,53317,9,1052,true,,,doos,true,,,,,,,ambient,,,2,normal,,,,[object Object],[object Object],[object Object] +18807,MACARON 6-PACK DHM INLAY,264,1,kilo,35.1,,,,,8716739157169,53309,9,1052,true,,,doos,true,,,,,,,ambient,,,2,normal,,,,[object Object],[object Object],[object Object] +18806,MACARON 9-PACK DHM DOOSJE,264,1,kilo,67.2,,,,,8716739157152,53295,9,1052,true,,,doos,true,,,,,,,ambient,,,2,normal,,,,[object Object],[object Object],[object Object] +18805,MACARON 9-PACK DHM INLAY,264,1,kilo,28.8,,,,,8716739157145,53287,9,1052,true,,,doos,true,,,,,,,ambient,,,2,normal,,,,[object Object],[object Object],[object Object] +18804,MACARON 12-PACK DHM DOOSJE,264,1,kilo,40.25,,,,,8716739157138,53279,9,1052,true,,,doos,true,,,,,,,ambient,,,2,normal,,,,[object Object],[object Object],[object Object] +18803,MACARON 12-PACK DHM INLAY,264,1,kilo,17,,,,,8716739157121,53260,9,1052,true,,,stuk,true,,,,,,,ambient,,,2,normal,,,,[object Object],[object Object],[object Object] +18801,SUMMERBERRY STACK,101,1,kilo,121.39,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688545727479_916442946_y%20stack%208st.png?alt=media&token=673f6972-f9ad-4f93-8c70-343eb64ec0ab,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688545727479_916442946_y%20stack%208st.png?alt=media&token=673f6972-f9ad-4f93-8c70-343eb64ec0ab,"
Sweet Street, 8x 8st 

",10749017016662,442933,9,1049,true,,,doos,true,,Sweet Street,,,,,frozen,,,2,franchise,,,,[object Object],[object Object], +18742,VEGAN GEBAKJE AARDBEIEN,101,1,doos,17.68,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688391351283_614674814_e%20aardbeien.png?alt=media&token=0f420823-fc76-4dec-b2f0-003779d1f7db,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688391351283_614674814_e%20aardbeien.png?alt=media&token=0f420823-fc76-4dec-b2f0-003779d1f7db,"
Patisserie Unique 12 st
",4004311195239,384291,9,1049,true,,,doos,true,,Patisserie Unique,,0,,,frozen,,NaN,2,franchise,,,,[object Object],[object Object], +18741,SKY HIGH APPLE PIE 12P,101,1,doos,62.65,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688391285148_827181427_h%20Apple%20pie.png?alt=media&token=a9f5cb03-3513-4fb7-b7d3-b4206be49459,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688391285148_827181427_h%20Apple%20pie.png?alt=media&token=a9f5cb03-3513-4fb7-b7d3-b4206be49459,"
Cut The Cake 4 x 12 p
",8715196556096,449776,9,1049,true,,,doos,true,,Cut The Cake,,0,,,frozen,,NaN,2,franchise,,,,[object Object],[object Object], +18740,REBELLIOUS RED VELVET 14P,101,1,doos,71.17,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688391233519_79422497_%20Red%20Velvet.png?alt=media&token=1e1f6414-dc3c-4fe5-8ab3-752d0a51e94b,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688391233519_79422497_%20Red%20Velvet.png?alt=media&token=1e1f6414-dc3c-4fe5-8ab3-752d0a51e94b,"
Cut The Cake 4 x 14 p
",8715196556010,449768,9,1049,true,,,doos,true,,Cut The Cake,,0,,,frozen,,NaN,2,franchise,,,,[object Object],[object Object], +18739,RAW CAKES TIRAMISU,101,1,doos,41.32,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688391136178_655980627_440914%20Tiramisu.jpg?alt=media&token=eb8736ad-5f05-4382-84cc-afe42900325a,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688391136178_655980627_440914%20Tiramisu.jpg?alt=media&token=eb8736ad-5f05-4382-84cc-afe42900325a,"
Nats Rawline 3 x 12 st
",5407005640586,440914,9,1049,true,,,doos,true,,Nats Rawline,,0,,,frozen,,NaN,2,franchise,,,,[object Object],[object Object], +18738,RAW CAKES RASPBERRY LIME,101,1,doos,42.26,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688391083360_848572299_erry%20%26%20Lime.jpg?alt=media&token=c7105ed3-786a-4016-b8f0-5d56c1d9fa00,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688391083360_848572299_erry%20%26%20Lime.jpg?alt=media&token=c7105ed3-786a-4016-b8f0-5d56c1d9fa00,"
Nats Rawline 3 x 12 st
",5407005640876,443719,9,1049,true,,,doos,true,,Nats Rawline,,0,,,frozen,,NaN,2,franchise,,,,[object Object],[object Object], +18737,RAW CAKES RASPBERRY BLUEBERRY,101,1,doos,41.85,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688390999106_179293923_y-blueberry.jpg?alt=media&token=91bb334e-9e79-486f-85c4-7e08e23e8bc7,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688390999106_179293923_y-blueberry.jpg?alt=media&token=91bb334e-9e79-486f-85c4-7e08e23e8bc7,"
Nats Rawline 3 x 12 st
",5407005640470,440930,9,1049,true,,,doos,true,,Nats Rawline,,0,,,frozen,,NaN,2,franchise,,,,[object Object],[object Object], +18735,RAW CAKES LIME MANGO,101,1,doos,41.85,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688390856719_321727338_ime%20%E2%80%93%20Mango.jpg?alt=media&token=cfa3f986-1ef4-4309-9bb3-2c84bc7dddf2,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688390856719_321727338_ime%20%E2%80%93%20Mango.jpg?alt=media&token=cfa3f986-1ef4-4309-9bb3-2c84bc7dddf2,"
Nats Rawline 3 x 12 st
",5407005640579,440949,9,1049,true,,,doos,true,,Nats Rawline,,0,,,frozen,,NaN,2,franchise,,,,[object Object],[object Object], +18734,RAW CAKES CHOCOLATE HAZELNUT,101,1,doos,41.85,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688390769219_884740623_ts%20raw%20cake.jpg?alt=media&token=a0e6dfde-791b-4177-9149-309b9a4919b9,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688390769219_884740623_ts%20raw%20cake.jpg?alt=media&token=a0e6dfde-791b-4177-9149-309b9a4919b9,"
Nats Rawline 3 x 12 st
",5407005641125,443700,9,1049,true,,,doos,true,,Nats Rawline,,0,,,frozen,,NaN,2,franchise,,,,[object Object],[object Object], +18733,RAW CAKES CARAMEL CHOCOLATE,101,1,doos,41.32,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688390523791_316569728_%20chocolate1.jpg?alt=media&token=5018d156-1db1-4c79-a3e4-31c431f51659,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688390523791_316569728_%20chocolate1.jpg?alt=media&token=5018d156-1db1-4c79-a3e4-31c431f51659,"
Nats Rawline 3 x 12 st
",5407005640593,440922,9,1049,true,,,doos,true,,Nats Rawline,,0,,,frozen,,NaN,2,franchise,,,,[object Object],[object Object], +18732,RASPBERRY WHITE CHOCOLATE CC,101,1,doos,80.96,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688390243381_375351179_%20Cheesecake.png?alt=media&token=24d91073-d782-4d6d-a60d-c598ea170cb6,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688390243381_375351179_%20Cheesecake.png?alt=media&token=24d91073-d782-4d6d-a60d-c598ea170cb6,"
Sweet Street 2 x 14 p
",10749017012558,374784,9,1049,true,,,doos,true,,Sweet Street,,0,,,frozen,,NaN,2,franchise,,,,[object Object],[object Object], +18731,PASSIONATE POMEGRANATE 14P,101,1,doos,70.39,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688389760672_248051217_Pomegranate.png?alt=media&token=3f7d38cb-aa70-48f8-a521-fdee15174da0,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688389760672_248051217_Pomegranate.png?alt=media&token=3f7d38cb-aa70-48f8-a521-fdee15174da0,"
Cut The Cake 4 x 14 p
",8715196556119,449822,9,1049,true,,,doos,true,,Cut The Cake,,0,,,frozen,,NaN,2,franchise,,,,[object Object],[object Object], +18730,NEW YORK CHEESECAKE,101,1,doos,94.06,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688389707108_901140884_%20Cheesecake.png?alt=media&token=8c6a3335-1a7a-4981-9549-debf85763290,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688389707108_901140884_%20Cheesecake.png?alt=media&token=8c6a3335-1a7a-4981-9549-debf85763290,"
Sweet Street 4 x 16 p
",10749017009145,317071,9,1049,true,,,doos,true,,Sweet Street,,0,,,frozen,,NaN,2,franchise,,,,[object Object],[object Object], +18729,HAZELINO KARAMEL,101,1,doos,21.26,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688389520355_211854468_ino%20Karamel.png?alt=media&token=93185c28-5deb-430e-bf04-b6c6e8a09c99,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688389520355_211854468_ino%20Karamel.png?alt=media&token=93185c28-5deb-430e-bf04-b6c6e8a09c99,"
Patisserie Unique 16 st
",8718026245085,398977,9,1049,true,,,doos,true,,Patisserie Unique,,0,,,frozen,,NaN,2,franchise,,,,[object Object],[object Object], +18728,HAZELINO CHRISTOFFEL,101,1,doos,21.26,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688389409084_706530979_Christoffel.png?alt=media&token=bc174677-d9cc-4e91-9365-41c50293b7f1,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688389409084_706530979_Christoffel.png?alt=media&token=bc174677-d9cc-4e91-9365-41c50293b7f1,"
Patisserie Unique 16 st
",8718026245054,398985,9,1049,true,,,doos,true,,Patisserie Unique,,0,,,frozen,,NaN,2,franchise,,,,[object Object],[object Object], +18727,GLUTEN LACTOSEVRIJ CHOCOLADE,101,1,doos,24.12,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688389319526_419892598_ade%20gebakje.png?alt=media&token=28253352-1cd2-4df5-be1a-1bea3dc84383,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688389319526_419892598_ade%20gebakje.png?alt=media&token=28253352-1cd2-4df5-be1a-1bea3dc84383,"
Patisserie Unique 12 st
",4004311187463,384275,9,1049,true,,,doos,true,,Patisserie Unique,,0,,,frozen,,NaN,2,franchise,,,,[object Object],[object Object], +18726,GLUTEN LACTOSEVRIJ AARDBEIEN,101,1,doos,24.12,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688389226227_386471740_ien%20gebakje.png?alt=media&token=7b964119-1bcf-4eaf-be0a-5b545fd1253b,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688389226227_386471740_ien%20gebakje.png?alt=media&token=7b964119-1bcf-4eaf-be0a-5b545fd1253b,"
Patisserie Unique 12 st
",4004311187371,384305,9,1049,true,,,doos,true,,Patisserie Unique,,0,,,frozen,,NaN,2,franchise,,,,[object Object],[object Object], +18725,CREME BRULEE CHEESE,101,1,doos,72.13,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688385861936_343085633_%20Cheesecake.png?alt=media&token=6830c9a5-0a60-46a0-b891-26cfab7f1aa8,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688385861936_343085633_%20Cheesecake.png?alt=media&token=6830c9a5-0a60-46a0-b891-26cfab7f1aa8,"
Sweet Street 2 x 14 p
",10749017012572,316733,9,1049,true,,,doos,true,,Sweet Street,,0,,,frozen,,NaN,2,franchise,,,,[object Object],[object Object], +18724,CRAZY CARROT CAKE 14P,101,1,doos,71.17,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688385320516_292955121_Carrot%20Cake.png?alt=media&token=daca2c37-7eb2-4613-ab8d-47a5f304e517,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688385320516_292955121_Carrot%20Cake.png?alt=media&token=daca2c37-7eb2-4613-ab8d-47a5f304e517,"
Cut The Cake 4 x 14 p
",8715196556034,449806,9,1049,true,,,doos,true,,Cut The Cake,,0,,,frozen,,NaN,2,franchise,,,,[object Object],[object Object], +18722,CHEEKY CHOCOLATE 14P,101,1,doos,70,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688384904957_805496646_y%20Chocolate.png?alt=media&token=60cb9220-43c4-4772-b0ca-647ccde5d8da,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688384904957_805496646_y%20Chocolate.png?alt=media&token=60cb9220-43c4-4772-b0ca-647ccde5d8da,"
Cut The Cake 4 x 14 p
",8715196556058,449792,9,1049,true,,,doos,true,,Cut the Cake,,0,,,frozen,,NaN,2,franchise,,,,[object Object],[object Object], +18721,BOMBASTIC BROWNIE 14P,101,1,doos,67.13,,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688384855959_904936215_tic%20Brownie.png?alt=media&token=1fd1eb92-8f6f-472c-8be8-860ebaa686e1,https://firebasestorage.googleapis.com/v0/b/app-verstrade.appspot.com/o/angular%2Fprod%2Fproducts%2F1688384855959_904936215_tic%20Brownie.png?alt=media&token=1fd1eb92-8f6f-472c-8be8-860ebaa686e1,"
Cut The Cake 4 x 14 p
",8715196556133,449784,9,1049,true,,,doos,true,,Cut The Cake,,0,,,frozen,,NaN,2,franchise,,,,[object Object],[object Object], diff --git a/oscar_odin/mappings/context.py b/oscar_odin/mappings/context.py index 4138d1e..988763d 100644 --- a/oscar_odin/mappings/context.py +++ b/oscar_odin/mappings/context.py @@ -5,14 +5,6 @@ from oscar_odin.utils import in_bulk -from oscar.core.loading import get_model - -Product = get_model("catalogue", "Product") -Category = get_model("catalogue", "Category") -StockRecord = get_model("partner", "StockRecord") -ProductClass = get_model("catalogue", "ProductClass") -ProductImage = get_model("catalogue", "ProductImage") - def get_instances_to_create_or_update(Model, instances, identifier_mapping): instances_to_create = [] diff --git a/oscar_odin/resources/catalogue.py b/oscar_odin/resources/catalogue.py index 84c784f..e644219 100644 --- a/oscar_odin/resources/catalogue.py +++ b/oscar_odin/resources/catalogue.py @@ -106,6 +106,7 @@ class Product(OscarCatalogue): images: List[Image] = odin.Options(empty=True) rating: Optional[float] is_discountable: bool + is_public: bool # Price information price: Decimal = DecimalField() diff --git a/tests/reverse/test_reallifecase.py b/tests/reverse/test_reallifecase.py new file mode 100644 index 0000000..805d391 --- /dev/null +++ b/tests/reverse/test_reallifecase.py @@ -0,0 +1,203 @@ +import io +import PIL +import odin +import requests + +from urllib.parse import urlparse + +from odin.codecs import csv_codec +from os import path +from decimal import Decimal as D + +from django.core.files import File +from django.test import TestCase + +from oscar.core.loading import get_model, get_class + +from django.utils.text import slugify + +from oscar_odin.fields import DecimalField +from oscar_odin.mappings.catalogue import products_to_db +from oscar_odin.resources.catalogue import ( + Product as ProductResource, + Image as ImageResource, + ProductClass as ProductClassResource, + Category as CategoryResource, + ProductAttributeValue as ProductAttributeValueResource, +) + +Product = get_model("catalogue", "Product") +ProductClass = get_model("catalogue", "ProductClass") +ProductAttribute = get_model("catalogue", "ProductAttribute") +ProductAttributeValue = get_model("catalogue", "ProductAttributeValue") +ProductImage = get_model("catalogue", "ProductImage") +Category = get_model("catalogue", "Category") +Partner = get_model("partner", "Partner") + +create_from_breadcrumbs = get_class("catalogue.categories", "create_from_breadcrumbs") + + +class CSVProductResource(odin.Resource): + id = odin.IntegerField() + name = odin.StringField() + category_id = odin.IntegerField() + weight = odin.IntegerField() + weight_type = odin.StringField() + price = DecimalField() + image = odin.StringField(null=True) + app_image = odin.StringField(null=True) + description = odin.StringField(null=True) + ean = odin.StringField(null=True) + number = odin.StringField(null=True) + supplier_id = odin.IntegerField() + active = odin.BooleanField() + unit = odin.StringField() + tags = odin.StringField(null=True) + storage_type = odin.StringField() + assortmentclass = odin.StringField() + + +class CSVProductMapping(odin.Mapping): + from_obj = CSVProductResource + to_obj = ProductResource + + mappings = ( + odin.define(from_field="number", to_field="upc"), + odin.define(from_field="name", to_field="title"), + odin.define(from_field="active", to_field="is_public"), + ) + + @odin.map_list_field(from_field="category_id") + def categories(self, category_id): + return [CategoryResource(code=category_id)] + + @odin.map_field(from_field="name") + def slug(self, name): + return slugify(name) + + @odin.map_field( + from_field=["weight", "weight_type", "ean", "unit", "tags", "storage_type"] + ) + def attributes(self, weight, weight_type, ean, unit, tags, storage_type): + return { + "weight": weight, + "weight_type": weight_type, + "ean": ean, + "unit": unit, + "tags": tags, + "storage_type": storage_type, + } + + @odin.map_list_field(from_field=["image", "app_image"]) + def images(self, image, app_image): + images = [] + + if image: + response = requests.get(image) + a = urlparse(image) + img = File(io.BytesIO(response.content), name=path.basename(a.path)) + images.append( + ImageResource(display_order=0, code=image, caption="", original=img) + ) + + if app_image and app_image != image: + response = requests.get(app_image) + a = urlparse(app_image) + img = File(io.BytesIO(response.content), name=path.basename(a.path)) + images.append( + ImageResource(display_order=1, caption="", code=image, original=img) + ) + + return images + + @odin.map_field(from_field="supplier_id") + def partner(self, supplier_id): + partner, _ = Partner.objects.get_or_create(name=supplier_id) + return partner + + @odin.assign_field + def product_class(self): + return ProductClassResource(slug="standard") + + @odin.assign_field + def structure(self): + return Product.STANDALONE + + @odin.assign_field + def is_discountable(self): + return True + + +class RealLifeTest(TestCase): + def test_mapping(self): + # Create product class + product_class, _ = ProductClass.objects.get_or_create( + slug="standard", + defaults={ + "name": "Standard product class", + "requires_shipping": True, + "track_stock": False, + }, + ) + ProductAttribute.objects.get_or_create( + code="weight", + product_class=product_class, + defaults={"name": "Weight", "type": ProductAttribute.INTEGER}, + ) + ProductAttribute.objects.get_or_create( + code="weight_type", + product_class=product_class, + defaults={"name": "Weight type", "type": ProductAttribute.TEXT}, + ) + ProductAttribute.objects.get_or_create( + code="ean", + product_class=product_class, + defaults={"name": "EAN", "type": ProductAttribute.TEXT}, + ) + ProductAttribute.objects.get_or_create( + code="unit", + product_class=product_class, + defaults={"name": "Unit", "type": ProductAttribute.TEXT}, + ) + ProductAttribute.objects.get_or_create( + code="tags", + product_class=product_class, + defaults={"name": "Tags", "type": ProductAttribute.TEXT}, + ) + ProductAttribute.objects.get_or_create( + code="storage_type", + product_class=product_class, + defaults={"name": "Storage type", "type": ProductAttribute.TEXT}, + ) + + # Create all the categories at first and assign a unique code + for cat_id in ["101", "213", "264"]: + cat = create_from_breadcrumbs(cat_id) + cat.code = cat_id + cat.save() + + # Get csv file and open it + csv_file = self.get_csv_fixture("products.csv") + with open(csv_file) as f: + # Use odin codec to load in csv to our created resource + products = csv_codec.reader(f, CSVProductResource, includes_header=True) + + # Map the csv resources to product resources + product_resources = CSVProductMapping.apply(products) + + # Map the product resources to products and save in DB + products_to_db(product_resources) + + self.assertEquals(Product.objects.all().count(), 59) + self.assertEquals(ProductAttributeValue.objects.all().count(), 257) + self.assertEquals(ProductImage.objects.all().count(), 52) + + def get_csv_fixture(self, filename): + return path.realpath( + path.join( + path.dirname(__file__), + "../../", + "oscar_odin/fixtures/oscar_odin/csv/", + filename, + ) + )