Skip to content

Commit

Permalink
Fix generate, docs, bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
kvs8 committed Sep 26, 2023
1 parent 48de5b6 commit 6c8e0a3
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 5 deletions.
75 changes: 73 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ The host looks like this, for the ability to send requests for tests using an ht
- Headers are optional
- Json-body is optional

Examples can be found [here](tests/unit/test_data/get_requests.http) and [here](tests/unit/test_data/post_requests.http)
Examples can be found [here](https://github.com/kvs8/vedro-replay/blob/main/tests/unit/test_data/get_requests.http)
and [here](https://github.com/kvs8/vedro-replay/blob/main/tests/unit/test_data/post_requests.http)

### Running tests
To run the tests, need two hosts to send requests to them. You need to set environment variables in any convenient way:
Expand All @@ -140,4 +141,74 @@ def prepare_byid(response) -> Response: # Generated method for scenario byid.py
exclude_headers = ['date'] # Date header exclusion
exclude_body = ['meta.api_version'] # Excluding a field from the body
return filter_response(JsonResponse(response), exclude_headers, exclude_body)
```
```

To ignore headers, simply specify their names separated by commas, for example:
```python
exclude_headers = ['header-name', 'x-header-name']
```

To exclude json fields from the response, use the following format:
```json
{
"meta": {
"api_version": "1.0.0",
"issue_date": "20230926"
},
"items": [
{
"id": 1,
"name": "chair"
},
{
"id": 2,
"name": "table"
}
]
}
```

Exclude by json keys:
```python
exclude_body = ['meta.api_version']
```
Result:
```json
{
"meta": {
"issue_date": "20230926"
},
"items": [
{
"id": 1,
"name": "chair"
},
{
"id": 2,
"name": "table"
}
]
}
```

Exclude for each list element:
```python
exclude_body = ['items.*.id']
```
Result:
```json
{
"meta": {
"api_version": "1.0.0",
"issue_date": "20230926"
},
"items": [
{
"name": "chair"
},
{
"name": "table"
}
]
}
```
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def find_required():

setup(
name="vedro-replay",
version="0.2.0",
version="0.2.1",
description="vedro-replay package",
long_description=open("README.md").read(),
long_description_content_type="text/markdown",
Expand Down
5 changes: 3 additions & 2 deletions vedro_replay/generator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import os
from abc import ABC, abstractmethod
from pathlib import Path
from pathlib import Path, PurePosixPath
from types import FunctionType
from typing import Any, List

Expand Down Expand Up @@ -165,6 +165,7 @@ def _get_file_with_requests(self) -> List[str]:
return [
file for file in os.listdir(self.__requests_dir)
if os.path.isfile(os.path.join(self.__requests_dir, file))
and PurePosixPath(file).suffix in ['.txt', '.http']
]

def _get_route(self, file_path: str) -> str:
Expand All @@ -185,7 +186,7 @@ def generate(args: Any) -> None:

try:
getattr(MainGenerator(requests_dir=args.requests_dir, force=args.force, log=log), args.option)()
log.info("\nThe necessary files have been generated!\n"
log.info("The necessary files have been generated!\n"
"To run the tests, you need to specify two api url to which request will be sent."
"You need to set environment variables in any convenient way, for example:\n"
"export GOLDEN_API_URL=https://golden.app && export TESTING_API_URL=https://test.app && vedro run")
Expand Down
1 change: 1 addition & 0 deletions vedro_replay/templates/contexts.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ async def testing_response(request: Request, prepare_response_method) -> Respons
api = Api(Config.TESTING_API_URL)
response = await api.do_request(request=request)
return prepare_response_method(response)

1 change: 1 addition & 0 deletions vedro_replay/templates/interfaces.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ class Api(AsyncHTTPInterface):
headers=request.headers,
json=request.json_body
)

0 comments on commit 6c8e0a3

Please sign in to comment.