2

I am using Dredd to test one of my endpoints. I think the test is failling due to the headers, because I'm getting the following expected:

headers:
    Content-Type: application/json

body:
[
  {
    "id": 15107,
    "name": "Route Name",
    "date": "2022-01-27T09:00:00",
    "full_user_name": "Test Admin",
    "url": "api/2/users/1/routes/15107"
  }
]
statusCode: 200

And the following actual:

statusCode: 200
headers:
    date: Wed, 02 Feb 2022 12:54:11 GMT
    server: WSGIServer/0.2 CPython/3.6.9
    content-type: application/json; charset=utf-8
    vary: Accept, Cookie
    allow: GET, POST, PATCH, HEAD, OPTIONS
    access-control-allow-origin: None
    access-control-allow-methods: POST,GET
    access-control-allow-headers: Origin,Content-Type,Accept,Accept-Encoding
    access-control-allow-credentials: true
    x-frame-options: SAMEORIGIN
    content-length: 136

bodyEncoding: utf-8
body:
[
  {
    "id": 15107,
    "name": "Route Name",
    "date": "2022-01-27T09:00:00",
    "full_user_name": "Test Admin",
    "url": "api/2/users/1/routes/15107"
  }
]

The only difference I see is the headers. Is there any way to ignore those? Like, for instance, content-length header. Maybe I only need to include the auth header in the Open API file. Right now I have specified documentation as follows:

...
  securitySchemes:
    ApiKey:
      type: apiKey
      name: Authorization
      in: header
      description: Authentication token
security:
  - ApiKey: []

And running dredd as follows with a python server:

dredd oas-routes.yaml http://127.0.0.1:8000/api/2/users/1/routes --header="Authorization: Token 6b232e1c00bbc8b12d0066a483bf401009fbdb21"

Any idea how to do this correctly? I'm quite new to testing with dredd to be honest.

Antonio Gamiz Delgado
  • 1,871
  • 1
  • 12
  • 33
  • Same question for me. Did you came up with some solution? – IvanMikhalka Nov 17 '22 at 17:29
  • Posted similar [question](https://stackoverflow.com/questions/74487193/dredd-verification-response-body-and-headers/74490770#74490770). Running with debug log level helped me to recognise issue: I was needed to have `application/json; charset=utf-8` instead of `application/json` for response format. – IvanMikhalka Nov 18 '22 at 14:03

0 Answers0