aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFilipp Lepalaan <f@230.to>2013-02-12 18:03:43 +0200
committerFilipp Lepalaan <f@230.to>2013-02-12 18:03:43 +0200
commit96b86337a32098d5c320b76c9505f40995d4e385 (patch)
tree390f13fd513bb33350e58d06a10b7786fb61fed1
parent8407948f622c3434373fbd9884a6706a3c904577 (diff)
downloadpy-gsxws-96b86337a32098d5c320b76c9505f40995d4e385.tar.gz
py-gsxws-96b86337a32098d5c320b76c9505f40995d4e385.tar.bz2
py-gsxws-96b86337a32098d5c320b76c9505f40995d4e385.zip
Coerce boolean to and from Y/N
-rwxr-xr-xgsxws.py10
-rw-r--r--tests/create_carryin_repair.json67
2 files changed, 42 insertions, 35 deletions
diff --git a/gsxws.py b/gsxws.py
index 740000a..4116fd9 100755
--- a/gsxws.py
+++ b/gsxws.py
@@ -264,6 +264,10 @@ class GsxResponse(dict):
if re.search('TimeStamp$', k):
v = datetime.strptime(v, '%d-%b-%y %H:%M:%S')
+ # convert Y and N to corresponding boolean
+ if re.search('^[YN]$', k):
+ v = (v == 'Y')
+
nodedict[k] = v
return nodedict
@@ -441,12 +445,14 @@ class Repair(GsxObject):
super(Repair, self).__init__(*args, **kwargs)
formats = get_format()
- # native date types are not welcome here :)
+ # native types are not welcome here :)
for k, v in kwargs.items():
if isinstance(v, date):
kwargs[k] = v.strftime(formats['df'])
if isinstance(v, time):
kwargs[k] = v.strftime(formats['tf'])
+ if isinstance(v, bool):
+ kwargs[k] = 'Y' if v else 'N'
self.data = kwargs
@@ -457,6 +463,7 @@ class Repair(GsxObject):
"""
dt = self._make_type('ns2:carryInRequestType')
dt.repairData = self.data
+
result = CLIENT.service.CreateCarryInRepair(dt)
return result.repairConfirmation
@@ -689,6 +696,7 @@ if __name__ == '__main__':
#f = 'tests/update_escalation.json'
fp = open(f, 'r')
data = json.load(fp)
+ data['requestReviewByApple'] = False
rep = Repair(**data)
print rep.create_carryin()
diff --git a/tests/create_carryin_repair.json b/tests/create_carryin_repair.json
index 56ce4e0..0e90c20 100644
--- a/tests/create_carryin_repair.json
+++ b/tests/create_carryin_repair.json
@@ -1,36 +1,35 @@
{
- "shipTo": "677592",
- "requestReviewByApple": "N",
- "serialNumber": "C3TFJJTNDCP9",
- "symptom": "Does not work",
- "diagnosis": "Does not work",
- "unitReceivedDate": "02/10/13",
- "unitReceivedTime": "12:00 AM",
- "checkIfOutOfWarrantyCoverage": "N",
- "overrideDiagnosticCodeCheck": "Y",
- "poNumber": "Order12341",
- "orderLines": [
- {
- "partNumber": "FD661-6136",
- "comptiaCode": "T03",
- "comptiaModifier": "B",
- "abused": "Y",
- "outOfWarrantyFlag": "N",
- "diagnosticCode": ""
- }
- ],
- "customerAddress": {
- "addressLine1": "Address line 1",
- "country": "FI",
- "zipCode": "95014",
- "regionCode": "005",
- "city": "Cupertino",
- "state": "ZZ",
- "street": "Valley Green Dr",
- "firstName": "First",
- "lastName": "Last",
- "companyName": "Apple Inc",
- "primaryPhone": "4088887766",
- "emailAddress": "abc@test.com"
- }
+ "shipTo": "677592",
+ "serialNumber": "C3TFJJTNDCP9",
+ "symptom": "Does not work",
+ "diagnosis": "Does not work",
+ "unitReceivedDate": "02/10/13",
+ "unitReceivedTime": "12:00 AM",
+ "checkIfOutOfWarrantyCoverage": "N",
+ "overrideDiagnosticCodeCheck": "Y",
+ "poNumber": "Order12341",
+ "orderLines": [
+ {
+ "partNumber": "FD661-6136",
+ "comptiaCode": "T03",
+ "comptiaModifier": "B",
+ "abused": "Y",
+ "outOfWarrantyFlag": "N",
+ "diagnosticCode": ""
+ }
+ ],
+ "customerAddress": {
+ "addressLine1": "Address line 1",
+ "country": "FI",
+ "zipCode": "95014",
+ "regionCode": "005",
+ "city": "Cupertino",
+ "state": "ZZ",
+ "street": "Valley Green Dr",
+ "firstName": "First",
+ "lastName": "Last",
+ "companyName": "Apple Inc",
+ "primaryPhone": "4088887766",
+ "emailAddress": "abc@test.com"
+ }
}