# Mock IT Adapter

<details>
  <summary>RU</summary>

</details>

A Python adapter for interacting with Mock IT API.

## Installation

```bash
pip install mock-it-adapter
```
## Usage

Create client for connection to Mock IT server:
```doctest
from mock_it_adapter import MockITClient

client = MockITClient(base_url)
""" Create client.

    Args:
        base_url (str): Mock IT server URL. 
    
    Returns:
        A Requests session.
"""
```

```doctest
create_mock(name, method, endpoint, status, response_body, matcher)
""" Create new mock.

    Args:
        method: [str] = Mock request http method.
        endpoint: [str] = Mock endpoint.
        name: Optional[str] = Mock name. If not specified, generated by pattern: "{endpoint}_{matcher.value}"
        status: Optional[str] = Mock response status code. Default - 200.
        response_body: Optional[str] = Mock response body.
        matcher: Optional[Matcher] = A matcher for the request trigger condition.
        
    Returns:
        Created mock model.
"""
```

### Example:
```doctest
from mock_it_adapter import MockITClient

client = MockITClient(base_url="http://localhost:20000")

client.create_mock(
    method="POST",
    endpoint="/new_mock_endpoint",
    name="example_mock_name_without_matcher",
    response_body="default mock body"
)
```
We may have multiple instances of mocs for the same endpoint:
```doctest
client.create_mock(
    method="POST",
    endpoint="/new_mock_endpoint",
    name="example_mock_name_with_matcher",
    status=201,
    response_body="{\"Morpheus\": \"Wake up, Neo... The Matrix has you... Follow the white rabbit...\"}"
    matcher=Matcher(
        matcher_type=MatcherType.KEY_TO_VALUE,
        key="name",
        value="Neo"
    )
)
```
#### How it works
Created mock url: http://localhost:20000/new_mock_endpoint

When request contains `key="name"` with `value="Neo"` we get in the response with body: `"{"Morpheus": "Wake up, Neo... The Matrix has you... Follow the white rabbit..."}"`

If request key and value not matched we get default response with body: `default mock body`
