diff options
author | Filipp Lepalaan <filipp@mac.com> | 2015-08-16 22:39:22 +0300 |
---|---|---|
committer | Filipp Lepalaan <filipp@mac.com> | 2015-08-16 22:39:22 +0300 |
commit | ca518df1ac4c08a8d352871fc9aa207443fc5fab (patch) | |
tree | 98fdd07cb7f6491b50d24c649cfa3d9626a86b29 | |
parent | 491d967f2e0d6fc62724746a430fe27a9421e639 (diff) | |
download | py-gsxws-ca518df1ac4c08a8d352871fc9aa207443fc5fab.tar.gz py-gsxws-ca518df1ac4c08a8d352871fc9aa207443fc5fab.tar.bz2 py-gsxws-ca518df1ac4c08a8d352871fc9aa207443fc5fab.zip |
Added workaround for IMEI/SN warranty check
To avoid “Please enter either a serial number or an IMEI number but not
both." in the updated API
-rw-r--r-- | gsxws/core.py | 3 | ||||
-rw-r--r-- | gsxws/products.py | 26 | ||||
-rw-r--r-- | tests/test_gsxws.py | 7 |
3 files changed, 21 insertions, 15 deletions
diff --git a/gsxws/core.py b/gsxws/core.py index 4fd4ee3..086df10 100644 --- a/gsxws/core.py +++ b/gsxws/core.py @@ -119,6 +119,8 @@ def validate(value, what=None): True >>> validate('G143111400', 'dispatchId') True + >>> validate('R164323085', 'dispatchId') + True >>> validate('blaa', 'serialNumber') False >>> validate('MacBook Pro (Retina, Mid 2012)', 'productName') @@ -366,7 +368,6 @@ class GsxObject(object): self.__setattr__(k, v) def __setattr__(self, name, value): - if name.startswith("_"): super(GsxObject, self).__setattr__(name, value) return diff --git a/gsxws/products.py b/gsxws/products.py index 4036bda..d7ef569 100644 --- a/gsxws/products.py +++ b/gsxws/products.py @@ -72,9 +72,11 @@ class Product(object): 'Out Of Warranty (No Coverage)' """ if self.should_check_activation: - self.activation() + ad = self.activation() + # "Please enter either a serial number or an IMEI number but not both." + return Product(ad.serialNumber).warranty() - if ship_to: + if ship_to is not None: self._gsx.shipTo = ship_to try: @@ -85,7 +87,7 @@ class Product(object): except Exception: pass - if date_received: + if date_received is not None: self._gsx.unitReceivedDate = date_received self._gsx._submit("unitDetail", "WarrantyStatus", "warrantyDetailInfo") @@ -135,12 +137,12 @@ class Product(object): """ url = url or self.imageURL - if not url: + if url is None: raise GsxError("No URL to fetch product image") try: return urllib.urlretrieve(url)[0] - except Exception, e: + except Exception as e: raise GsxError("Failed to fetch product image: %s" % e) def activation(self): @@ -156,13 +158,9 @@ class Product(object): GsxError: Provided serial number does not belong to an iOS Device... """ self._gsx._namespace = "glob:" - ad = self._gsx._submit("FetchIOSActivationDetailsRequest", - "FetchIOSActivationDetails", - "activationDetailsInfo") - self.serialNumber = ad.serialNumber - self._gsx.serialNumber = self.serialNumber - return ad - + return self._gsx._submit("FetchIOSActivationDetailsRequest", + "FetchIOSActivationDetails", + "activationDetailsInfo") @property def fmip_status(self, wty=None): @@ -194,6 +192,10 @@ class Product(object): @property def should_check_activation(self): + """ + Returns True if activation check should be run. + This is mainly for WarrantyStatus which does not accept IMEI. + """ return hasattr(self, "alternateDeviceId") and not hasattr(self, "serialNumber") @property diff --git a/tests/test_gsxws.py b/tests/test_gsxws.py index bd2d8b0..07a7ca4 100644 --- a/tests/test_gsxws.py +++ b/tests/test_gsxws.py @@ -305,9 +305,12 @@ class TestRemoteWarrantyFunctions(RemoteTestCase): def test_warranty_lookup(self): self.assertEqual(self.wty.warrantyStatus, 'Out Of Warranty (No Coverage)') + def test_warranty_lookup_imei(self): + wty = Product(env['GSX_IMEI']).warranty() + self.assertEqual(wty.warrantyStatus, 'Out Of Warranty (No Coverage)') + def test_fmip_status(self): - self.assertEqual(self.product.fmip_status, - 'Find My iPhone is active. Find My iPhone must be turned off for whole unit repairs.') + self.assertContains(self.product.fmip_status, 'Find My iPhone is active') def test_fmip_active(self): self.assertTrue(self.product.fmip_is_active) |