def test_product_type_template(monkeypatch):
    """product_type_template tests on two scopes, for a fixed alias, plus a fail result"""
    monkeypatch.setattr('requests.get', make_requests_get_mock('sample_getproducttypetemplate.xml'))
    alias = "insolites_produit"
    inventory_management = InventoryManagement(ShibaConnection("test", "test", sandbox=True))
    ptemplate = inventory_management.product_type_template(alias, "")
    assert "producttypetemplateresult" in ptemplate.content.tag
Example #2
0
def test_assert_quota_exeeded(monkeypatch):
    """raises ShibaQuotaExceededError exception"""
    monkeypatch.setattr('shiba.shibatools.post_request', make_simple_text_mock('quota_exceeded_message.xml'))

    connection = ShibaConnection("test", "test")
    inventory = InventoryManagement(connection)
    f = open(op.join(op.dirname(__file__), 'Assets', 'genericimportfile.xml'), 'rb')
    testdict = xmltodict.parse(f)
    with assert_raises(ShibaQuotaExceededError):
        inventory.generic_import_file(data=testdict)
def test_generic_import_file(monkeypatch):
    """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"""

    monkeypatch.setattr('shiba.shibatools.post_request', make_simple_text_mock('sample_genericimportfile.xml'))

    f = open(op.join(op.dirname(__file__), 'Assets', 'genericimportfile.xml'), 'rb')
    testdict = xmltodict.parse(f)
    inventory_management = InventoryManagement(ShibaConnection("test", "test", sandbox=True))
    ret = inventory_management.generic_import_file(testdict)
    assert "OK" == ret.content.response.status

    f = open(op.join(op.dirname(__file__), 'Assets', 'genericimportfile.xml'), 'rb')
    testobj = objectify.parse(f)
    inventory_management = InventoryManagement(ShibaConnection("test", "test", sandbox=True))
    ret = inventory_management.generic_import_file(testobj)
    assert "OK" == ret.content.response.status
 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_export_inventory(monkeypatch):
    monkeypatch.setattr('requests.get', make_requests_get_mock('sample_exportinventory.xml'))
    inventory_management = InventoryManagement(ShibaConnection("test", "test", sandbox=True))
    obj = inventory_management.export_inventory()
    assert "inventoryresult" in obj.content.tag
def test_get_available_shipping_types(monkeypatch):
    monkeypatch.setattr('requests.get', make_requests_get_mock('sample_getavailableshippingtypes.xml'))
    inventory_management = InventoryManagement(ShibaConnection("test", "test", sandbox=True))
    obj = inventory_management.get_available_shipping_types()
    assert "getavailableshippingtypesresult" in obj.content.tag
def test_product_types(monkeypatch):
    monkeypatch.setattr('requests.get', make_requests_get_mock('sample_getproducttypes.xml'))
    inventory_management = InventoryManagement(ShibaConnection("test", "test", sandbox=True))
    ptypes = inventory_management.product_types()
    assert "producttypesresult" in ptypes.content.tag
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.assertIn("producttypesresult", 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.assertIn("producttypetemplateresult", ptemplate.content.tag)
        ptemplate = self.init.product_type_template(alias, "VALUES")
        self.assertIn("producttypetemplateresult", 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.assertEqual("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.assertEqual("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.assertEqual("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):
        """
        This test fails if you do not use a PRO ACCOUNT.
        :return:
        """
        print("This test fails if you do not use a PRO ACCOUNT.")
        obj = self.init.export_inventory()
        self.assertIn("inventoryresult", obj.content.tag)