Support validation of Response without providing Request

Aperta
#343 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
25/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
python

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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?

Lingua principale
Python
Stelle
368
Fork
140
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di python-openapi/openapi-core

Tutte le issue di python-openapi/openapi-core

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.