From 3286a81190b83c91adc3f4cfab1fcff4766f3e7d Mon Sep 17 00:00:00 2001 From: Anton Sarukhanov <code@ant.sr> Date: Sun, 5 Feb 2017 01:27:15 -0500 Subject: [PATCH] Started writing tests --- .gitlab-ci.yml | 4 ++++ test-requirements.txt | 2 ++ tests/static/sample_ecwid.csv | 5 +++++ tests/test_adapter_adapter.py | 17 +++++++++++++++++ tests/test_wooifier.py | 33 +++++++++++++++++++++++++++++++++ 5 files changed, 61 insertions(+) create mode 100644 tests/static/sample_ecwid.csv create mode 100644 tests/test_adapter_adapter.py create mode 100644 tests/test_wooifier.py diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c39e576..50dc633 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -5,6 +5,10 @@ before_script: - pip install -e . - pip install -r test-requirements.txt +pytest: + script: + - py.test + pep8: script: - pep8 wooify diff --git a/test-requirements.txt b/test-requirements.txt index 8098e7b..2dcafec 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1 +1,3 @@ pep8==1.7.0 +pytest==3.0.6 +pytest-cov==2.4.0 diff --git a/tests/static/sample_ecwid.csv b/tests/static/sample_ecwid.csv new file mode 100644 index 0000000..035f805 --- /dev/null +++ b/tests/static/sample_ecwid.csv @@ -0,0 +1,5 @@ +name;sku;description;category1;category2;category3;image;weight;price;recommended_price;quantity;enabled;shipping_freight;fixed_shipping_rate_only;upc;brand;seo_title;seo_description;product_url;product_id +Test 1;"testFoo";"<p><span style=""shitty-css: yes;"">The testiest of tests!</span></p>";Test Parent / Test Child 1;;;;42.00;13.37;;;yes;0.00;no;;;;;http://example.com/product1;12345654321 +Test 2;"testBar";"<p><span style=""shitty-css: yes;"">The testiest of tests!</span></p>";Test Parent / Test Child 2;;;;42.00;13.37;;;yes;0.00;no;;;;;http://example.com/product2;12345654321 +Test 3;"testQux";"<p><span style=""shitty-css: yes;"">The testiest of tests!</span></p>";Testy Test;;;;42.00;13.37;;;yes;0.00;no;;;;;http://example.com/product3;12345654321 +Test 4;"testBaz";"<p><span style=""shitty-css: yes;"">The testiest of tests!</span></p>";Test Parent / Test Child 2;;;;42.00;13.37;;;yes;0.00;no;;;;;http://example.com/product4;12345654321 diff --git a/tests/test_adapter_adapter.py b/tests/test_adapter_adapter.py new file mode 100644 index 0000000..864c7d9 --- /dev/null +++ b/tests/test_adapter_adapter.py @@ -0,0 +1,17 @@ +import os +import pytest + +from wooify.adapters.adapter import Adapter + +def test_init(): + with pytest.raises(NotImplementedError): + adapter = Adapter('foo') + +def test_clean_products(monkeypatch): + def mockparse(self, test_file): + self.products = [{ + 'Description': '<b>foo', + }] + monkeypatch.setattr(Adapter, 'parse', mockparse) + adapter = Adapter('foo') + clean = adapter.clean_products diff --git a/tests/test_wooifier.py b/tests/test_wooifier.py new file mode 100644 index 0000000..533d3de --- /dev/null +++ b/tests/test_wooifier.py @@ -0,0 +1,33 @@ +import csv +import os +import pytest + +from wooify.wooifier import Wooifier +from wooify.adapters.adapter import Adapter +from wooify.constants import (ALLOWED_HTML_TAGS, HTML_FIELDS, + WOO_IMP_EXP_PRODUCT_FIELDS) + +def test_init(): + wooifier = Wooifier(Adapter) + assert wooifier.adapter_cls == Adapter + +def test_wooify(monkeypatch, tmpdir): + def mockparse(self, test_file): + products = [{ + 'sku': 'test1', + 'name': 'Test 1', + }] + for p in products: + product = dict(WOO_IMP_EXP_PRODUCT_FIELDS) + product.update({'SKU': p['sku'], 'Product Name': p['name']}) + self.products.append(product) + monkeypatch.setattr(Adapter, 'parse', mockparse) + wooifier = Wooifier(Adapter) + in_file = tmpdir.join("input.csv") + products_file = tmpdir.join("products.csv") + categories_file = tmpdir.join("categories.csv") + wooifier.wooify(in_file, products_file.strpath, categories_file.strpath) + csv_reader = csv.DictReader(products_file.open()) + for row in csv_reader: + assert row['SKU'] == 'test1' + assert row['Product Name'] == 'Test 1' -- GitLab