Support validation of Response without providing Request

Abierto
#343 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
25/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
python

Línea de trabajo

Start with ResponseValidator in openapi_core.validation.response.validators and read the response-validation examples, then compare the validator code with the refactoring mentioned on the master branch. The work is complete when the documented validation flow can handle a response without the caller supplying a request, with its operation and method requirements defined and tested.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Hi,

I was planning on using the (Django REST Framework) Response validation in some unit tests. These unit tests are performing different actions on the REST API and validate the result. I would like to validate the response against the schema as well.

The problem is, all the django unit tests are based on having a self.client that is called to performing actions using response = self.client.post()..., response = self.client.get(...), etc.

So I don't have access to the request that was sent, so I can't use the pattern provided in the examples:

from openapi_core.validation.response.validators import ResponseValidator

validator = ResponseValidator(spec)
result = validator.validate(request, response)

# raise errors if response invalid
result.raise_for_errors()

# get list of errors
errors = result.errors

I went through the validator code and from what I can see now the request object is mainly used to determine which operation & method was executed. I also see there's some refactoring going on on the master branch.

Is there any way to validate the response, without providing the request object?

I tried to make a "mock" request object, but I don't know enough about the (Django) request internals yet to know what attributes and values to set.

I am also interested to know how others are using the validation. Are you using it server site as some (Django) middleware that checks requests/responses?

Lenguaje dominante
Python
Estrellas
368
Forks
140
Métricas de merge de PR
Sin PR fusionados en 30 d

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de python-openapi/openapi-core

Todos los issues de python-openapi/openapi-core

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.