diff --git a/tests/Assets/genericimportfile.xml b/tests/offline/Assets/genericimportfile.xml similarity index 100% rename from tests/Assets/genericimportfile.xml rename to tests/offline/Assets/genericimportfile.xml diff --git a/tests/Assets/note.xml b/tests/offline/Assets/note.xml similarity index 100% rename from tests/Assets/note.xml rename to tests/offline/Assets/note.xml diff --git a/tests/Assets/quota_exceeded_message.xml b/tests/offline/Assets/quota_exceeded_message.xml similarity index 100% rename from tests/Assets/quota_exceeded_message.xml rename to tests/offline/Assets/quota_exceeded_message.xml diff --git a/tests/Assets/sample_accept_sale.xml b/tests/offline/Assets/sample_accept_sale.xml similarity index 100% rename from tests/Assets/sample_accept_sale.xml rename to tests/offline/Assets/sample_accept_sale.xml diff --git a/tests/Assets/sample_cancelitem.xml b/tests/offline/Assets/sample_cancelitem.xml similarity index 100% rename from tests/Assets/sample_cancelitem.xml rename to tests/offline/Assets/sample_cancelitem.xml diff --git a/tests/Assets/sample_confirmpreorder.xml b/tests/offline/Assets/sample_confirmpreorder.xml similarity index 100% rename from tests/Assets/sample_confirmpreorder.xml rename to tests/offline/Assets/sample_confirmpreorder.xml diff --git a/tests/Assets/sample_contactus.xml b/tests/offline/Assets/sample_contactus.xml similarity index 100% rename from tests/Assets/sample_contactus.xml rename to tests/offline/Assets/sample_contactus.xml diff --git a/tests/Assets/sample_contactuser.xml b/tests/offline/Assets/sample_contactuser.xml similarity index 100% rename from tests/Assets/sample_contactuser.xml rename to tests/offline/Assets/sample_contactuser.xml diff --git a/tests/Assets/sample_exportinventory.xml b/tests/offline/Assets/sample_exportinventory.xml similarity index 100% rename from tests/Assets/sample_exportinventory.xml rename to tests/offline/Assets/sample_exportinventory.xml diff --git a/tests/Assets/sample_genericimportfile.xml b/tests/offline/Assets/sample_genericimportfile.xml similarity index 100% rename from tests/Assets/sample_genericimportfile.xml rename to tests/offline/Assets/sample_genericimportfile.xml diff --git a/tests/Assets/sample_getavailableshippingtypes.xml b/tests/offline/Assets/sample_getavailableshippingtypes.xml similarity index 100% rename from tests/Assets/sample_getavailableshippingtypes.xml rename to tests/offline/Assets/sample_getavailableshippingtypes.xml diff --git a/tests/Assets/sample_getbillinginformation.xml b/tests/offline/Assets/sample_getbillinginformation.xml similarity index 100% rename from tests/Assets/sample_getbillinginformation.xml rename to tests/offline/Assets/sample_getbillinginformation.xml diff --git a/tests/Assets/sample_getcategorymap.xml b/tests/offline/Assets/sample_getcategorymap.xml similarity index 100% rename from tests/Assets/sample_getcategorymap.xml rename to tests/offline/Assets/sample_getcategorymap.xml diff --git a/tests/Assets/sample_getcompensationdetails.xml b/tests/offline/Assets/sample_getcompensationdetails.xml similarity index 100% rename from tests/Assets/sample_getcompensationdetails.xml rename to tests/offline/Assets/sample_getcompensationdetails.xml diff --git a/tests/Assets/sample_getcurrentsales.xml b/tests/offline/Assets/sample_getcurrentsales.xml similarity index 100% rename from tests/Assets/sample_getcurrentsales.xml rename to tests/offline/Assets/sample_getcurrentsales.xml diff --git a/tests/Assets/sample_getiteminfos.xml b/tests/offline/Assets/sample_getiteminfos.xml similarity index 100% rename from tests/Assets/sample_getiteminfos.xml rename to tests/offline/Assets/sample_getiteminfos.xml diff --git a/tests/Assets/sample_getitemtodolist.xml b/tests/offline/Assets/sample_getitemtodolist.xml similarity index 100% rename from tests/Assets/sample_getitemtodolist.xml rename to tests/offline/Assets/sample_getitemtodolist.xml diff --git a/tests/Assets/sample_getnewsales.xml b/tests/offline/Assets/sample_getnewsales.xml similarity index 100% rename from tests/Assets/sample_getnewsales.xml rename to tests/offline/Assets/sample_getnewsales.xml diff --git a/tests/Assets/sample_getoperations.xml b/tests/offline/Assets/sample_getoperations.xml similarity index 100% rename from tests/Assets/sample_getoperations.xml rename to tests/offline/Assets/sample_getoperations.xml diff --git a/tests/Assets/sample_getproductlist.xml b/tests/offline/Assets/sample_getproductlist.xml similarity index 100% rename from tests/Assets/sample_getproductlist.xml rename to tests/offline/Assets/sample_getproductlist.xml diff --git a/tests/Assets/sample_getproducttypes.xml b/tests/offline/Assets/sample_getproducttypes.xml similarity index 100% rename from tests/Assets/sample_getproducttypes.xml rename to tests/offline/Assets/sample_getproducttypes.xml diff --git a/tests/Assets/sample_getproducttypetemplate.xml b/tests/offline/Assets/sample_getproducttypetemplate.xml similarity index 100% rename from tests/Assets/sample_getproducttypetemplate.xml rename to tests/offline/Assets/sample_getproducttypetemplate.xml diff --git a/tests/Assets/sample_getshippinginformation.xml b/tests/offline/Assets/sample_getshippinginformation.xml similarity index 100% rename from tests/Assets/sample_getshippinginformation.xml rename to tests/offline/Assets/sample_getshippinginformation.xml diff --git a/tests/Assets/sample_productlist.xml b/tests/offline/Assets/sample_productlist.xml similarity index 100% rename from tests/Assets/sample_productlist.xml rename to tests/offline/Assets/sample_productlist.xml diff --git a/tests/Assets/sample_settrackingpackageinfos.xml b/tests/offline/Assets/sample_settrackingpackageinfos.xml similarity index 100% rename from tests/Assets/sample_settrackingpackageinfos.xml rename to tests/offline/Assets/sample_settrackingpackageinfos.xml diff --git a/tests/offline/__init__.py b/tests/offline/__init__.py new file mode 100644 index 0000000..a5aa6cb --- /dev/null +++ b/tests/offline/__init__.py @@ -0,0 +1 @@ +__author__ = 'jgriselle' diff --git a/tests/test_accountingmanagement.py b/tests/offline/test_accountingmanagement.py similarity index 100% rename from tests/test_accountingmanagement.py rename to tests/offline/test_accountingmanagement.py diff --git a/tests/test_inventorymanagement.py b/tests/offline/test_inventorymanagement.py similarity index 100% rename from tests/test_inventorymanagement.py rename to tests/offline/test_inventorymanagement.py diff --git a/tests/test_marketplacemanagement.py b/tests/offline/test_marketplacemanagement.py similarity index 100% rename from tests/test_marketplacemanagement.py rename to tests/offline/test_marketplacemanagement.py diff --git a/tests/test_salesmanagement.py b/tests/offline/test_salesmanagement.py similarity index 100% rename from tests/test_salesmanagement.py rename to tests/offline/test_salesmanagement.py diff --git a/tests/test_shibatools.py b/tests/offline/test_shibatools.py similarity index 100% rename from tests/test_shibatools.py rename to tests/offline/test_shibatools.py diff --git a/tests/online/Assets/genericimportfile.xml b/tests/online/Assets/genericimportfile.xml new file mode 100644 index 0000000..29e9bda --- /dev/null +++ b/tests/online/Assets/genericimportfile.xml @@ -0,0 +1,13 @@ + + + + + + sellerReference + + + 30 + + + + \ No newline at end of file diff --git a/tests/online/__init__.py b/tests/online/__init__.py new file mode 100644 index 0000000..a5aa6cb --- /dev/null +++ b/tests/online/__init__.py @@ -0,0 +1 @@ +__author__ = 'jgriselle' diff --git a/tests/online/test_accountingmanagement.py b/tests/online/test_accountingmanagement.py new file mode 100644 index 0000000..76ce73e --- /dev/null +++ b/tests/online/test_accountingmanagement.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Class AccountingManagementTest +# Testing AccountingManagement Class methods +# https://developer.priceminister.com/blog/fr/documentation/accounting + + +from __future__ import unicode_literals + +from Shiba.accountingmanagement import AccountingManagement +from Shiba.shibaconnection import ShibaConnection +from Shiba.shibaexceptions import * + +import os +import ConfigParser + +import unittest + +from datetime import date + + +class AccountingManagementTest(unittest.TestCase): + + def setUp(self): + settings = ConfigParser.ConfigParser() + try: + settings.read(os.path.dirname(os.path.realpath(__file__)) + "/Assets/nosetests.cfg") + except: + raise ShibaCallingError("error : can't read login ID from the nosetests.cfg file") + try: + login = settings.get(str("NoseConfig"), "login") + pwd = settings.get(str("NoseConfig"), "pwd") + except: + raise ShibaCallingError("error : configuration file doesn't seem to be regular") + self.init = AccountingManagement(ShibaConnection(login, pwd, "https://ws.sandbox.priceminister.com")) + + def test_get_operations(self): + """get_operations routine test, with date object as lastoperationdate too""" + obj = self.init.get_operations() + self.assertTrue("getoperationsresult" in obj.content.tag) + obj = self.init.get_operations("21/12/2012-00:00:00") + self.assertTrue(obj.content.request.lastoperationdate == "21/12/2012-00:00:00") + testdate = date(2012, 12, 21) + obj = self.init.get_operations(testdate) + self.assertTrue(obj.content.request.lastoperationdate == "21/12/12-00:00:00") + obj = None + try: + obj = self.init.get_operations("INVALIDDATE") + except ShibaParameterError: + pass + self.assertTrue(obj is None) + + def test_get_compensation_details(self): + """get_compensation_details test, must fail""" + obj = None + try: + obj = self.init.get_compensation_details("1337") + except ShibaParameterError: + pass + self.assertTrue(obj is None) diff --git a/tests/online/test_inventorymanagement.py b/tests/online/test_inventorymanagement.py new file mode 100644 index 0000000..e81a4df --- /dev/null +++ b/tests/online/test_inventorymanagement.py @@ -0,0 +1,88 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Class InventoryManagementTest +# Testing InventoryManagement Class methods +# https://developer.priceminister.com/blog/fr/documentation/inventory-management + + +from __future__ import unicode_literals + +from Shiba.inventorymanagement import InventoryManagement +from Shiba.shibaconnection import ShibaConnection +from Shiba.shibaexceptions import * +from nose.tools import * + +import xmltodict +from lxml import objectify + +import unittest + +import ConfigParser +import os + +class InventoryManagementTest(unittest.TestCase): + + def setUp(self): + settings = ConfigParser.ConfigParser() + try: + settings.read(os.path.dirname(os.path.realpath(__file__)) + "/Assets/nosetests.cfg") + except: + raise ShibaCallingError("error : can't read login ID from the nosetests.cfg file") + try: + login = settings.get(str("NoseConfig"), "login") + pwd = settings.get(str("NoseConfig"), "pwd") + except: + raise ShibaCallingError("error : configuration file doesn't seem to be regular") + self.init = InventoryManagement(ShibaConnection(login, pwd, "https://ws.sandbox.priceminister.com")) + + def test_product_types(self): + """product_types return test""" + + ptypes = self.init.product_types() + self.assertTrue("producttypesresult" in ptypes.content.tag) + + def test_product_type_template(self): + """product_type_template tests on two scopes, for a fixed alias, plus a fail result""" + + alias = "insolites_produit" + ptemplate = self.init.product_type_template(alias, "") + self.assertTrue("producttypetemplateresult" in ptemplate.content.tag) + ptemplate = self.init.product_type_template(alias, "VALUES") + self.assertTrue("producttypetemplateresult" in ptemplate.content.tag) + + @raises(ShibaParameterError) + def test_product_type_template_fail(self): + self.init.product_type_template("INVALIDALIAS", "INVALIDSCOPE") + + def test_generic_import_file(self): + """generic_import_file test, from an XML file. Conversion is done by xmltodict from a dict or OrderedDict + , as well with objectify with an objectified ElementTree element""" + + f = open(os.path.dirname(os.path.realpath(__file__)) + "/Assets/genericimportfile.xml", "rb") + testdict = xmltodict.parse(f) + ret = self.init.generic_import_file(testdict) + self.assertTrue("OK" == ret.content.response.status) + f = open(os.path.dirname(os.path.realpath(__file__)) + "/Assets/genericimportfile.xml", "rb") + testobj = objectify.parse(f) + ret = self.init.generic_import_file(testobj) + self.assertTrue("OK" == ret.content.response.status) + + def test_generic_import_report(self): + """genreic_import_report method test from an import file call""" + f = open(os.path.dirname(os.path.realpath(__file__)) + "/Assets/genericimportfile.xml", "rb") + testobj = objectify.parse(f) + ret = self.init.generic_import_file(testobj) + importid = ret.content.response.importid + ret = self.init.generic_import_report(importid) + self.assertTrue("file" == ret.content.response.file.filename) + + def test_get_available_shipping_types(self): + try: + self.init.get_available_shipping_types() + except ShibaRightsError: + pass + + def test_export_inventory(self): + obj = self.init.export_inventory() + self.assertTrue("inventoryresult" in obj.content.tag) \ No newline at end of file diff --git a/tests/online/test_marketplacemanagement.py b/tests/online/test_marketplacemanagement.py new file mode 100644 index 0000000..f2dc687 --- /dev/null +++ b/tests/online/test_marketplacemanagement.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Class MarketplaceManagementTest +# Testing MarketplaceManagement Class methods +# https://developer.priceminister.com/blog/fr/documentation/product-data + + +from __future__ import unicode_literals + +from Shiba.marketplacemanagement import MarketplaceManagement +from Shiba.shibaconnection import ShibaConnection +from Shiba.shibaexceptions import * + +import unittest + +import ConfigParser +import os + +class MarketplaceManagementTest(unittest.TestCase): + + def setUp(self): + settings = ConfigParser.ConfigParser() + try: + settings.read(os.path.dirname(os.path.realpath(__file__)) + "/Assets/nosetests.cfg") + except: + raise ShibaCallingError("error : can't read login ID from the nosetests.cfg file") + try: + login = settings.get(str("NoseConfig"), "login") + pwd = settings.get(str("NoseConfig"), "pwd") + except: + raise ShibaCallingError("error : configuration file doesn't seem to be regular") + self.init = MarketplaceManagement(ShibaConnection(login, pwd, "https://ws.sandbox.priceminister.com")) + + def test_get_product_list(self): + """testing get_product_list methods with different queries, with some invalid ones as well""" + try: + obj = self.init.get_product_list() + except ShibaParameterError: + pass + obj = self.init.get_product_list(kw="livre") + self.assertTrue("listingresult" in obj.content.tag) + try: + obj = self.init.get_product_list(nbproductsperpage=-15, kw="livre") + except ShibaParameterError: + pass + obj = self.init.get_product_list(kw="informatique", scope="PRICING") + self.assertTrue("listingresult" in obj.content.tag) + + def test_get_category_map(self): + """get_category_map regular test""" + obj = self.init.get_category_map() + self.assertTrue("categorymap" in obj.content.tag) \ No newline at end of file diff --git a/tests/online/test_salesmanagement.py b/tests/online/test_salesmanagement.py new file mode 100644 index 0000000..f793aaf --- /dev/null +++ b/tests/online/test_salesmanagement.py @@ -0,0 +1,172 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Class SalesManagementTest +# Testing SalesManagement Class methods +# https://developer.priceminister.com/blog/fr/documentation/post-confirmation-of-sale +# https://developer.priceminister.com/blog/fr/documentation/new-sales + +from __future__ import unicode_literals + +from Shiba.salesmanagement import SalesManagement +from Shiba.shibaconnection import ShibaConnection +from Shiba.shibaexceptions import * + +import unittest + +import ConfigParser +import os + +class SalesManagementTest(unittest.TestCase): + """SalesManagement class unit tests, as it's not possible to emulate a real seller profile, most of those tests + are only verifying the proper handling of errors""" + def setUp(self): + settings = ConfigParser.ConfigParser() + try: + settings.read(os.path.dirname(os.path.realpath(__file__)) + "/Assets/nosetests.cfg") + except: + raise ShibaCallingError("error : can't read login ID from the nosetests.cfg file") + try: + login = settings.get(str("NoseConfig"), "login") + pwd = settings.get(str("NoseConfig"), "pwd") + except: + raise ShibaCallingError("error : configuration file doesn't seem to be regular") + self.init = SalesManagement(ShibaConnection(login, pwd, "https://ws.sandbox.priceminister.com")) + + def test_get_new_sales(self): + """regular get_new_sales test""" + obj = self.init.get_new_sales() + self.assertTrue("getnewsalesresult" in obj.content.tag) + + def test_accept_sale(self): + """Only fail result, as accepting an actual sale is not simulable""" + itemid = "000000" + obj = None + try: + obj = self.init.accept_sale(itemid) + except ShibaServiceError: + pass + except ShibaParameterError: + pass + + def test_refuse_sale(self): + """Only fail result, as refusing an actual sale is not simulable""" + itemid = "000000" + obj = None + try: + obj = self.init.refuse_sale(itemid) + except ShibaServiceError: + pass + except ShibaParameterError: + pass + + def test_get_current_sales(self): + """get_current_sales test, on variable parameters, plus some fail results""" + obj = self.init.get_current_sales() + self.assertTrue("getcurrentsalesresult" in obj.content.tag) + self.assertTrue(False == obj.content.request.ispendingpreorder) + obj = self.init.get_current_sales(ispendingpreorder="y") + self.assertTrue("getcurrentsalesresult" in obj.content.tag) + self.assertTrue(True == obj.content.request.ispendingpreorder) + try: + self.init.get_current_sales(ispendingpreorder="n") + except ShibaCallingError: + pass + obj = self.init.get_current_sales(purchasedate="WRONGDATE") + self.assertTrue(elem.content.tag is not "purchasedate" for elem in obj.content.response) + obj = self.init.get_current_sales(purchasedate="2012-12-21") + self.assertTrue("21/12/2012" == obj.content.request.purchasedate) + + def test_get_billing_information(self): + """get_billing_information test, will raise an error due to unknown purchaseid""" + obj = None + try: + obj = self.init.get_billing_information("1337") + except ShibaServiceError: + pass + self.assertTrue(obj is None) + + def test_get_shipping_information(self): + """get_billing_information test, will raise an error due to unknown purchaseid""" + obj = None + try: + obj = self.init.get_shipping_information("1337") + except ShibaServiceError: + pass + self.assertTrue(obj is None) + + def test_get_items_todo_list(self): + """get_items_todo_list routine test""" + obj = self.init.get_item_todo_list() + self.assertTrue("getitemtodolistresult" in obj.content.tag) + + def test_get_item_infos(self): + """get_item_infos on a unknown product, must fail""" + obj = None + try: + obj = self.init.get_item_infos("181063") + except ShibaServiceError: + pass + self.assertTrue(obj is None) + + def test_cancel_item(self): + """cancel_item on an unknown product, must fail""" + obj = None + try: + obj = self.init.cancel_item("1337", "comment") + except ShibaServiceError: + pass + self.assertTrue(obj is None) + + def test_contact_us_about_item(self): + """contact_us_about_item on an unknown product, must fail""" + obj = None + try: + obj = self.init.contact_us_about_item("1337", "message", "1337") + except ShibaServiceError: + pass + self.assertTrue(obj is None) + + def test_contact_user_about_item(self): + """contact_user_about_item on an unknown product, must fail""" + obj = None + try: + obj = self.init.contact_user_about_item("1337", "message") + except ShibaServiceError: + pass + self.assertTrue(obj is None) + + def test_set_tracking_package_infos(self): + """set_tracking_package_infos on an unknown product, must fail. Testing internal error catching as well.""" + obj = None + try: + obj = self.init.set_tracking_package_infos("1337", "UPS", "0000000000") + except ShibaParameterError: + pass + self.assertTrue(obj is None) + try: + obj = self.init.set_tracking_package_infos("1337", "Autre", "0000000000") + except ShibaCallingError: + pass + self.assertTrue(obj is None) + + def test_confirm_preorder(self): + """confirm_preorder on an unknown advert, must fail. Testing internal error catching as well.""" + obj = None + try: + obj = self.init.confirm_preorder("1337", 1) + except ShibaParameterError: + pass + self.assertTrue(obj is None) + try: + obj = self.init.confirm_preorder("1337", -8) + except ShibaCallingError: + pass + self.assertTrue(obj is None) + + def test_wrong_user(self): + wronginstance = SalesManagement(ShibaConnection("test", "test")) + try: + obj = wronginstance.get_new_sales() + except ShibaLoginError: + pass diff --git a/tests/online/test_shibatools.py b/tests/online/test_shibatools.py new file mode 100644 index 0000000..08c8c6a --- /dev/null +++ b/tests/online/test_shibatools.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Class ShibaToolsTest +# Unit tests each reachable method from ShibaTools class + +from __future__ import unicode_literals + +from Shiba.shibatools import ShibaTools +from Shiba.shibaexceptions import * +from Shiba.shibaconnection import ShibaConnection + +import ConfigParser +import os + +import unittest + +class ShibaToolsTest(unittest.TestCase): + def setUp(self): + settings = ConfigParser.ConfigParser() + try: + settings.read(os.path.dirname(os.path.realpath(__file__)) + "/Assets/nosetests.cfg") + except: + raise ShibaCallingError("error : can't read login ID from the nosetests.cfg file") + try: + login = settings.get(str("NoseConfig"), "login") + pwd = settings.get(str("NoseConfig"), "pwd") + except: + raise ShibaCallingError("error : configuration file doesn't seem to be regular") + self.init = ShibaTools() + + def test_retrieve_obj_from_url(self): + """retrieve_obj_from_url test with a remote XML file""" + obj = self.init.retrieve_obj_from_url("http://www.w3schools.com/xml/note.xml") + self.assertTrue("note" in obj.content.tag) + self.assertTrue("to" in obj.content.to.tag and obj.content.to == "Tove") + self.assertTrue("heading" in obj.content.heading.tag and obj.content.heading == "Reminder") + self.assertTrue("body" in obj.content.body.tag and obj.content.body == "Don't forget me this weekend!") + + def test_post_request(self): + """testing a post request with retrieve_obj_from_url""" + ret = self.init.post_request("http://postcatcher.in/catchers/54107375e4a183020000118c", "THIS IS SOME CONTENT") + self.assertTrue(ret == "Created" or "Application Error" in ret) + + def test_create_obj_from_xml(self): + """This function is entirely implicitely tested from the InventoryManagementTest.test_generic_import_file""" + pass + + def test_inf_constructor(self): + connection = ShibaConnection("test", "test") + action = "genericimportreport" + ret = self.init.inf_constructor(connection, action, inf1="info1", inf2="info2") + self.assertTrue("inf1" in ret and "inf2" in ret) + self.assertTrue(ret["inf1"] == "info1" and ret["action"] == "genericimportreport") + + def test_url_constructor(self): + connection = ShibaConnection("test", "test") + action = "genericimportreport" + ret = self.init.inf_constructor(connection, action, inf1="info1", inf2="info2") + url = self.init.url_constructor(connection, ret) + self.assertTrue("https://ws.priceminister.com/stock_ws?pwd=test&version=2011-11-29&action=genericimportreport&" + "login=test&inf2=info2&inf1=info1" == url) \ No newline at end of file