From 1b6a975f604664ff862e217d44b9f58459095760 Mon Sep 17 00:00:00 2001 From: Na'aman Hirschfeld Date: Sat, 20 Feb 2021 17:05:55 +0200 Subject: [PATCH] updated readme --- README.md | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 494c3adc..df9d9b59 100644 --- a/README.md +++ b/README.md @@ -111,9 +111,9 @@ from openapi_tester import SchemaTester, is_camel_case from tests.utils import my_uuid_4_validator schema_test_with_case_validation = SchemaTester( - case_tester=is_camel_case, - ignore_case=["IP"], - validators=[my_uuid_4_validator] + case_tester=is_camel_case, + ignore_case=["IP"], + validators=[my_uuid_4_validator] ) @@ -139,7 +139,7 @@ def my_test(client): ) ``` -### Case tester +### case_tester The case tester argument takes a callable that is used to validate the key casings of both schemas and responses. If nothing is passed, case validation is skipped. @@ -153,11 +153,11 @@ The library currently has 4 built-in case testers: You can of course pass your own custom case tester. -### Ignore case +### ignore_case List of keys to ignore when testing key casing. This setting only applies when case_tester is not `None`. -### Validators +### validators List of custom validators. A validator is a function that receives two parameters: schema_section and data, and returns either an error message or `None`, e.g.: @@ -173,12 +173,26 @@ def my_uuid_4_validator(schema_section: dict, data: Any) -> Optional[str]: try: result = UUID(data, version=4) if not str(result) == str(data): - return f"Expected uuid4, but received {data}" + return f"Expected uuid4, but received {data}" except ValueError: return f"Expected uuid4, but received {data}" return None ``` +### field_key_map + +You can pass an optional dictionary that maps custom url parameter names into values, for cases 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). + +```python +from openapi_tester import SchemaTester + +schema_tester = SchemaTester(field_key_map={ + "language": "en", +}) +``` + ## Schema Validation When the SchemaTester loads a schema, it runs it through