From f438b1221354469a9ce50f591eba7272f2698526 Mon Sep 17 00:00:00 2001 From: Filipp Lepalaan Date: Sat, 28 Apr 2018 16:35:19 +0300 Subject: Initial commit --- .gitignore | 2 + LICENSE | 25 +++++++ README.md | 81 +++++++++++++++++++++++ requirements.pip | 1 + responses/AcknowledgeCommunication.xml | 18 +++++ responses/Authenticate.xml | 11 ++++ responses/ComponentCheck.xml | 18 +++++ responses/ComptiaCodeLookup.xml | 52 +++++++++++++++ responses/CreateCarryIn.xml | 53 +++++++++++++++ responses/CreateGeneralEscalation.xml | 14 ++++ responses/CreateMailInRepair.xml | 53 +++++++++++++++ responses/CreateRepairOrReplace.xml | 62 +++++++++++++++++ responses/CreateWholeUnitExchange.xml | 48 ++++++++++++++ responses/FetchCommunicationArticles.xml | 31 +++++++++ responses/FetchCommunicationContent.xml | 34 ++++++++++ responses/FetchDiagnosticConsoleURL.xml | 17 +++++ responses/FetchDiagnosticDetails.xml | 99 ++++++++++++++++++++++++++++ responses/FetchDiagnosticSuites.xml | 23 +++++++ responses/GeneralEscalationDetailsLookup.xml | 53 +++++++++++++++ responses/InitiateIOSDiagnostic.xml | 15 +++++ responses/MarkRepairComplete.xml | 28 ++++++++ responses/PartsLookup.xml | 70 ++++++++++++++++++++ responses/ReportedSymptomIssue.xml | 30 +++++++++ responses/RunDiagnosticTest.xml | 16 +++++ responses/UpdateCarryIn.xml | 43 ++++++++++++ responses/UpdateGeneralEscalation.xml | 14 ++++ responses/WarrantyStatus.xml | 67 +++++++++++++++++++ serve.py | 77 ++++++++++++++++++++++ 28 files changed, 1055 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 requirements.pip create mode 100644 responses/AcknowledgeCommunication.xml create mode 100644 responses/Authenticate.xml create mode 100644 responses/ComponentCheck.xml create mode 100644 responses/ComptiaCodeLookup.xml create mode 100644 responses/CreateCarryIn.xml create mode 100644 responses/CreateGeneralEscalation.xml create mode 100644 responses/CreateMailInRepair.xml create mode 100644 responses/CreateRepairOrReplace.xml create mode 100644 responses/CreateWholeUnitExchange.xml create mode 100644 responses/FetchCommunicationArticles.xml create mode 100644 responses/FetchCommunicationContent.xml create mode 100644 responses/FetchDiagnosticConsoleURL.xml create mode 100644 responses/FetchDiagnosticDetails.xml create mode 100644 responses/FetchDiagnosticSuites.xml create mode 100644 responses/GeneralEscalationDetailsLookup.xml create mode 100644 responses/InitiateIOSDiagnostic.xml create mode 100644 responses/MarkRepairComplete.xml create mode 100644 responses/PartsLookup.xml create mode 100644 responses/ReportedSymptomIssue.xml create mode 100644 responses/RunDiagnosticTest.xml create mode 100644 responses/UpdateCarryIn.xml create mode 100644 responses/UpdateGeneralEscalation.xml create mode 100644 responses/WarrantyStatus.xml create mode 100755 serve.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..270cfe9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.env +.env2 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..2f3bfa4 --- /dev/null +++ b/LICENSE @@ -0,0 +1,25 @@ +BSD 2-Clause License + +Copyright (c) 2018, Filipp Lepalaan +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..e726f77 --- /dev/null +++ b/README.md @@ -0,0 +1,81 @@ +Introduction +============ + +`gsx-mockserver` is a mock version of the GSX SOAP API. It can be used for testing your GSX integration code or hosting demo environments, for example allowing you to test GSX-API functionality even if you don't have the necessary SSL certificates and firewall whitelistings for GSX access. + +The mock responses are collected from example XML snippets in Apple's [API documentation][apidocs] and is therefore by no means exhaustive and 1:1 accurate, but it's definitely better than nothing and much faster to develop against than using the actual API test environments. + + +Installation +============ + +The server has only one external dependency - `lxml` which is used to parse the request XML. It should work with both Python 3 and 2, but is primarily developed and tested on 3. + + $ pip install lxml + $ python serve.py + Validating XML responses... + GSX mock server serving on http://localhost:8080 + +You can also specify the port and address to serve on with the `-p` and `-a` arguments - check `-h` for the details. + +Usage +===== + +Simply point your GSX client code to the server you just started. The most traight-forward method would probably be to replace the API URL in your code. + +If you're using [py-gsxws](https://github.com/filipp/py-gsxws), then you can simply point your GSX client to use the mock server by setting the `GSX_URL` environment variable to the URL of the mock server: + + GSX_URL=http://localhost:8080 python my_gsx_code_using_pygsxws.py + + +Variable reflection +=================== + +The mock server has a simple mechanism which can replace values in the response XML with values in the request allowing you to run tests that expect a certain value in the response. For example, if you're testing the "Mark Repair Complete" endpoint, it would be reasonable to expect the same repair dispatch ID to appear in the confirmation response that was sent in the request. To make this work, simply use a Python template placeholder inside the response XML file - naming it after the request parameter you want to use. For example, sending a `MarkRepairComplete` request such as this: + +```xml + + + Sdt7tXp2XytTEVwHBeDx6lHTXI3w9s+M + + 123456 + 123456 + + +``` + +would result in the following response: + +```xml + + ykNJV0zy368v5uqnUYthI63zNSeip8/J + + 123456 + STOP/HOLD + Some Message1 + Some Message2 + + + 123456 + HOLD + Some Message1 + Some Message2 + + + 123456 + HOLD + Some Message1 + Some Message2 + +ionNumber>123456 +``` + +Please note that due to inconsistencies in the response schema, this feature doesn't work with every request type. + +Development +=========== + +If you run into an API call that the mock server cannot handle (resulting in a 404 response), just go to the [API docs][apidocs], find the example XML for the relevant call and copy/paste it into `responses/$SOAPAction.xml` where `$SOAPAction` equals the value of the `SOAPAction`header of the sent request (excluding the double quotes, for example Authenticate, MarkRepairComplete, UpdateCarryIn, etc) + +[apidocs]: https://gsxapiut.apple.com/apidocs/ut/html/WSReference.html?user=asp + diff --git a/requirements.pip b/requirements.pip new file mode 100644 index 0000000..ab90481 --- /dev/null +++ b/requirements.pip @@ -0,0 +1 @@ +lxml diff --git a/responses/AcknowledgeCommunication.xml b/responses/AcknowledgeCommunication.xml new file mode 100644 index 0000000..4e11447 --- /dev/null +++ b/responses/AcknowledgeCommunication.xml @@ -0,0 +1,18 @@ + + + + + + + 1234 + + + SN34 + Y + + + + + + diff --git a/responses/Authenticate.xml b/responses/Authenticate.xml new file mode 100644 index 0000000..856727a --- /dev/null +++ b/responses/Authenticate.xml @@ -0,0 +1,11 @@ + + + + + + teHHI9DcQcLsTBtI7+jdLqmOFqFrRaMZ + Sdt7tXp2XytTEVwHBeDx6lHTXI3w9s+M + + + + diff --git a/responses/ComponentCheck.xml b/responses/ComponentCheck.xml new file mode 100644 index 0000000..27a8c79 --- /dev/null +++ b/responses/ComponentCheck.xml @@ -0,0 +1,18 @@ + + + + + + 170ae1310160353346 + + + MLB + Logic Board + + G153220777 + Y + + + + + diff --git a/responses/ComptiaCodeLookup.xml b/responses/ComptiaCodeLookup.xml new file mode 100644 index 0000000..0693673 --- /dev/null +++ b/responses/ComptiaCodeLookup.xml @@ -0,0 +1,52 @@ + + + + + + K7/KdqKveTGrWj3d1a+ZnvCHSgGXcnTF + + + 1 + Visual + + X01 + Memory Module (RAM) - Kernel Panic + + + X02 + Memory Module (RAM) - No Boot + + + X03 + Cables - Defective + + + X04 + Remote - Inoperable + + + X05 + Remote - Battery Life Too Short + + + X06 + Memory Module (RAM) - Issues + + + + Not Applicable + A + + + Continuous + B + + + Intermittent + C + + + + + + diff --git a/responses/CreateCarryIn.xml b/responses/CreateCarryIn.xml new file mode 100644 index 0000000..7685ba1 --- /dev/null +++ b/responses/CreateCarryIn.xml @@ -0,0 +1,53 @@ + + + + + + teHHI9DcQcLsTBtI7+jdLqmOFqFrRaMZ + + G112477331 + Diagnostic Code Not Entered + 800204262010153816 + FAILED + + + BRL + BRL 23.50 + 076-1080 + + 1 + + + + BRL + BRL 11.50 + 661-3226 + + 1 + + USD 38.00 + 3.00 + 3.00 + 3.00 + 3.00 + 2.00 + 2.00 + 3.00 + STOP/HOLD/MSG + The repair would go on Component Check Review. + Your accidental damage coverage under the AppleCare+ + contract will be reduced by one incident, but you will not incur a fee + for this repair. + + + Return Before Replace + + + Mail-in + + + + + + + diff --git a/responses/CreateGeneralEscalation.xml b/responses/CreateGeneralEscalation.xml new file mode 100644 index 0000000..1453625 --- /dev/null +++ b/responses/CreateGeneralEscalation.xml @@ -0,0 +1,14 @@ + + + + + + 9a55f1310158234234 + + 802714 + 2011-07-08 00:00:00 UTC + + + + + diff --git a/responses/CreateMailInRepair.xml b/responses/CreateMailInRepair.xml new file mode 100644 index 0000000..4787f00 --- /dev/null +++ b/responses/CreateMailInRepair.xml @@ -0,0 +1,53 @@ + + + + + + teHHI9DcQcLsTBtI7+jdLqmOFqFrRaMZ + + G112477331 + Diagnostic Code Not Entered + 800204262010153816 + FAILED + + + BRL + BRL 11.50 + 661-7654 + + 1 + + BRL 38.00 + 3.00 + 3.00 + 3.00 + 3.00 + 2.00 + 2.00 + 3.00 + + Madera + MEMPHIS + AI + United States + TN + 6380 HOLMES ROAD + FLEXTRONICS + 38141 + + STOP/HOLD/MSG + Some message1 + Some message2 + + + Return Before Replace + + + Mail-in + + + + + + + diff --git a/responses/CreateRepairOrReplace.xml b/responses/CreateRepairOrReplace.xml new file mode 100644 index 0000000..8c14ceb --- /dev/null +++ b/responses/CreateRepairOrReplace.xml @@ -0,0 +1,62 @@ + + + + + + 734d2c566e1280959479183 + + G245605424 + + Internal Acct for for Ceva RC - AU + Unit 9, Discovery Cove,1801, B + Madera + Banksmeadow + NSW + Australia + 2019 + Apple + + BRL 0.00 + 3.00 + 3.00 + 3.00 + 3.00 + 2.00 + 2.00 + 0.0 + + S3750LL/A + Other + BRL 0.00 + BRL + Y + 1> + + + S3750LL/A + + + + 895642387834567 + FAILED + STOP/HOLD/MSG + Some Message1 + Some Message2 + + + Return Before Replace + + + Mail-in + + + + + + + diff --git a/responses/CreateWholeUnitExchange.xml b/responses/CreateWholeUnitExchange.xml new file mode 100644 index 0000000..4a2ea05 --- /dev/null +++ b/responses/CreateWholeUnitExchange.xml @@ -0,0 +1,48 @@ + + + + + + 79ebc1310162214229 + + G200404764 + BRL 355.95 + BRL 3.00 + BRL 3.00 + BRL 3.00 + BRL 3.00 + BRL 2.00 + BRL 2.00 + 0.0 + + 661-5571 + + BRL 349.00 + BRL + + 1 + + + ACSH08 + + BRL 6.95 + BRL + + 1 + + STOP/HOLD + Some Message1 + Some Message2 + + + Return Before Replace + + + Mail-in + + + + + + + diff --git a/responses/FetchCommunicationArticles.xml b/responses/FetchCommunicationArticles.xml new file mode 100644 index 0000000..1c74f74 --- /dev/null +++ b/responses/FetchCommunicationArticles.xml @@ -0,0 +1,31 @@ + + + + + + + 1234 + + SN642 + + Always Reset the PRAM Before Using the Graphics Processor Test + + +

As a reminder, reset the PRAM before using the + Graphics Processor Test. Failure to do so could result in false + errors and incorrect reports of Dead on Arrival (DOA) + logic boards.

+
+ Medium + 02/13/11 + Y + 02/15/11 + N + TECHNICIAN + MANAGER +
+
+
+
+
diff --git a/responses/FetchCommunicationContent.xml b/responses/FetchCommunicationContent.xml new file mode 100644 index 0000000..44e87f7 --- /dev/null +++ b/responses/FetchCommunicationContent.xml @@ -0,0 +1,34 @@ + + + + + + + 1234 + + + Always Reset the PRAM Before Using the Graphics Processor Test + + +

As a reminder, reset the PRAM before using the + Graphics Processor Test. Failure to do so could result in false + errors and incorrect reports of Dead on Arrival (DOA) + logic boards.

+
+ Some big HTML content + Medium + + TECHNICIAN + MANAGER + + IMAC + 3EH + iMac (20-inch, Early 2009) + + en +
+
+
+
+
diff --git a/responses/FetchDiagnosticConsoleURL.xml b/responses/FetchDiagnosticConsoleURL.xml new file mode 100644 index 0000000..b5b6b72 --- /dev/null +++ b/responses/FetchDiagnosticConsoleURL.xml @@ -0,0 +1,17 @@ + + + + + + + 123456 + + https://diagnostics.apple.com + + + + + + + diff --git a/responses/FetchDiagnosticDetails.xml b/responses/FetchDiagnosticDetails.xml new file mode 100644 index 0000000..6e06f6b --- /dev/null +++ b/responses/FetchDiagnosticDetails.xml @@ -0,0 +1,99 @@ + + + + + + + + + + + Serial Number + C02DN8KJDHJF + + + Diagnostic Event Number + 47165961006635015191936 + + + Event Start Date + 16-JAN-15 06:43:58 + + + Event Completion Date + 16-JAN-15 06:43:58 + + + Service Account ID + 0000053729 + + + Shp-To + 0000053729 + + + modulePassCount + 56 + + + Suite Name + Mobile Resource Inspector + + + Requested Channel + GSX + + + Diagnostic Event End Result + WARNING + + + + + Checksum Test + PASSED + BootROM + BootROM + + + FW GUID MAC Address Checksum Tes + PASSED + BootROM + BootROM + + + Sensor Check Test + PASSED + SMC + SMC + + + Link Speed Verify Test + WARNING + WiFi + WiFi + + + Presence Test + PASSED + EthernetController + EthernetController + + + + MAC + + Current OS Version + 10.8.2 + + + Hardware Model + iMac14,4 + + + + There are priority messages pending + + + + \ No newline at end of file diff --git a/responses/FetchDiagnosticSuites.xml b/responses/FetchDiagnosticSuites.xml new file mode 100644 index 0000000..16b6a71 --- /dev/null +++ b/responses/FetchDiagnosticSuites.xml @@ -0,0 +1,23 @@ + + + + + + + 123456 + + + 1234 + Mac Resource Inspector + + + 5678 + Quick Test + + + + + + + diff --git a/responses/GeneralEscalationDetailsLookup.xml b/responses/GeneralEscalationDetailsLookup.xml new file mode 100644 index 0000000..cded0cf --- /dev/null +++ b/responses/GeneralEscalationDetailsLookup.xml @@ -0,0 +1,53 @@ + + + + + + 0b8591308861450587 + + 785749 + GSX Help + + 1 + GB020N5TZ3A + + OPEN + Account Management Question + Apple + dummy tester + 08/24/12 09:48 AM + global AdminP1 + dummy tester + 1day 4hours 7minutes + + 10000144395733 + Repair Extension Program Issue + + CUSTOMER: GSX Tech AMR + Activation Issues on iOS Devices After Repair + Has the repair been marked complete? + + + + MY NOTES HERE + + + + Sam: Thanks for contacting the RTC. My name is Sam. How can I help you today? + GSX Tech AMR: Hello! + GSX Tech AMR:I'm having some issue repairing a device + Sam: Sure. How can I help you today + + + TEMS AC User1: Thanks for contacting Agreement Admin. My name is TEMS AC User1. How can I help you? + GSX Tech AMR: Hello! + GSX Tech AMR:I'm having some issue running diagnostic in a device. + TEMS AC User1: Sure. + GSX Tech AMR: Thanks for assisting me in this issue + + + + + + + diff --git a/responses/InitiateIOSDiagnostic.xml b/responses/InitiateIOSDiagnostic.xml new file mode 100644 index 0000000..60fe3cc --- /dev/null +++ b/responses/InitiateIOSDiagnostic.xml @@ -0,0 +1,15 @@ + + + + + + + 5522d3445672222f + + 1234567890 + + + + + diff --git a/responses/MarkRepairComplete.xml b/responses/MarkRepairComplete.xml new file mode 100644 index 0000000..9b2f399 --- /dev/null +++ b/responses/MarkRepairComplete.xml @@ -0,0 +1,28 @@ + + + + + + ykNJV0zy368v5uqnUYthI63zNSeip8/J + + $dispatchId + STOP/HOLD + Some Message1 + Some Message2 + + + $dispatchId + HOLD + Some Message1 + Some Message2 + + + $dispatchId + HOLD + Some Message1 + Some Message2 + + + + + diff --git a/responses/PartsLookup.xml b/responses/PartsLookup.xml new file mode 100644 index 0000000..a29d01f --- /dev/null +++ b/responses/PartsLookup.xml @@ -0,0 +1,70 @@ + + + + + + AnK6lhP8j4Zw8hHYswYMGCthSKGnzy9O + + HG7F + N + CON7 + 32GB, Black, GSM, iPhone 7, CI/AR + 661-05427 + Module + + + BATTR + Battery Only Price + 129 + + + DSPLY + Display Only Price + 109 + + + B + + + DC18,DC19 + Y + + SVC,REMOTE + 661-4448 + Module + 5 + 661-2549 + + + 59T + Y + + Power Adapter w/Plug, Ultra-Compact, USB, iPhone/iPod-US/CAN/JPN/TWN + 661-4954 + Module + 3 + + + + + N + + SVC,STEREO HEADSET + 661-5028 + Module + 6 + 922-8629 + + + HG7F + N + CON7 + 32GB, Black, GSM, iPhone 7, CI/AR + 661-05427 + Module + B + + + + + diff --git a/responses/ReportedSymptomIssue.xml b/responses/ReportedSymptomIssue.xml new file mode 100644 index 0000000..f276181 --- /dev/null +++ b/responses/ReportedSymptomIssue.xml @@ -0,0 +1,30 @@ + + + + + + 170ae1310160353346 + + + IP022 + Bluetooth + + + IP025 + Wi-Fi + + + + + 26092 + Apps + + + 26094 + Bluetooth/Wi-Fi + + + + + + \ No newline at end of file diff --git a/responses/RunDiagnosticTest.xml b/responses/RunDiagnosticTest.xml new file mode 100644 index 0000000..072e4f3 --- /dev/null +++ b/responses/RunDiagnosticTest.xml @@ -0,0 +1,16 @@ + + + + + + + 123456 + + + + + + + + diff --git a/responses/UpdateCarryIn.xml b/responses/UpdateCarryIn.xml new file mode 100644 index 0000000..18bb07a --- /dev/null +++ b/responses/UpdateCarryIn.xml @@ -0,0 +1,43 @@ + + + + + + 620271310148985581 + + $repairConfirmationNumber + BRL 0.00 + 3.00 + 3.00 + 3.00 + 3.00 + 2.00 + 2.00 + 0.0 + + 661-5000 + + BRL 0.00 + BRL + + 1 + + + 661-5321 + + BRL 0.00 + BRL + + 1 + + 895642387834567 + FAILED + STOP/HOLD/MSG + Some Message1 + Some Message2 + + + + + + diff --git a/responses/UpdateGeneralEscalation.xml b/responses/UpdateGeneralEscalation.xml new file mode 100644 index 0000000..0b18250 --- /dev/null +++ b/responses/UpdateGeneralEscalation.xml @@ -0,0 +1,14 @@ + + + + + + 91f5a1310158382330 + + SUCCESS + 12/18/12 11:10 AM + + + + + diff --git a/responses/WarrantyStatus.xml b/responses/WarrantyStatus.xml new file mode 100644 index 0000000..5f85da1 --- /dev/null +++ b/responses/WarrantyStatus.xml @@ -0,0 +1,67 @@ + + + + + + 5fdef1309390619199 + + $serialNumber + Out Of Warranty (No Coverage) + 08/24/11 + 08/25/10 + 0 + 08/25/10 + + United States + 08/25/10 + + + + iPhone 4 + IPHONE 4,16GB BLACK + + + + + + + + Y + Y + Y + + + Y + Y + Available + Find My iPhone is Active. Find My iPhone must be turned off for Whole Unit Repairs. + + RFD + Y + NEW + + Some Message1 + Some Message2 + + Return Before Replace + Mail-in + + + APP FOR RUBIX + + + AppleCare+ Battery Only Repair + USD 49.00 + + + AppleCare+ Display Only Repair + USD 69.00 + + + + + + + + + diff --git a/serve.py b/serve.py new file mode 100755 index 0000000..433e740 --- /dev/null +++ b/serve.py @@ -0,0 +1,77 @@ +#!/usr/bin/env python + +import os +import argparse +from glob import glob +from io import BytesIO +from string import Template + +try: + from http.server import BaseHTTPRequestHandler, HTTPServer +except ImportError: + from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer + +from lxml import etree + + +class Handler(BaseHTTPRequestHandler): + + def do_POST(self): + assert self.headers['SOAPAction'], 'Invalid request' + + self.action = self.headers['SOAPAction'].strip('"') + self.path = 'responses/%s.xml' % self.action + self.log_message(self.action) + + if not os.path.exists(self.path): + msg = 'Sorry, unkown action %s' % self.action + self.send_error(404, msg) + return + + self.send_response(200) + l = int(self.headers['Content-Length']) + request = etree.parse(BytesIO(self.rfile.read(l))) + + print(etree.tostring(request, pretty_print=True).decode()) + + context = {} + r = request.xpath('//repairData|//requestData|//MarkRepairCompleteRequest') + + if r: + for i in r[0].iterchildren(): + context[i.tag] = i.text + + self.send_header('Content-Type', 'text/xml; charset="UTF-8"') + self.end_headers() + + with open(self.path, 'r') as f: + xml = f.read() + xml = Template(xml).safe_substitute(context) + self.send_header('Content-Length', len(xml)) + self.wfile.write(xml.encode()) + print(xml) + + +def validate_responses(): + for r in glob('responses/*.xml'): + try: + etree.parse(r) + except etree.XMLSyntaxError: + raise Exception('Invalid XML response: %s' % r) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser = argparse.ArgumentParser() + parser.add_argument('-a', '--address', + help='Address to host server on', default='localhost') + parser.add_argument('-p', '--port', + help='Port number to host server on', default=8080, type=int) + args = parser.parse_args() + + print('Validating XML responses...') + validate_responses() + + with HTTPServer((args.address, args.port), Handler) as httpd: + print('GSX mock server serving on http://%s:%d' % (args.address, args.port)) + httpd.serve_forever() -- cgit v1.2.3