diff options
28 files changed, 1055 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..270cfe9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.env +.env2 @@ -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 +<MarkRepairCompleteRequest> + <userSession> + <userSessionId>Sdt7tXp2XytTEVwHBeDx6lHTXI3w9s+M</userSessionId> + </userSession> + <repairConfirmationNumbers>123456</repairConfirmationNumbers> + <dispatchId>123456</dispatchId> + </MarkRepairCompleteRequest> +</asp:MarkRepairComplete> +``` + +would result in the following response: + +```xml +<MarkRepairCompleteResponse> + <operationId>ykNJV0zy368v5uqnUYthI63zNSeip8/J</operationId> + <repairConfirmationNumbers> + <repairConfirmationNumber>123456</repairConfirmationNumber> + <outcome>STOP/HOLD</outcome> + <messages>Some Message1</messages> + <messages>Some Message2</messages> + </repairConfirmationNumbers> + <repairConfirmationNumbers> + <repairConfirmationNumber>123456</repairConfirmationNumber> + <outcome>HOLD</outcome> + <messages>Some Message1</messages> + <messages>Some Message2</messages> + </repairConfirmationNumbers> + <repairConfirmationNumbers> + <repairConfirmationNumber>123456</repairConfirmationNumber> + <outcome>HOLD</outcome> + <messages>Some Message1</messages> + <messages>Some Message2</messages> + </repairConfirmationNumbers> +</MarkRepairCompleteResponse>ionNumber>123456</repairConfirmationNumber> +``` + +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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" + xmlns:glob="http://gsxws.apple.com/elements/global"> + <soapenv:Header/> + <soapenv:Body> + <glob:AcknowledgeCommunicationResponse> + <AcknowledgeCommunicationResponse> + <operationId>1234</operationId> + <communicationResponse> + <acknowledgementStatus> + <articleID>SN34</articleID> + <acknowledgeStatus>Y</acknowledgeStatus> + </acknowledgementStatus> + </communicationResponse> + </AcknowledgeCommunicationResponse> + </glob:AcknowledgeCommunicationResponse> + </soapenv:Body> +</soapenv:Envelope> 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> + <S:Body> + <ns1:AuthenticateResponse xmlns:ns1="http://gsxws.apple.com/elements/global"> + <AuthenticateResponse> + <operationId>teHHI9DcQcLsTBtI7+jdLqmOFqFrRaMZ</operationId> + <userSessionId>Sdt7tXp2XytTEVwHBeDx6lHTXI3w9s+M</userSessionId> + </AuthenticateResponse> + </ns1:AuthenticateResponse> + </S:Body> +</S:Envelope> 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> + <S:Body> + <ns3:ComponentCheckResponse xmlns:ns2="http://asp.core.endpoint.ws.gsx.ist.apple.com/" xmlns:ns3="http://gsxws.apple.com/elements/core/asp" xmlns:ns4="http://gsxws.apple.com/elements/global" xmlns:ns5="http://gsxws.apple.com/elements/core/asp/am" xmlns:ns6="http://gsxws.apple.com/elements/core"> + <ComponentCheckResponse> + <operationId>170ae1310160353346</operationId> + <componentCheckDetails> + <componentDetails> + <componentCode>MLB</componentCode> + <componentDescription>Logic Board</componentDescription> + </componentDetails> + <dispatchID>G153220777</dispatchID> + <eligibility>Y</eligibility> + </componentCheckDetails> + </ComponentCheckResponse> + </ns3:ComponentCheckResponse> + </S:Body> +</S:Envelope> 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> + <S:Body> + <ns5:ComptiaCodeLookupResponse xmlns:ns5="http://gsxws.apple.com/elements/global"> + <ComptiaCodeLookupResponse> + <operationId>K7/KdqKveTGrWj3d1a+ZnvCHSgGXcnTF</operationId> + <comptiaInfo> + <comptiaGroup> + <componentId>1</componentId> + <componentName>Visual</componentName> + <comptiaCodeInfo> + <comptiaCode>X01</comptiaCode> + <comptiaDescription>Memory Module (RAM) - Kernel Panic</comptiaDescription> + </comptiaCodeInfo> + <comptiaCodeInfo> + <comptiaCode>X02</comptiaCode> + <comptiaDescription>Memory Module (RAM) - No Boot</comptiaDescription> + </comptiaCodeInfo> + <comptiaCodeInfo> + <comptiaCode>X03</comptiaCode> + <comptiaDescription>Cables - Defective</comptiaDescription> + </comptiaCodeInfo> + <comptiaCodeInfo> + <comptiaCode>X04</comptiaCode> + <comptiaDescription>Remote - Inoperable</comptiaDescription> + </comptiaCodeInfo> + <comptiaCodeInfo> + <comptiaCode>X05</comptiaCode> + <comptiaDescription>Remote - Battery Life Too Short</comptiaDescription> + </comptiaCodeInfo> + <comptiaCodeInfo> + <comptiaCode>X06</comptiaCode> + <comptiaDescription>Memory Module (RAM) - Issues</comptiaDescription> + </comptiaCodeInfo> + </comptiaGroup> + <comptiaModifier> + <comptiaDescription>Not Applicable</comptiaDescription> + <modifierCode>A</modifierCode> + </comptiaModifier> + <comptiaModifier> + <comptiaDescription>Continuous</comptiaDescription> + <modifierCode>B</modifierCode> + </comptiaModifier> + <comptiaModifier> + <comptiaDescription>Intermittent</comptiaDescription> + <modifierCode>C</modifierCode> + </comptiaModifier> + </comptiaInfo> + </ComptiaCodeLookupResponse> + </ns5:ComptiaCodeLookupResponse> + </S:Body> +</S:Envelope> 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> + <S:Body> + <ns4:CreateCarryInResponse xmlns:ns4="http://gsxws.apple.com/types/core/asp"> + <CreateCarryInResponse> + <operationId>teHHI9DcQcLsTBtI7+jdLqmOFqFrRaMZ</operationId> + <repairConfirmation> + <confirmationNumber>G112477331</confirmationNumber> + <diagnosticDescription>Diagnostic Code Not Entered</diagnosticDescription> + <diagnosticEventNumber>800204262010153816</diagnosticEventNumber> + <diagnosticEventEndResult>FAILED</diagnosticEventEndResult> + <parts> + <availability/> + <currency>BRL</currency> + <netPrice>BRL 23.50</netPrice> + <partNumber>076-1080</partNumber> + <partType/> + <quantity>1</quantity> + </parts> + <parts> + <availability/> + <currency>BRL</currency> + <netPrice>BRL 11.50</netPrice> + <partNumber>661-3226</partNumber> + <partType/> + <quantity>1</quantity> + </parts> + <totalFromOrder>USD 38.00</totalFromOrder> + <icmsTax>3.00</icmsTax> + <pisTax>3.00</pisTax> + <ipiTax>3.00</ipiTax> + <icmsStTax>3.00</icmsStTax> + <cofinsTax>2.00</cofinsTax> + <issTax>2.00</issTax> + <vatTax>3.00</vatTax> + <outcome>STOP/HOLD/MSG</outcome> + <messages>The repair would go on Component Check Review.</messages> + <messages>Your accidental damage coverage under the AppleCare+ + contract will be reduced by one incident, but you will not incur a fee + for this repair.</messages> + <availableRepairStrategies> + <availableRepairStrategy> + Return Before Replace + </availableRepairStrategy> + <availableRepairStrategy> + Mail-in + </availableRepairStrategy> + </availableRepairStrategies> + </repairConfirmation> + </CreateCarryInResponse> + </ns4:CreateCarryInResponse> + </S:Body> +</S:Envelope> 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> + <S:Body> + <ns4:CreateGeneralEscalationResponse xmlns:ns2="http://iphone.endpoint.ws.gsx.ist.apple.com/" xmlns:ns3="http://gsxws.apple.com/elements/global" xmlns:ns4="http://gsxws.apple.com/elements/iphone"> + <CreateGeneralEscalationResponse> + <operationId>9a55f1310158234234</operationId> + <escalationConfirmation> + <escalationId>802714</escalationId> + <createTimestamp>2011-07-08 00:00:00 UTC</createTimestamp> + </escalationConfirmation> + </CreateGeneralEscalationResponse> + </ns4:CreateGeneralEscalationResponse> + </S:Body> +</S:Envelope> 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> + <S:Body> + <ns4:CreateMailInRepairResponse xmlns:ns4="http://gsxws.apple.com/types/core/asp"> + <CreateMailInRepairResponse> + <operationId>teHHI9DcQcLsTBtI7+jdLqmOFqFrRaMZ</operationId> + <repairConfirmation> + <confirmationNumber>G112477331</confirmationNumber> + <diagnosticDescription>Diagnostic Code Not Entered</diagnosticDescription> + <diagnosticEventNumber>800204262010153816</diagnosticEventNumber> + <diagnosticEventEndResult>FAILED</diagnosticEventEndResult> + <parts> + <availability/> + <currency>BRL</currency> + <netPrice>BRL 11.50</netPrice> + <partNumber>661-7654</partNumber> + <partType/> + <quantity>1</quantity> + </parts> + <totalFromOrder>BRL 38.00</totalFromOrder> + <icmsTax>3.00</icmsTax> + <pisTax>3.00</pisTax> + <ipiTax>3.00</ipiTax> + <icmsStTax>3.00</icmsStTax> + <cofinsTax>2.00</cofinsTax> + <issTax>2.00</issTax> + <vatTax>3.00</vatTax> + <vendorAddress> + <county>Madera</county> + <city>MEMPHIS</city> + <companyName>AI</companyName> + <countryName>United States</countryName> + <state>TN</state> + <street>6380 HOLMES ROAD</street> + <vendorName>FLEXTRONICS</vendorName> + <zipCode>38141</zipCode> + </vendorAddress> + <outcome>STOP/HOLD/MSG</outcome> + <messages>Some message1</messages> + <messages>Some message2</messages> + <availableRepairStrategies> + <availableRepairStrategy> + Return Before Replace + </availableRepairStrategy> + <availableRepairStrategy> + Mail-in + </availableRepairStrategy> + </availableRepairStrategies> + </repairConfirmation> + </CreateMailInRepairResponse> + </ns4:CreateMailInRepairResponse> + </S:Body> +</S:Envelope> 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> + <S:Body> + <ns3:CreateRepairOrReplaceResponse xmlns:ns2="http://asp.core.endpoint.ws.gsx.ist.apple.com/" + xmlns:ns3="http://gsxws.apple.com/elements/core/asp" + xmlns:ns4="http://gsxws.apple.com/elements/global" + xmlns:ns5="http://gsxws.apple.com/elements/core" + xmlns:ns6="http://gsxws.apple.com/elements/core/asp/am" + xmlns:ns7="http://gsxws.apple.com/types/core/asp"> + <CreateRepairOrReplaceResponse> + <operationId>734d2c566e1280959479183</operationId> + <repairConfirmation> + <confirmationNumber>G245605424</confirmationNumber> + <dcAddress> + <vendorName>Internal Acct for for Ceva RC - AU</vendorName> + <street>Unit 9, Discovery Cove,1801, B</street> + <county>Madera</county> + <city>Banksmeadow</city> + <state>NSW</state> + <countryName>Australia</countryName> + <zipCode>2019</zipCode> + <companyName>Apple</companyName> + </dcAddress> + <totalFromOrder>BRL 0.00</totalFromOrder> + <icmsTax>3.00</icmsTax> + <pisTax>3.00</pisTax> + <ipiTax>3.00</ipiTax> + <icmsStTax>3.00</icmsStTax> + <cofinsTax>2.00</cofinsTax> + <issTax>2.00</issTax> + <vatTax>0.0</vatTax> + <parts> + <partNumber>S3750LL/A</partNumber> + <partType>Other</partType> + <netPrice>BRL 0.00</netPrice> + <currency>BRL</currency> + <availability>Y</availability> + <quantity>1></quantity> + </parts> + <loanerParts> + <partNumber>S3750LL/A</partNumber> + <serialNumber></serialNumber> + <IMEINumber></IMEINumber> + </loanerParts> + <diagnosticEventNumber>895642387834567</diagnosticEventNumber> + <diagnosticEventEndResult>FAILED</diagnosticEventEndResult> + <outcome>STOP/HOLD/MSG</outcome> + <messages>Some Message1</messages> + <messages>Some Message2</messages> + <availableRepairStrategies> + <availableRepairStrategy> + Return Before Replace + </availableRepairStrategy> + <availableRepairStrategy> + Mail-in + </availableRepairStrategy> + </availableRepairStrategies> + </repairConfirmation> + </CreateRepairOrReplaceResponse> + </ns3:CreateRepairOrReplaceResponse> + </S:Body> +</S:Envelope> 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> + <S:Body> + <ns4:CreateWholeUnitExchangeResponse xmlns:ns2="http://asp.core.endpoint.ws.gsx.ist.apple.com/" xmlns:ns3="http://gsxws.apple.com/elements/global" xmlns:ns4="http://gsxws.apple.com/elements/core/asp" xmlns:ns5="http://gsxws.apple.com/elements/core/asp/am" xmlns:ns6="http://gsxws.apple.com/elements/core"> + <CreateWholeUnitExchangeResponse> + <operationId>79ebc1310162214229</operationId> + <repairConfirmation> + <confirmationNumber>G200404764</confirmationNumber> + <totalFromOrder>BRL 355.95</totalFromOrder> + <icmsTax>BRL 3.00</icmsTax> + <pisTax>BRL 3.00</pisTax> + <ipiTax>BRL 3.00</ipiTax> + <icmsStTax>BRL 3.00</icmsStTax> + <cofinsTax>BRL 2.00</cofinsTax> + <issTax>BRL 2.00</issTax> + <vatTax>0.0</vatTax> + <parts> + <partNumber>661-5571</partNumber> + <partType/> + <netPrice>BRL 349.00</netPrice> + <currency>BRL</currency> + <availability/> + <quantity>1</quantity> + </parts> + <parts> + <partNumber>ACSH08</partNumber> + <partType/> + <netPrice>BRL 6.95</netPrice> + <currency>BRL</currency> + <availability/> + <quantity>1</quantity> + </parts> + <outcome>STOP/HOLD</outcome> + <messages>Some Message1</messages> + <messages>Some Message2</messages> + <applicableRepairStrategies> + <applicableRepairStrategy> + Return Before Replace + </applicableRepairStrategy> + <applicableRepairStrategy> + Mail-in + </applicableRepairStrategy> + </applicableRepairStrategies> + </repairConfirmation> + </CreateWholeUnitExchangeResponse> + </ns4:CreateWholeUnitExchangeResponse> + </S:Body> +</S:Envelope> 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" + xmlns:glob="http://gsxws.apple.com/elements/global"> + <soapenv:Header/> + <soapenv:Body> + <glob:FetchCommunicationArticlesResponse> + <FetchCommunicationArticlesResponse> + <operationId>1234</operationId> + <communicationMessage> + <articleID>SN642</articleID> + <articleTitle> + Always Reset the PRAM Before Using the Graphics Processor Test + </articleTitle> + <articleSummary> + <p>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.</p> + </articleSummary> + <priority>Medium</priority> + <createdDate>02/13/11</createdDate> + <readStatus>Y</readStatus> + <lastActedOn>02/15/11</lastActedOn> + <acknowledgementRequired>N</acknowledgementRequired> + <functionalRole>TECHNICIAN</functionalRole> + <functionalRole>MANAGER</functionalRole> + </communicationMessage> + </FetchCommunicationArticlesResponse> + </glob:FetchCommunicationArticlesResponse> + </soapenv:Body> +</soapenv:Envelope> 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" + xmlns:glob="http://gsxws.apple.com/elements/global"> + <soapenv:Header/> + <soapenv:Body> + <glob:FetchCommunicationContentResponse> + <FetchCommunicationContentResponse> + <operationId>1234</operationId> + <communicationMessage> + <articleTitle> + Always Reset the PRAM Before Using the Graphics Processor Test + </articleTitle> + <articleSummary> + <p>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.</p> + </articleSummary> + <articleContent>Some big HTML content</articleContent> + <priority>Medium</priority> + <trainingUrl></trainingUrl> + <functionalRole>TECHNICIAN</functionalRole> + <functionalRole>MANAGER</functionalRole> + <productModel> + <productLine>IMAC</productLine> + <configCode>3EH</configCode> + <configDescription>iMac (20-inch, Early 2009)</configDescription> + </productModel> + <languageCode>en</languageCode> + </communicationMessage> + </FetchCommunicationContentResponse> + </glob:FetchCommunicationContentResponse> + </soapenv:Body> +</soapenv:Envelope> 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" + xmlns:glob="http://gsxws.apple.com/elements/global"> + <soapenv:Header/> + <soapenv:Body> + <glob:FetchDiagnosticConsoleURLResponse> + <FetchDiagnosticConsoleURLResponseData> + <operationId>123456</operationId> + <fetchDCURLResponseData> + <diagnosticConsoleURL>https://diagnostics.apple.com</diagnosticConsoleURL> + </fetchDCURLResponseData> + <communicationMessage/> + </FetchDiagnosticConsoleURLResponseData> + <communicationMessage/> + </glob:FetchDiagnosticConsoleURLResponse> + </soapenv:Body> +</soapenv:Envelope> 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:glob="http://gsxws.apple.com/elements/global"> + <soapenv:Header/> + <soapenv:Body> + <glob:FetchDiagnosticDetailsResponse> + <FetchDiagnosticDetailsResponseData> + <operationId></operationId> + <diagnosticDetailsResponseData> + <diagnosticTestContext> + <testContext> + <key>Serial Number</key> + <value>C02DN8KJDHJF</value> + </testContext> + <testContext> + <key>Diagnostic Event Number</key> + <value>47165961006635015191936</value> + </testContext> + <testContext> + <key>Event Start Date</key> + <value>16-JAN-15 06:43:58</value> + </testContext> + <testContext> + <key>Event Completion Date</key> + <value>16-JAN-15 06:43:58</value> + </testContext> + <testContext> + <key>Service Account ID</key> + <value>0000053729</value> + </testContext> + <testContext> + <key>Shp-To</key> + <value>0000053729</value> + </testContext> + <testContext> + <key>modulePassCount</key> + <value>56</value> + </testContext> + <testContext> + <key>Suite Name</key> + <value>Mobile Resource Inspector</value> + </testContext> + <testContext> + <key>Requested Channel</key> + <value>GSX</value> + </testContext> + <testContext> + <key>Diagnostic Event End Result</key> + <value>WARNING</value> + </testContext> + </diagnosticTestContext> + <diagnosticTestResults> + <testResultsData> + <testName>Checksum Test</testName> + <testStatus>PASSED</testStatus> + <moduleName>BootROM</moduleName> + <moduleLocation>BootROM</moduleLocation> + </testResultsData> + <testResultsData> + <testName>FW GUID MAC Address Checksum Tes</testName> + <testStatus>PASSED</testStatus> + <moduleName>BootROM</moduleName> + <moduleLocation>BootROM</moduleLocation> + </testResultsData> + <testResultsData> + <testName>Sensor Check Test</testName> + <testStatus>PASSED</testStatus> + <moduleName>SMC</moduleName> + <moduleLocation>SMC</moduleLocation> + </testResultsData> + <testResultsData> + <testName>Link Speed Verify Test</testName> + <testStatus>WARNING</testStatus> + <moduleName>WiFi</moduleName> + <moduleLocation>WiFi</moduleLocation> + </testResultsData> + <testResultsData> + <testName>Presence Test</testName> + <testStatus>PASSED</testStatus> + <moduleName>EthernetController</moduleName> + <moduleLocation>EthernetController</moduleLocation> + </testResultsData> + </diagnosticTestResults> + <diagnosticProfileData> + <profileType>MAC</profileType> + <deviceProfile> + <key>Current OS Version</key> + <value>10.8.2</value> + </deviceProfile> + <deviceProfile> + <key>Hardware Model</key> + <value>iMac14,4</value> + </deviceProfile> + </diagnosticProfileData> + </diagnosticDetailsResponseData> + <communicationMessage>There are priority messages pending</communicationMessage> + </FetchDiagnosticDetailsResponseData> + </glob:FetchDiagnosticDetailsResponse> + </soapenv:Body> +</soapenv:Envelope>
\ 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" + xmlns:glob="http://gsxws.apple.com/elements/global"> + <soapenv:Header/> + <soapenv:Body> + <glob:FetchDiagnosticSuitesResponse> + <FetchDiagnosticSuitesResponseData> + <operationId>123456</operationId> + <diagnosticSuitesResponseData> + <diagnosticSuiteDetails> + <suiteId>1234</suiteId> + <suiteName>Mac Resource Inspector</suiteName> + </diagnosticSuiteDetails> + <diagnosticSuiteDetails> + <suiteId>5678</suiteId> + <suiteName>Quick Test</suiteName> + </diagnosticSuiteDetails> + </diagnosticSuitesResponseData> + <communicationMessage/> + </FetchDiagnosticSuitesResponseData> + </glob:FetchDiagnosticSuitesResponse> + </soapenv:Body> +</soapenv:Envelope> 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> + <S:Body> + <ns4:GeneralEscalationDetailsLookupResponse xmlns:ns2="http://asp.core.endpoint.ws.gsx.ist.apple.com/" xmlns:ns3="http://gsxws.apple.com/elements/global" xmlns:ns4="http://gsxws.apple.com/elements/core/asp" xmlns:ns5="http://gsxws.apple.com/elements/core/asp/am" xmlns:ns6="http://gsxws.apple.com/elements/core"> + <GeneralEscalationDetailsLookupResponse> + <operationId>0b8591308861450587</operationId> + <lookupResponseData> + <escalationId>785749</escalationId> + <escalationType>GSX Help</escalationType> + <escalationContext> + <contextType>1</contextType> + <contextID>GB020N5TZ3A</contextID> + </escalationContext> + <escalationStatus>OPEN</escalationStatus> + <issueType>Account Management Question</issueType> + <escalationTo>Apple</escalationTo> + <createdBy>dummy tester</createdBy> + <createTimestamp>08/24/12 09:48 AM</createTimestamp> + <lastViewedBy>global AdminP1</lastViewedBy> + <lastModifiedBy>dummy tester</lastModifiedBy> + <escalationAge>1day 4hours 7minutes</escalationAge> + <caseDetails> + <caseId>10000144395733</caseId> + <caseTitle>Repair Extension Program Issue</caseTitle> + <caseSummary> + CUSTOMER: GSX Tech AMR + Activation Issues on iOS Devices After Repair + Has the repair been marked complete? + </caseSummary> + </caseDetails> + <escalationNotes> + <note>MY NOTES HERE</note> + </escalationNotes> + <chatTranscripts> + <chatTranscript> + 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 + </chatTranscript> + <chatTranscript> + 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 + </chatTranscript> + </chatTranscripts> + </lookupResponseData> + </GeneralEscalationDetailsLookupResponse> + </ns4:GeneralEscalationDetailsLookupResponse> + </S:Body> +</S:Envelope> 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" + xmlns:glob="http://gsxws.apple.com/elements/global"> + <soapenv:Header/> + <soapenv:Body> + <glob:InitiateIOSDiagnosticResponse> + <InitiateIOSDiagnosticResponse> + <operationId>5522d3445672222f</operationId> + <initiateResponseData> + <ticketNumber>1234567890</ticketNumber> + </initiateResponseData> + </InitiateIOSDiagnosticResponse> + </glob:InitiateIOSDiagnosticResponse> + </soapenv:Body> +</soapenv:Envelope> 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> + <S:Body> + <ns4:MarkRepairCompleteResponse xmlns:ns4="http://gsxws.apple.com/types/core/asp"> + <MarkRepairCompleteResponse> + <operationId>ykNJV0zy368v5uqnUYthI63zNSeip8/J</operationId> + <repairConfirmationNumbers> + <repairConfirmationNumber>$dispatchId</repairConfirmationNumber> + <outcome>STOP/HOLD</outcome> + <messages>Some Message1</messages> + <messages>Some Message2</messages> + </repairConfirmationNumbers> + <repairConfirmationNumbers> + <repairConfirmationNumber>$dispatchId</repairConfirmationNumber> + <outcome>HOLD</outcome> + <messages>Some Message1</messages> + <messages>Some Message2</messages> + </repairConfirmationNumbers> + <repairConfirmationNumbers> + <repairConfirmationNumber>$dispatchId</repairConfirmationNumber> + <outcome>HOLD</outcome> + <messages>Some Message1</messages> + <messages>Some Message2</messages> + </repairConfirmationNumbers> + </MarkRepairCompleteResponse> + </ns4:MarkRepairCompleteResponse> +</S:Body> +</S:Envelope> 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> + <S:Body> + <ns3:PartsLookupResponse xmlns:ns3="http://gsxws.apple.com/elements/core"> + <PartsLookupResponse> + <operationId>AnK6lhP8j4Zw8hHYswYMGCthSKGnzy9O</operationId> + <parts> + <eeeCode>HG7F</eeeCode> + <isSerialized>N</isSerialized> + <laborTier>CON7</laborTier> + <partDescription>32GB, Black, GSM, iPhone 7, CI/AR</partDescription> + <partNumber>661-05427</partNumber> + <partType>Module</partType> + <pricingOptions> + <pricingOption> + <code>BATTR</code> + <description>Battery Only Price</description> + <price>129</price> + </pricingOption> + <pricingOption> + <code>DSPLY</code> + <description>Display Only Price</description> + <price>109</price> + </pricingOption> + </pricingOptions> + <componentCode>B</componentCode> + </parts> + <parts> + <eeeCode>DC18,DC19</eeeCode> + <isSerialized>Y</isSerialized> + <laborTier></laborTier> + <partDescription>SVC,REMOTE</partDescription> + <partNumber>661-4448</partNumber> + <partType>Module</partType> + <componentCode>5</componentCode> + <originalPartNumber>661-2549</originalPartNumber> + </parts> + <parts> + <eeeCode>59T</eeeCode> + <isSerialized>Y</isSerialized> + <laborTier></laborTier> + <partDescription>Power Adapter w/Plug, Ultra-Compact, USB, iPhone/iPod-US/CAN/JPN/TWN</partDescription> + <partNumber>661-4954</partNumber> + <partType>Module</partType> + <componentCode>3</componentCode> + <originalPartNumber></originalPartNumber> + </parts> + <parts> + <eeeCode></eeeCode> + <isSerialized>N</isSerialized> + <laborTier></laborTier> + <partDescription>SVC,STEREO HEADSET</partDescription> + <partNumber>661-5028</partNumber> + <partType>Module</partType> + <componentCode>6</componentCode> + <originalPartNumber>922-8629</originalPartNumber> + </parts> + <parts> + <eeeCode>HG7F</eeeCode> + <isSerialized>N</isSerialized> + <laborTier>CON7</laborTier> + <partDescription>32GB, Black, GSM, iPhone 7, CI/AR</partDescription> + <partNumber>661-05427</partNumber> + <partType>Module</partType> + <componentCode>B</componentCode> + </parts> + </PartsLookupResponse> + </ns3:PartsLookupResponse> + </S:Body> +</S:Envelope> 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> + <S:Body> + <ns4:ReportedSymptomIssueResponse xmlns:ns2="http://asp.core.endpoint.ws.gsx.ist.apple.com/" xmlns:ns3="http://gsxws.apple.com/elements/core/asp" xmlns:ns4="http://gsxws.apple.com/elements/global" xmlns:ns5="http://gsxws.apple.com/elements/core/asp/am" xmlns:ns6="http://gsxws.apple.com/elements/core"> + <ReportedSymptomIssueResponse> + <operationId>170ae1310160353346</operationId> + <Issues> + <Issue> + <reportedIssueCode>IP022</reportedIssueCode> + <reportedIssueDesc>Bluetooth</reportedIssueDesc> + </Issue> + <Issue> + <reportedIssueCode>IP025</reportedIssueCode> + <reportedIssueDesc>Wi-Fi</reportedIssueDesc> + </Issue> + </Issues> + <Symptoms> + <Symptom> + <reportedSymptomCode>26092</reportedSymptomCode> + <reportedSymptomDesc>Apps</reportedSymptomDesc> + </Symptom> + <Symptom> + <reportedSymptomCode>26094</reportedSymptomCode> + <reportedSymptomDesc>Bluetooth/Wi-Fi</reportedSymptomDesc> + </Symptom> + </Symptoms> + </ReportedSymptomIssueResponse> + </ns4:ReportedSymptomIssueResponse> + </S:Body> +</S:Envelope>
\ 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" + xmlns:glob="http://gsxws.apple.com/elements/global"> + <soapenv:Header/> + <soapenv:Body> + <glob:RunDiagnosticTestResponse> + <RunDiagnosticTestResponseData> + <operationId>123456</operationId> + <diagnosticTestResponseData> + <responseMessage/> + </diagnosticTestResponseData> + <communicationMessage/> + </RunDiagnosticTestResponseData> + </glob:RunDiagnosticTestResponse> + </soapenv:Body> +</soapenv:Envelope> 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> + <S:Body> + <ns4:UpdateCarryInResponse xmlns:ns2="http://asp.core.endpoint.ws.gsx.ist.apple.com/" xmlns:ns3="http://gsxws.apple.com/elements/global" xmlns:ns4="http://gsxws.apple.com/elements/core/asp" xmlns:ns5="http://gsxws.apple.com/elements/core/asp/am" xmlns:ns6="http://gsxws.apple.com/elements/core"> + <UpdateCarryInResponse> + <operationId>620271310148985581</operationId> + <repairConfirmation> + <confirmationNumber>$repairConfirmationNumber</confirmationNumber> + <totalFromOrder>BRL 0.00</totalFromOrder> + <icmsTax>3.00</icmsTax> + <pisTax>3.00</pisTax> + <ipiTax>3.00</ipiTax> + <icmsStTax>3.00</icmsStTax> + <cofinsTax>2.00</cofinsTax> + <issTax>2.00</issTax> + <vatTax>0.0</vatTax> + <parts> + <partNumber>661-5000</partNumber> + <partType/> + <netPrice>BRL 0.00</netPrice> + <currency>BRL</currency> + <availability/> + <quantity>1</quantity> + </parts> + <parts> + <partNumber>661-5321</partNumber> + <partType/> + <netPrice>BRL 0.00</netPrice> + <currency>BRL</currency> + <availability/> + <quantity>1</quantity> + </parts> + <diagnosticEventNumber>895642387834567</diagnosticEventNumber> + <diagnosticEventEndResult>FAILED</diagnosticEventEndResult> + <outcome>STOP/HOLD/MSG</outcome> + <messages>Some Message1</messages> + <messages>Some Message2</messages> + </repairConfirmation> + <communicationMessage/> + </UpdateCarryInResponse> + </ns4:UpdateCarryInResponse> + </S:Body> +</S:Envelope> 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> + <S:Body> + <ns4:UpdateGeneralEscalationResponse xmlns:ns2="http://iphone.endpoint.ws.gsx.ist.apple.com/" xmlns:ns3="http://gsxws.apple.com/elements/global" xmlns:ns4="http://gsxws.apple.com/elements/iphone"> + <UpdateGeneralEscalationResponse> + <operationId>91f5a1310158382330</operationId> + <escalationConfirmation> + <updateStatus>SUCCESS</updateStatus> + <updateTimestamp>12/18/12 11:10 AM</updateTimestamp> + </escalationConfirmation> + </UpdateGeneralEscalationResponse> + </ns4:UpdateGeneralEscalationResponse> + </S:Body> +</S:Envelope> 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> + <S:Body> + <ns3:WarrantyStatusResponse xmlns:ns2="http://asp.core.endpoint.ws.gsx.ist.apple.com/" xmlns:ns3="http://gsxws.apple.com/elements/global" xmlns:ns4="http://gsxws.apple.com/elements/core/asp" xmlns:ns5="http://gsxws.apple.com/elements/core/asp/am" xmlns:ns6="http://gsxws.apple.com/elements/core"> + <WarrantyStatusResponse> + <operationId>5fdef1309390619199</operationId> + <warrantyDetailInfo> + <serialNumber>$serialNumber</serialNumber> + <warrantyStatus>Out Of Warranty (No Coverage)</warrantyStatus> + <coverageEndDate>08/24/11</coverageEndDate> + <coverageStartDate>08/25/10</coverageStartDate> + <daysRemaining>0</daysRemaining> + <estimatedPurchaseDate>08/25/10</estimatedPurchaseDate> + <globalWarranty/> + <purchaseCountry>United States</purchaseCountry> + <registrationDate>08/25/10</registrationDate> + <imageURL></imageURL> + <explodedViewURL></explodedViewURL> + <manualURL></manualURL> + <productDescription>iPhone 4</productDescription> + <configDescription>IPHONE 4,16GB BLACK</configDescription> + <slaGroupDescription/> + <ecorathFlag/> + <powerTrainFlag/> + <triCareFlag/> + <contractCoverageEndDate/> + <contractCoverageStartDate/> + <contractType/> + <laborCovered>Y</laborCovered> + <limitedWarranty>Y</limitedWarranty> + <partCovered>Y</partCovered> + <warrantyReferenceNo/> + <isPersonalized/> + <acPlusFlag>Y</acPlusFlag> + <isLoaner>Y</isLoaner> + <status>Available</status> + <activationLockStatus>Find My iPhone is Active. Find My iPhone must be turned off for Whole Unit Repairs.</activationLockStatus> + <consumerLawInfo> + <serviceType>RFD</serviceType> + <popMandatory>Y</popMandatory> + <allowedPartType>NEW</allowedPartType> + </consumerLawInfo> + <messages>Some Message1</messages> + <messages>Some Message2</messages> + <availableRepairStrategies> + <availableRepairStrategy>Return Before Replace</availableRepairStrategy> + <availableRepairStrategy>Mail-in</availableRepairStrategy> + </availableRepairStrategies> + <eligibleAppleCareContract> + <appleCareContract>APP FOR RUBIX</appleCareContract> + <eligibleAppleCareTiers> + <appleCareTier> + <tierDesc>AppleCare+ Battery Only Repair</tierDesc> + <tierPrice>USD 49.00</tierPrice> + </appleCareTier> + <appleCareTier> + <tierDesc>AppleCare+ Display Only Repair</tierDesc> + <tierPrice>USD 69.00</tierPrice> + </appleCareTier> + </eligibleAppleCareTiers> + </eligibleAppleCareContract> + </warrantyDetailInfo> + <communicationMessage/> + </WarrantyStatusResponse> + </ns3:WarrantyStatusResponse> + </S:Body> +</S:Envelope> 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() |