From 79e4628a53f1cac06f6426b301dafa1351412702 Mon Sep 17 00:00:00 2001 From: Filipp Lepalaan Date: Fri, 7 Mar 2014 11:16:21 +0200 Subject: Added timestamp datatype, more tests --- gsxws/objectify.py | 7 ++++++- gsxws/products.py | 4 ++-- tests/fixtures/escalation_details_lookup.xml | 29 ++++++++++++++++++++++++++++ tests/test_gsxws.py | 21 +++++++++++++++++++- 4 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 tests/fixtures/escalation_details_lookup.xml diff --git a/gsxws/objectify.py b/gsxws/objectify.py index 3480b70..b37379c 100644 --- a/gsxws/objectify.py +++ b/gsxws/objectify.py @@ -84,7 +84,8 @@ def gsx_datetime(value): def gsx_timestamp(value): - return datetime.strptime(value, "%d-%b-%y %H:%M:%S") + # 03/06/14 09:01 PM + return datetime.strptime(value, "%m/%d/%y %H:%M %p") class GsxElement(objectify.ObjectifiedElement): @@ -126,6 +127,8 @@ class GsxElement(objectify.ObjectifiedElement): return gsx_price(result) if name.endswith('Date'): return gsx_date(result) + if name.endswith('Timestamp'): + return gsx_timestamp(result) if re.search(r'^[YN]$', result): return gsx_boolean(result) @@ -153,8 +156,10 @@ def parse(root, response): return root.find('*//%s' % response) + if __name__ == '__main__': import doctest import logging logging.basicConfig(level=logging.DEBUG) doctest.testmod() + diff --git a/gsxws/products.py b/gsxws/products.py index a9073d6..5b58a23 100644 --- a/gsxws/products.py +++ b/gsxws/products.py @@ -81,7 +81,7 @@ class Product(object): if date_received: self._gsx.unitReceivedDate = date_received - + self._gsx._submit("unitDetail", "WarrantyStatus", "warrantyDetailInfo") self.warrantyDetails = self._gsx._req.objects self.imageURL = self.warrantyDetails.imageURL @@ -186,7 +186,7 @@ class Product(object): @property def is_valid(self): - return self.is_iphone or self.is_ipad or self.is_mac + return self.is_ios or self.is_mac @property def has_warranty(self): diff --git a/tests/fixtures/escalation_details_lookup.xml b/tests/fixtures/escalation_details_lookup.xml new file mode 100644 index 0000000..6aa9335 --- /dev/null +++ b/tests/fixtures/escalation_details_lookup.xml @@ -0,0 +1,29 @@ + + + + + + 4ClHBDHhOL0NWdQMp4XBB + + 2392767 + GSX Help + O + GSX Usage Question + Apple + filipp Lepalaan + 03/06/14 09:01 PM + filipp Lepalaan + 03/06/14 09:06 PM + filipp Lepalaan + 03/06/14 09:02 PM + 4 minutes + + blaa + test + + + + + + + \ No newline at end of file diff --git a/tests/test_gsxws.py b/tests/test_gsxws.py index 3cb1e06..5571c22 100644 --- a/tests/test_gsxws.py +++ b/tests/test_gsxws.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- import logging -from datetime import date from os import environ as env +from datetime import date, datetime from unittest import main, skip, TestCase @@ -29,6 +29,24 @@ class TestCoreFunctions(TestCase): self.assertRegexpMatches(rep.dumps(), 'ääöö') +class TestTypes(TestCase): + def setUp(self): + xml = open('tests/fixtures/escalation_details_lookup.xml', 'r').read() + self.data = parse(xml, 'lookupResponseData') + + def test_unicode(self): + self.assertIsInstance(self.data.lastModifiedBy, unicode) + + def test_timestamp(self): + self.assertIsInstance(self.data.createTimestamp, datetime) + + def test_ts_comp(self): + self.assertGreater(datetime.now(), self.data.createTimestamp) + + def test_list(self): + self.assertIsInstance(self.data.escalationNotes, list) + + class TestErrorFunctions(TestCase): def setUp(self): xml = open('tests/fixtures/multierror.xml', 'r').read() @@ -251,6 +269,7 @@ class TestRepairUpdate(RemoteTestCase): result = self.repair.set_techid('XXXXX') self.assertEqual(result.confirmationNumber, self.dispatchId) + class TestCarryinRepairDetail(TestCase): def setUp(self): self.data = parse('tests/fixtures/repair_details_ca.xml', -- cgit v1.2.3