responsaas


Nameresponsaas JSON
Version 0.1.0 PyPI version JSON
download
home_page
Summary
upload_time2023-08-24 20:31:46
maintainer
docs_urlNone
authorDanCardin
requires_python>=3.8,<4.0
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Responsaas

[![Actions Status](https://github.com/dancardin/responsaas/workflows/test/badge.svg)](https://github.com/dancardin/responsaas/actions)
[![Coverage Status](https://coveralls.io/repos/github/DanCardin/responsaas/badge.svg?branch=main)](https://coveralls.io/github/DanCardin/responsaas?branch=main)
[![Documentation Status](https://readthedocs.org/projects/responsaas/badge/?version=latest)](https://responsaas.readthedocs.io/en/latest/?badge=latest)
[![Docker](https://img.shields.io/docker/cloud/build/dancardin/responsaas?label=Docker&style=flat)](https://hub.docker.com/r/dancardin/responsaas)

Wraps the python [responses](https://github.com/getsentry/responses) library As
A Service.

See the full documentation [here](https://responsaas.readthedocs.io/en/latest/)
(or more specifically
[converting from responses](https://responsaas.readthedocs.io/en/latest/converting)).

## Quickstart

### Automatic (with pytest)

Using
[pytest-mock-resources](https://github.com/schireson/pytest-mock-resources/), we
can use Docker to manage the lifecycle of the server.

`pip install responsaas[pmr]`

```python
from responsaas.pytest import create_responsaas_fixture, create_responsaas_server_fixture

responsaas_server = create_responsaas_server_fixture()
responsaas = create_responsaas_fixture()

def test_foo(responsaas: Responsaas):
    responsaas.add("/foo", json={"bar": True})

    response = requests.get(responsaas.base_url + "/foo")
    assert response.json() == {"bar": True}
```

### Manual

The manual examples assume you have some external way of standing up the server

`pip install responsaas`

```python
import requests
from responsaas import ResponsaasServer, Responsaas

# With pytest
from responsaas.pytest import create_responsaas_fixture

responsaas = create_responsaas_fixture("http://localhost:7564")

def test_foo(responsaas: Responsaas):
    responsaas.add("/foo", json={"bar": True})

    response = requests.get(responsaas.base_url + "/foo")
    assert response.json() == {"bar": True}


# Or completely manually.
def test_foo():
    responsaas_server = ResponsaasServer("http://localhost:7564")
    with responsaas_server.activate() as responsaas:
        responsaas.add("/foo", json={"bar": True})

        response = requests.get(responsaas.base_url + "/foo")
        assert response.json() == {"bar": True}
```

## Why?!?

Under the hood, `repsonses` is `patch`ing the network calls being made and
replacing their result with the result you specify. It's very fast, convenient,
and (by default) disallows you from making **actual** network calls.

**However** the same (`patch`) strategy that makes it useful has some issues.

- This can run afoul of other libraries which perform `patch` operations. The
  issue history of responses has many instances (frequently with `moto`), where
  patches get clobbered in one way or another.

  - `responsaas` does not use `patch` at all. It is a real standalone service
    responding to real requests.

- Either through `patch` issues, or through programmer error, `responses` can be
  **so** non-invasive that API calls accidentally get made through to the
  original destination URL.

  - `responsaas` forces you to change (or really, make configurable) the URL
    you're hitting for tests, which should make it impossible to hit the
    original destination url in tests on accident.

- `responses` allows you to return arbitrary python objects (like exceptions)
  which wouldn't be possible for a request to actually return.

  - `responsaas` (once again), is a literal service responding to requests. The
    requesting client code is receiving bytes over the wire, and parsing it
    normally.

- `responses` is(?) limited to mocking the `requests` library. Which doesn't
  cover cases like `httpx`, `aiohttp`, etc.

  - `responsaas` is client agnostic, given that it's a real service.

- `responses` needs an additional mechanism to allow "passthru" requests

  - `responsaas` (once again), is a literal service responding to requests, so
    it can only return.

## How?

What's going on internally is:

- Each test registers a new "namespace" against the `responsaas` server
- Each new namespace corresponds to one `responses.RequestsMock`.
- As incoming requests are received by the server, they're mapped to the request
  shape expected by `responses`, and routed directly through its request
  matching and responds logic.


            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "responsaas",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8,<4.0",
    "maintainer_email": "",
    "keywords": "",
    "author": "DanCardin",
    "author_email": "ddcardin@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/77/0d/b030cc78ea91fa26e14dcd25456eae613be362ed417d7830c61d9c7b4af6/responsaas-0.1.0.tar.gz",
    "platform": null,
    "description": "# Responsaas\n\n[![Actions Status](https://github.com/dancardin/responsaas/workflows/test/badge.svg)](https://github.com/dancardin/responsaas/actions)\n[![Coverage Status](https://coveralls.io/repos/github/DanCardin/responsaas/badge.svg?branch=main)](https://coveralls.io/github/DanCardin/responsaas?branch=main)\n[![Documentation Status](https://readthedocs.org/projects/responsaas/badge/?version=latest)](https://responsaas.readthedocs.io/en/latest/?badge=latest)\n[![Docker](https://img.shields.io/docker/cloud/build/dancardin/responsaas?label=Docker&style=flat)](https://hub.docker.com/r/dancardin/responsaas)\n\nWraps the python [responses](https://github.com/getsentry/responses) library As\nA Service.\n\nSee the full documentation [here](https://responsaas.readthedocs.io/en/latest/)\n(or more specifically\n[converting from responses](https://responsaas.readthedocs.io/en/latest/converting)).\n\n## Quickstart\n\n### Automatic (with pytest)\n\nUsing\n[pytest-mock-resources](https://github.com/schireson/pytest-mock-resources/), we\ncan use Docker to manage the lifecycle of the server.\n\n`pip install responsaas[pmr]`\n\n```python\nfrom responsaas.pytest import create_responsaas_fixture, create_responsaas_server_fixture\n\nresponsaas_server = create_responsaas_server_fixture()\nresponsaas = create_responsaas_fixture()\n\ndef test_foo(responsaas: Responsaas):\n    responsaas.add(\"/foo\", json={\"bar\": True})\n\n    response = requests.get(responsaas.base_url + \"/foo\")\n    assert response.json() == {\"bar\": True}\n```\n\n### Manual\n\nThe manual examples assume you have some external way of standing up the server\n\n`pip install responsaas`\n\n```python\nimport requests\nfrom responsaas import ResponsaasServer, Responsaas\n\n# With pytest\nfrom responsaas.pytest import create_responsaas_fixture\n\nresponsaas = create_responsaas_fixture(\"http://localhost:7564\")\n\ndef test_foo(responsaas: Responsaas):\n    responsaas.add(\"/foo\", json={\"bar\": True})\n\n    response = requests.get(responsaas.base_url + \"/foo\")\n    assert response.json() == {\"bar\": True}\n\n\n# Or completely manually.\ndef test_foo():\n    responsaas_server = ResponsaasServer(\"http://localhost:7564\")\n    with responsaas_server.activate() as responsaas:\n        responsaas.add(\"/foo\", json={\"bar\": True})\n\n        response = requests.get(responsaas.base_url + \"/foo\")\n        assert response.json() == {\"bar\": True}\n```\n\n## Why?!?\n\nUnder the hood, `repsonses` is `patch`ing the network calls being made and\nreplacing their result with the result you specify. It's very fast, convenient,\nand (by default) disallows you from making **actual** network calls.\n\n**However** the same (`patch`) strategy that makes it useful has some issues.\n\n- This can run afoul of other libraries which perform `patch` operations. The\n  issue history of responses has many instances (frequently with `moto`), where\n  patches get clobbered in one way or another.\n\n  - `responsaas` does not use `patch` at all. It is a real standalone service\n    responding to real requests.\n\n- Either through `patch` issues, or through programmer error, `responses` can be\n  **so** non-invasive that API calls accidentally get made through to the\n  original destination URL.\n\n  - `responsaas` forces you to change (or really, make configurable) the URL\n    you're hitting for tests, which should make it impossible to hit the\n    original destination url in tests on accident.\n\n- `responses` allows you to return arbitrary python objects (like exceptions)\n  which wouldn't be possible for a request to actually return.\n\n  - `responsaas` (once again), is a literal service responding to requests. The\n    requesting client code is receiving bytes over the wire, and parsing it\n    normally.\n\n- `responses` is(?) limited to mocking the `requests` library. Which doesn't\n  cover cases like `httpx`, `aiohttp`, etc.\n\n  - `responsaas` is client agnostic, given that it's a real service.\n\n- `responses` needs an additional mechanism to allow \"passthru\" requests\n\n  - `responsaas` (once again), is a literal service responding to requests, so\n    it can only return.\n\n## How?\n\nWhat's going on internally is:\n\n- Each test registers a new \"namespace\" against the `responsaas` server\n- Each new namespace corresponds to one `responses.RequestsMock`.\n- As incoming requests are received by the server, they're mapped to the request\n  shape expected by `responses`, and routed directly through its request\n  matching and responds logic.\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "",
    "version": "0.1.0",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "505aef7c2208a89a44ece6bdbe168bd91febf021693822a918581404281a008a",
                "md5": "c01125dc83525b467a98d8a3b9e2bab3",
                "sha256": "232ba7b09665d78a27af231811806656151c514c700189f34aed905456aa32a6"
            },
            "downloads": -1,
            "filename": "responsaas-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c01125dc83525b467a98d8a3b9e2bab3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<4.0",
            "size": 14442,
            "upload_time": "2023-08-24T20:31:44",
            "upload_time_iso_8601": "2023-08-24T20:31:44.461900Z",
            "url": "https://files.pythonhosted.org/packages/50/5a/ef7c2208a89a44ece6bdbe168bd91febf021693822a918581404281a008a/responsaas-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "770db030cc78ea91fa26e14dcd25456eae613be362ed417d7830c61d9c7b4af6",
                "md5": "a81e381a4506a227501ffca29fdef835",
                "sha256": "83f8697bf489d4784eb0e3a9d89d127caa88f5178a79ed560204754da7c944f2"
            },
            "downloads": -1,
            "filename": "responsaas-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "a81e381a4506a227501ffca29fdef835",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<4.0",
            "size": 14088,
            "upload_time": "2023-08-24T20:31:46",
            "upload_time_iso_8601": "2023-08-24T20:31:46.038813Z",
            "url": "https://files.pythonhosted.org/packages/77/0d/b030cc78ea91fa26e14dcd25456eae613be362ed417d7830c61d9c7b4af6/responsaas-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-24 20:31:46",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "responsaas"
}
        
Elapsed time: 0.14206s