Skip to content
This repository has been archived by the owner on Nov 19, 2023. It is now read-only.

Commit

Permalink
Unpin djangorestframework (#279)
Browse files Browse the repository at this point in the history
* fix: Unpin `djangorestframework`

The blocking drf-yasg issue has been resolved
axnsan12/drf-yasg#810

* chore: Add package extras

* chore: Bump version from 2.1.2 to 2.1.3

* chore: Update pre-commit hooks

* docs: Update readme
  • Loading branch information
sondrelg authored Oct 7, 2022
1 parent 5029a33 commit ef24951
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 142 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
python -m venv .venv
source .venv/bin/activate
pip install wheel setuptools pip -U
poetry install --no-interaction --no-root
poetry install --no-interaction --no-root --extras drf-spectacular --extras drf-yasg
if: steps.cache-venv.outputs.cache-hit != 'true'
- run: |
source .venv/bin/activate
Expand Down
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/psf/black
rev: 22.8.0
rev: 22.10.0
hooks:
- id: black

Expand Down Expand Up @@ -31,7 +31,7 @@ repos:
]

- repo: https://github.com/asottile/pyupgrade
rev: v2.38.1
rev: v3.0.0
hooks:
- id: pyupgrade
args: [ "--py3-plus", "--py36-plus", "--py37-plus" ]
Expand All @@ -42,7 +42,7 @@ repos:
- id: isort

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.971
rev: v0.982
hooks:
- id: mypy
additional_dependencies:
Expand Down
32 changes: 13 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,32 @@ pip install drf-openapi-tester

## Usage

First instantiate one or more instances of SchemaTester:
Instantiate one or more instances of `SchemaTester`:

```python
from openapi_tester import SchemaTester

schema_tester = SchemaTester()


```

If you are using either [drf-yasg](https://github.com/axnsan12/drf-yasg)
or [drf-spectacular](https://github.com/tfranzel/drf-spectacular) this will be auto-detected, and the schema will be
loaded by the SchemaTester automatically. If you are using schema files though, you will need to pass the file path to
the tester:
loaded by the `SchemaTester` automatically.

If you are using schema files, you will need to pass the file path:

```python
from openapi_tester import SchemaTester

# path should be a string
schema_tester = SchemaTester(schema_file_path="./schemas/publishedSpecs.yaml")


```

Once you instantiate a tester, you can use it to test responses:
Once you've instantiated a tester, you can use it to test responses:

```python
from openapi_tester.schema_tester import SchemaTester

# you need to create at least one instance of SchemaTester.
# you can pass kwargs to it
schema_tester = SchemaTester()


Expand All @@ -60,7 +55,7 @@ def test_response_documentation(client):
schema_tester.validate_response(response=response)
```

If you are using the Django testing framework, you can create a base APITestCase that incorporates schema validation:
If you are using the Django testing framework, you can create a base `APITestCase` that incorporates schema validation:

```python
from rest_framework.response import Response
Expand Down Expand Up @@ -131,7 +126,7 @@ def my_test(client):

### case_tester

The case tester argument takes a callable that is used to validate the key casings of both schemas and responses. If
The case tester argument takes a callable that is used to validate the key case of both schemas and responses. If
nothing is passed, case validation is skipped.

The library currently has 4 built-in case testers:
Expand All @@ -141,11 +136,11 @@ The library currently has 4 built-in case testers:
- `is_camel_case`
- `is_kebab_case`

You can of course pass your own custom case tester.
You can use one of these, or your own.

### ignore_case

List of keys to ignore when testing key casing. This setting only applies when case_tester is not `None`.
List of keys to ignore when testing key case. This setting only applies when case_tester is not `None`.

### validators

Expand All @@ -171,7 +166,7 @@ def my_uuid_4_validator(schema_section: dict, data: Any) -> Optional[str]:

### field_key_map

You can pass an optional dictionary that maps custom url parameter names into values, for cases where this cannot be
You can pass an optional dictionary that maps custom url parameter names into values, for situations where this cannot be
inferred by the DRF `EndpointEnumerator`. A concrete use case for this option is when
the [django i18n locale prefixes](https://docs.djangoproject.com/en/3.1/topics/i18n/translation/#language-prefix-in-url-patterns).

Expand All @@ -185,10 +180,9 @@ schema_tester = SchemaTester(field_key_map={

## Schema Validation

When the SchemaTester loads a schema, it runs it through
[OpenAPI Spec validator](https://github.com/p1c2u/openapi-spec-validator) which validates that the schema passes without
specification compliance issues. In case of issues with the schema itself, the validator will raise the appropriate
error.
When the SchemaTester loads a schema, it parses it using an
[OpenAPI spec validator](https://github.com/p1c2u/openapi-spec-validator). This validates the schema.
In case of issues with the schema itself, the validator will raise the appropriate error.

## Django testing client

Expand Down
Loading

0 comments on commit ef24951

Please sign in to comment.