aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFilipp Lepalaan <filipp@mac.com>2018-10-10 07:44:52 +0300
committerFilipp Lepalaan <filipp@mac.com>2018-10-10 07:44:52 +0300
commit9d4459d5cfbe507f6a56cdd93c17d3a7be63b2c9 (patch)
tree259fa7a82339cc250dbd5fc0eb32eff2d8ce39ca
parentd849b9447c38b09d3edd2b03bd46249be6f5990a (diff)
downloadgsx-mockserver-9d4459d5cfbe507f6a56cdd93c17d3a7be63b2c9.tar.gz
gsx-mockserver-9d4459d5cfbe507f6a56cdd93c17d3a7be63b2c9.tar.bz2
gsx-mockserver-9d4459d5cfbe507f6a56cdd93c17d3a7be63b2c9.zip
Update README
-rw-r--r--README.md72
1 files changed, 46 insertions, 26 deletions
diff --git a/README.md b/README.md
index 76be9bf..a0b885b 100644
--- a/README.md
+++ b/README.md
@@ -1,57 +1,79 @@
-Introduction
-============
+# 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
-============
+## Installation
The server requires Python 3 and has only one external dependency - `lxml` which is used to parse the request XML.
- $ pip install lxml
- $ python serve.py
- Validating XML responses...
- GSX mock server serving on http://localhost:8080
+ $ 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. Use the `GSX_THROTTLE=X` environment
variable to add a X-second delay to each API response.
-Usage
-=====
+## 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
+ GSX_URL=http://localhost:8080 python my_gsx_code_using_pygsxws.py
+## Variable reflection
-Variable reflection
-===================
+The server will automatically replace values in the response with corresponding values in the request meaning if you have ```<serialNumber>lalalala</serialNumber>``` in your request, the ```<serialNumber>``` in the response will also be ```lalalala```.
-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:
+For variables that have different names in requests and responses (like **dispatchId** vs **repairConfirmationNumber**) you can also use Python's [string templates](https://docs.python.org/3.6/library/string.html?highlight=template#string.Template.template) in the response files themselves. In this case a request like this:
```xml
<MarkRepairCompleteRequest>
- <userSession>
- <userSessionId>Sdt7tXp2XytTEVwHBeDx6lHTXI3w9s+M</userSessionId>
+ <userSession>
+ <userSessionId>Sdt7tXp2XytTEVwHBeDx6lHTXI3w9s+M</userSessionId>
</userSession>
- <repairConfirmationNumbers>123456</repairConfirmationNumbers>
+ <repairConfirmationNumbers>LALALALALA</repairConfirmationNumbers>
<dispatchId>123456</dispatchId>
</MarkRepairCompleteRequest>
</asp:MarkRepairComplete>
```
-would result in the following response:
+And a response template like this:
```xml
<MarkRepairCompleteResponse>
- <operationId>ykNJV0zy368v5uqnUYthI63zNSeip8/J</operationId>
- <repairConfirmationNumbers>
- <repairConfirmationNumber>123456</repairConfirmationNumber>
+ <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>$dispatchId</repairConfirmationNumber>
+```
+
+... 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>
@@ -68,15 +90,13 @@ would result in the following response:
<messages>Some Message1</messages>
<messages>Some Message2</messages>
</repairConfirmationNumbers>
-</MarkRepairCompleteResponse>ionNumber>123456</repairConfirmationNumber>
+</MarkRepairCompleteResponse>123456</repairConfirmationNumber>
```
Please note that due to inconsistencies in the response schema, this feature doesn't work with every request type.
-Development
-===========
+## 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
-