aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFilipp Lepalaan <f@230.to>2013-09-08 22:34:08 +0300
committerFilipp Lepalaan <f@230.to>2013-09-08 22:34:08 +0300
commitf1e1789e1a9cdebf5268d0fa3dd2846178669777 (patch)
tree965286e26e500854843f4fe095190982bf097b3e
parent56be452b6d8485e598ce9f5a532f5adb548f5c2c (diff)
downloadpy-gsxws-f1e1789e1a9cdebf5268d0fa3dd2846178669777.tar.gz
py-gsxws-f1e1789e1a9cdebf5268d0fa3dd2846178669777.tar.bz2
py-gsxws-f1e1789e1a9cdebf5268d0fa3dd2846178669777.zip
Return None instead of AttributeError
-rw-r--r--gsxws/objectify.py12
-rw-r--r--tests/test_gsxws.py17
2 files changed, 22 insertions, 7 deletions
diff --git a/gsxws/objectify.py b/gsxws/objectify.py
index a1856d9..5658d1a 100644
--- a/gsxws/objectify.py
+++ b/gsxws/objectify.py
@@ -77,13 +77,21 @@ def gsx_timestamp(value):
class GsxElement(objectify.ObjectifiedElement):
def __getattribute__(self, name):
- result = super(GsxElement, self).__getattribute__(name)
+ try:
+ result = super(GsxElement, self).__getattribute__(name)
+ except AttributeError:
+ """
+ The XML returned by GSX can be pretty inconsistent, especially
+ between the different environments. It's therefore more
+ practical to return None than to look for AttributeErrors all
+ over your application...
+ """
+ return
if isinstance(result, objectify.NumberElement):
return result.pyval
if isinstance(result, objectify.StringElement):
-
name = result.tag
result = result.text
diff --git a/tests/test_gsxws.py b/tests/test_gsxws.py
index 1018440..6146a2c 100644
--- a/tests/test_gsxws.py
+++ b/tests/test_gsxws.py
@@ -1,27 +1,28 @@
# -*- coding: utf-8 -*-
-import os
import logging
from datetime import date
+from os import environ as env
+
from unittest import main, skip, TestCase
from gsxws.objectify import parse
from gsxws.products import Product
from gsxws import repairs, escalations
+
class RemoteTestCase(TestCase):
def setUp(self):
from gsxws.core import connect
logging.basicConfig(level=logging.DEBUG)
- env = os.environ
connect(env['GSX_USER'], env['GSX_PASSWORD'], env['GSX_SOLDTO'], env['GSX_ENV'])
+
class TestEscalationFunctions(RemoteTestCase):
@skip("Skip")
def setUp(self):
super(TestEscalationFunctions, self).setUp()
esc = escalations.Escalation()
- env = os.environ
esc.shipTo = env['GSX_SHIPTO']
esc.issueTypeCode = 'WS'
esc.notes = 'This is a test'
@@ -81,6 +82,12 @@ class TestRepairFunctions(TestCase):
rep.create()
+class TestPartFunction(RemoteTestCase):
+ def test_product_parts(self):
+ parts = Product(env['GSX_SN']).parts()
+ self.assertIsInstance(parts[0].partNumber, basestring)
+
+
class TestWarrantyFunctions(TestCase):
def setUp(self):
self.data = parse('tests/fixtures/warranty_status.xml',
@@ -103,7 +110,7 @@ class TestWarrantyFunctions(TestCase):
class TestOnsiteCoverage(RemoteTestCase):
def setUp(self):
super(TestOnsiteCoverage, self).setUp()
- self.product = Product('XXXXXXXXXXX')
+ self.product = Product(env['GSX_SN'])
self.product.warranty()
def test_has_onsite(self):
@@ -128,7 +135,7 @@ class TestActivation(TestCase):
self.assertIs(type(self.data.unlocked), bool)
self.assertTrue(self.data.unlocked)
- p = Product('XXXXXXXXXXX')
+ p = Product(env['GSX_SN'])
self.assertTrue(p.is_unlocked(self.data))