aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFilipp Lepalaan <filipp@mac.com>2014-05-13 22:02:05 +0300
committerFilipp Lepalaan <filipp@mac.com>2014-05-13 22:02:05 +0300
commit269216c477a8506c529fa83665ec3405fcbaeda7 (patch)
treea7a6fd8da7be982fd1aa20d87d6c21c21e1d1a3b
parent2e8cef4bddba9213495fa8f9fcd4938311ac606f (diff)
downloadpy-gsxws-269216c477a8506c529fa83665ec3405fcbaeda7.tar.gz
py-gsxws-269216c477a8506c529fa83665ec3405fcbaeda7.tar.bz2
py-gsxws-269216c477a8506c529fa83665ec3405fcbaeda7.zip
Fix iOS diagnostics through Product.diagnostics()
-rw-r--r--gsxws/objectify.py8
-rw-r--r--gsxws/products.py6
-rw-r--r--tests/test_gsxws.py17
3 files changed, 28 insertions, 3 deletions
diff --git a/gsxws/objectify.py b/gsxws/objectify.py
index e73adb3..19f6b12 100644
--- a/gsxws/objectify.py
+++ b/gsxws/objectify.py
@@ -9,6 +9,7 @@ from lxml import objectify
from datetime import datetime
DATETIME_TYPES = ('dispatchSentDate',)
+DIAGS_TIMESTAMP_TYPES = ('startTimeStamp', 'endTimeStamp',)
STRING_TYPES = ('alternateDeviceId', 'imeiNumber',)
BASE64_TYPES = ('packingList', 'proformaFileData', 'returnLabelFileData',)
FLOAT_TYPES = ('totalFromOrder', 'exchangePrice', 'stockPrice', 'netPrice',)
@@ -88,6 +89,11 @@ def gsx_timestamp(value):
return datetime.strptime(value, "%m/%d/%y %I:%M %p")
+def gsx_diags_timestamp(value):
+ # It is always in GMT and in format DD-MMM-YY HH24:MM:SS
+ return datetime.strptime(value, "%d-%b-%y %I:%M:%S")
+
+
class GsxElement(objectify.ObjectifiedElement):
"""
Each element in the GSX response tree should be a GsxElement
@@ -121,6 +127,8 @@ class GsxElement(objectify.ObjectifiedElement):
if name in DATETIME_TYPES:
return gsx_datetime(result)
+ if name in DIAGS_TIMESTAMP_TYPES:
+ return gsx_diags_timestamp(result)
if name in BASE64_TYPES:
return gsx_attachment(result)
if name in FLOAT_TYPES:
diff --git a/gsxws/products.py b/gsxws/products.py
index 5b58a23..6be6ace 100644
--- a/gsxws/products.py
+++ b/gsxws/products.py
@@ -113,7 +113,11 @@ class Product(object):
"""
>>> Product('DGKFL06JDHJP').diagnostics()
"""
- diags = Diagnostics(serialNumber=self.serialNumber)
+ diags = Diagnostics(serialNumber=self.sn)
+
+ if hasattr(self, "alternateDeviceId"):
+ diags = Diagnostics(alternateDeviceId=self.alternateDeviceId)
+
return diags.fetch()
def fetch_image(self, url=None):
diff --git a/tests/test_gsxws.py b/tests/test_gsxws.py
index 5012a1b..8ce6328 100644
--- a/tests/test_gsxws.py
+++ b/tests/test_gsxws.py
@@ -6,9 +6,10 @@ from datetime import date, datetime
from unittest import main, skip, TestCase
-from gsxws.objectify import parse
+from gsxws.objectify import parse, gsx_diags_timestamp
from gsxws.products import Product
-from gsxws import repairs, escalations, lookups, GsxError, ServicePart
+from gsxws import (repairs, escalations, lookups,
+ GsxError, ServicePart, diagnostics)
class RemoteTestCase(TestCase):
@@ -211,6 +212,18 @@ class TestWarrantyFunctions(TestCase):
self.assertTrue(self.data.partCovered)
+class TestDiagnostics(RemoteTestCase):
+ def setUp(self):
+ super(TestDiagnostics, self).setUp()
+ self.results = diagnostics.Diagnostics(serialNumber=env['GSX_SN']).fetch()
+
+ def test_diag_result(self):
+ self.assertEqual(self.results.eventHeader.serialNumber, env['GSX_SN'])
+
+ def test_result_timestamp(self):
+ ts = gsx_diags_timestamp(self.results.eventHeader.startTimeStamp)
+ self.assertIsInstance(ts, datetime)
+
class TestOnsiteCoverage(RemoteTestCase):
def setUp(self):
super(TestOnsiteCoverage, self).setUp()