Skip to content

Commit

Permalink
new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
boguta_m committed Dec 10, 2014
1 parent bdb7e9c commit 05a730c
Show file tree
Hide file tree
Showing 38 changed files with 451 additions and 0 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions tests/offline/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__author__ = 'jgriselle'
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions tests/online/Assets/genericimportfile.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<items>
<item>
<attributes>
<advert>
<attribute><key>sellerReference</key><value><![CDATA[SKU1]]></value></attribute>
</advert>
<shipping>
<package_weight>30</package_weight>
</shipping>
</attributes>
</item>
</items>
1 change: 1 addition & 0 deletions tests/online/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__author__ = 'jgriselle'
61 changes: 61 additions & 0 deletions tests/online/test_accountingmanagement.py
Original file line number Diff line number Diff line change
@@ -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)
88 changes: 88 additions & 0 deletions tests/online/test_inventorymanagement.py
Original file line number Diff line number Diff line change
@@ -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)
53 changes: 53 additions & 0 deletions tests/online/test_marketplacemanagement.py
Original file line number Diff line number Diff line change
@@ -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)
172 changes: 172 additions & 0 deletions tests/online/test_salesmanagement.py
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 05a730c

Please sign in to comment.