{ "info": { "author": "Thomas Lee", "author_email": "thomaslee@yam.ai", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "License :: OSI Approved :: Apache Software License", "Programming Language :: Python :: 3.6", "Topic :: Software Development :: Testing :: Mocking" ], "description": "# Yamas - Yet Another Mock API Server\n\nThis project develops a simple mock API server for prototyping and testing client applications. \n\nBased on [`http.server`](https://docs.python.org/3.6/library/http.server.html) of Python3.6+, Yamas is a testing API server which can accept HTTP requests from a client and reply with pre-defined mock HTTP responses. (*Note: Yamas should not be used for production.*)\n\nThe mock responses and the rules of selecting them are specified in a JSON file. Processing an request, Yamas locates the wanted mock response by matching the request path with a sequence of user-specified regular expressions and then looking up the response by the request method.\n\n## Usage\n\nYamas has been published to [PyPI](https://pypi.org/project/yamas/). You can use `pip` to install Yamas:\n\n```sh\npip install yamas\n```\n\nThe command-line interface of Yamas is as follows:\n\n```sh\nyamas [-e|--endpoint host:port] -f|--file mock_responses_spec\n```\n\n* `-e` or `--endpoint` specifies the host address and the port number of the endpoint; if this is not specified, `127.0.0.1:7000` will be used.\n* `-f` or `--file` specifies the path of the JSON file which defines the mock responses and the selection rules.\n\nFor example,\n\n```sh\nyamas -e localhost:8000 -f mock_responses.json\n```\n\nTo run Yamas using the source code under the project root directory (e.g., `/home/yam/git/yamas`):\n\n```sh\npip install .\nyamas -e localhost:8000 -f data/mock_responses.json\n```\n\nTo run the tests:\n\n```sh\npython -m pytest tests/\n```\n\n## Specification of mock responses\n\nThe mock responses and the rules of selecting them are specified in a JSON file, which is given on the command line. A sample specification is given as follows:\n\n```json\n{\n \"global\": {\n \"headers\": {\n \"Access-Control-Allow-Origin\": \"*\"\n },\n \"serverHeader\": \"YetAnotherMockAPIServer 0.0.1\"\n },\n \"rules\": {\n \"^/users/(\\\\w+)/todo/(\\\\d+)$\": {\n \"GET\": {\n \"status\": 200,\n \"content\": {\n \"user\": \"$p_0\",\n \"taskid\": \"$p_1\",\n \"task\": \"Buy milk\",\n \"pri\": \"low\"\n },\n \"contentType\": \"json\",\n \"interpolate\": true\n },\n \"DELETE\": {\n \"status\": 410\n }\n },\n \"^/users/\\\\w+/todo/?\": {\n \"GET\": {\n \"status\": 200,\n \"content\": [\n \"123\",\n \"456\",\n \"789\"\n ],\n \"contentType\": \"json\"\n },\n \"POST\": {\n \"content\": {\n \"taskid\": \"123\"\n },\n \"contentType\": \"json\",\n \"interpolate\": false\n }\n },\n \"^/users/(\\\\w+)/profile.xml$\": {\n \"GET\": {\n \"status\": 200,\n \"headers\": {\n \"Content-Type\": \"application/xml\"\n },\n \"content\": \"$p_0yam.aipremium\",\n \"contentType\": \"text\",\n \"interpolate\": true\n },\n \"PUT\": {\n \"status\": 409,\n \"content\": \"object already updated\",\n \"contentType\": \"text\"\n }\n },\n \"^/users/(\\\\w+)/profile$\": {\n \"GET\": {\n \"status\": 200,\n \"headers\": {\n \"Content-Type\": \"\"\n },\n \"content\": \"Hello $p_0\",\n \"contentType\": \"text\",\n \"interpolate\": true\n },\n \"POST\": {\n \"status\": 200,\n \"headers\": {\n \"Content-Type\": \"\"\n },\n \"content\": {\n \"hello\": \"$p_0\"\n },\n \"contentType\": \"json\",\n \"interpolate\": true\n }\n }\n }\n}\n```\n\nThe root level is a JSON object. Inside the root object, there are optional objects `global` and `rules`.\n\nUnder `global`, there are optional objects `headers` and `serverHeader`. The `headers` object specifies the default HTTP response headers to be included in the response to each request matching any of the rules specified below. The `serverHeader` field gives a string value that customizes the default HTTP response header `Server`.\n\nThe `rules` object maps the pattern ([Python regular expressions](https://docs.python.org/3.6/howto/regex.html)) of an HTTP request path (i.e., key) to an object containing the mock responses for different HTTP methods (i.e., value). The matching is done in the order of the key-value pairs specified under `rules`. In other words, a key is selected one at a time from the top to the bottom and its regular expression is used to match the request path.\n\nWhen the request path matches the pattern in a key, the associated JSON object specifying the mock responses associated with the HTTP methods will be selected. When the request path does not match the regular expression, the regular expression in the next key will be selected. If the request path matches no regular expression, a [404 Not Found](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status) response will be replied.\n\nWhen a request path matches the pattern in a key, the corresponding JSON object will be used to construct the response. Inside this JSON object, the keys are [HTTP methods](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods). The JSON object value corresponding to each HTTP method key specifies a mock response.\n\nThe mock response object contains the following:\n\n* `status` specifies the status code of the response. If `status` is not specified, `200 OK` will be used.\n* `headers` specifies a JSON object containing the header names and values. If there are no user-defined headers, `headers` can be omitted. If the value of a header is an empty string, the corresponding header which may be automatically added, (e.g., `Content-Type` and a globally specified header) will be removed.\n* `content` specifies the content (or body) of the response. Its value should match its `contentType`.\n* `contentType` specifies the data type of the content. The following types can be used:\n * `text`: `content` must be a string of the [UTF-8](https://en.wikipedia.org/wiki/UTF-8) text content. The header `Content-Type: text/plain` will be automatically added unless it is overriden by a user-specified `Content-Type` header.\n * `json`: `content` is treated as a JSON value. The header `Content-Type: application/json` will be automatically added unless it is overriden by a user-specified `Content-Type` header.\n * `contentType` is omitted: `content` is treated as `text` except the header `Content-Type: text/plain` is not automatically added.\n* `interpolate` specifies whether the matched values of the capturing groups in the request path will replace the placeholders in the content template. It is `false` by default. When `interpolate` is `true`, every string value in `content` is expected to be a [Python template string](https://docs.python.org/3/library/string.html#template-strings). If `content` is `text`, the value is treated as a template. If the `content` is `json`, every string value in the object is treated as a template. As shown in the the above example, the placeholder `$p_i` will be replaced with the matched value of the *i*-th capturing group in the request path pattern. As in the above example, `$p_0` will be substituted with the matched value of the first capturing group `(\\w+)` in the pattern path `^/users/(\\w+)/todo/(\\d+)$`, `$p_1` will be substituted with the value of the second matched capturing group `(\\d+)`. Note: the special character `$` should be escaped as `$$`.\n\n## Professional services\n\nIf you need any support or consultancy services from YAM AI Machinery, please find us at:\n\n* https://www.yam.ai\n* https://twitter.com/theYAMai\n* https://www.linkedin.com/company/yamai\n* https://www.facebook.com/theYAMai\n* https://github.com/yam-ai\n* https://hub.docker.com/u/yamai", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/yam-ai/yamas", "keywords": "rest api mocking server", "license": "", "maintainer": "", "maintainer_email": "", "name": "yamas", "package_url": "https://pypi.org/project/yamas/", "platform": "", "project_url": "https://pypi.org/project/yamas/", "project_urls": { "Homepage": "https://github.com/yam-ai/yamas" }, "release_url": "https://pypi.org/project/yamas/0.2.1/", "requires_dist": null, "requires_python": ">=3.6", "summary": "Yamas - Yet Another Mock API Server", "version": "0.2.1", "yanked": false, "yanked_reason": null }, "last_serial": 6091741, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "af85cbaeda4d4e1c3ce986a3191362e0", "sha256": "155d00c0aa88831b0676b848c8ddcf04e07a4f4ee8a135807a464dfd9ed1d7f4" }, "downloads": -1, "filename": "yamas-0.1.0.tar.gz", "has_sig": false, "md5_digest": "af85cbaeda4d4e1c3ce986a3191362e0", "packagetype": "sdist", "python_version": "source", "requires_python": ">3.6", "size": 5864, "upload_time": "2019-10-27T03:31:09", "upload_time_iso_8601": "2019-10-27T03:31:09.554269Z", "url": "https://files.pythonhosted.org/packages/1c/e1/678ac10628fb6c0507152131c27805dd4eedc9cb7b81b6ab5cb19c4d4ae9/yamas-0.1.0.tar.gz", "yanked": false, "yanked_reason": null } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "850c205df5375331c79e45a9ea2b1aaf", "sha256": "25b36b3940564358e354ca03ad824c185e1ff5c4a1d98a899ff46768900abe85" }, "downloads": -1, "filename": "yamas-0.1.1.tar.gz", "has_sig": false, "md5_digest": "850c205df5375331c79e45a9ea2b1aaf", "packagetype": "sdist", "python_version": "source", "requires_python": ">3.6", "size": 7297, "upload_time": "2019-10-27T15:56:24", "upload_time_iso_8601": "2019-10-27T15:56:24.320373Z", "url": "https://files.pythonhosted.org/packages/ad/4d/861f4d40b241346f11e349a3a669f2e496355b361d12511799f0178ee7d2/yamas-0.1.1.tar.gz", "yanked": false, "yanked_reason": null } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "1b67282422b566dc2eb288ea63b4b3c4", "sha256": "062d91c3a587d31be8d3182eb3e25b0600007bff54ae27054a0fc2172a2a63a0" }, "downloads": -1, "filename": "yamas-0.1.2.tar.gz", "has_sig": false, "md5_digest": "1b67282422b566dc2eb288ea63b4b3c4", "packagetype": "sdist", "python_version": "source", "requires_python": ">3.6", "size": 8831, "upload_time": "2019-10-28T03:52:48", "upload_time_iso_8601": "2019-10-28T03:52:48.779560Z", "url": "https://files.pythonhosted.org/packages/54/37/9d4739b1ed4ae6c5cab28e835237956589ce2c1ade6a3e1e02ec8eb131db/yamas-0.1.2.tar.gz", "yanked": false, "yanked_reason": null } ], "0.1.4": [ { "comment_text": "", "digests": { "md5": "d4680911f800c37573657642b83557e9", "sha256": "061564c023e5e93e9125ec5e6ddfbba68c9ad3423e850f45546ff978ea66c6d7" }, "downloads": -1, "filename": "yamas-0.1.4.tar.gz", "has_sig": false, "md5_digest": "d4680911f800c37573657642b83557e9", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 10171, "upload_time": "2019-11-01T08:15:26", "upload_time_iso_8601": "2019-11-01T08:15:26.539128Z", "url": "https://files.pythonhosted.org/packages/b4/ca/ad4814fde6afb2d749ca4416b07a13657e4ed1dfaf8610a7c199254a4e0f/yamas-0.1.4.tar.gz", "yanked": false, "yanked_reason": null } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "f9bab51ec6a24badd1d78a31c2dbc549", "sha256": "164d909d33e4c118b7e19cfda9226b5cf3df126e65aaf9f76b614e9e15f7a249" }, "downloads": -1, "filename": "yamas-0.2.1.tar.gz", "has_sig": false, "md5_digest": "f9bab51ec6a24badd1d78a31c2dbc549", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 11809, "upload_time": "2019-11-07T07:00:15", "upload_time_iso_8601": "2019-11-07T07:00:15.766439Z", "url": "https://files.pythonhosted.org/packages/2e/ad/fb7f2ad14ddbd1e1b106989e70d1d92852403a4b86728d378c32abd01003/yamas-0.2.1.tar.gz", "yanked": false, "yanked_reason": null } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "f9bab51ec6a24badd1d78a31c2dbc549", "sha256": "164d909d33e4c118b7e19cfda9226b5cf3df126e65aaf9f76b614e9e15f7a249" }, "downloads": -1, "filename": "yamas-0.2.1.tar.gz", "has_sig": false, "md5_digest": "f9bab51ec6a24badd1d78a31c2dbc549", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 11809, "upload_time": "2019-11-07T07:00:15", "upload_time_iso_8601": "2019-11-07T07:00:15.766439Z", "url": "https://files.pythonhosted.org/packages/2e/ad/fb7f2ad14ddbd1e1b106989e70d1d92852403a4b86728d378c32abd01003/yamas-0.2.1.tar.gz", "yanked": false, "yanked_reason": null } ], "vulnerabilities": [] }