pyresttest icon indicating copy to clipboard operation
pyresttest copied to clipboard

define headers in config

Open esonger opened this issue 8 years ago • 2 comments

I am trying to do this:


---
- config:
  - testset: 'api test'
 - variable_binds: {headers: {'lang': 'en','version': '1.0', ... }

- test:
  - group: 'user api'
  - name: 'test'
  - url: '/profile'
  - method: 'post'
  - headers: {template: $headers}
  - body: 'cover=cover'
  - validators:
    - compare: {jsonpath_ming: 'error', comparator: 'eq', expected: 0}

but

pyresttest/pyresttest/tests.py", line 207, in get_headers return dict(map(template_tuple, self._headers.items())) AttributeError: 'str' object has no attribute 'items'

how can do ?

esonger avatar Aug 30 '16 08:08 esonger

Hi @esonger

I run in the same error, but I was trying to use a generator instead of a variable_binds.

I'm not sure if this will help, but I could setup header this way:

- config:`
    - testset: "API Basic tests"
    - generators:
        - 'authgen': {type: 'authtime', uuid: abcde}
    - variable_binds: {authid: '$auth_token'}
- test:
    - group: "Test"
    - name: "Teste header generator "
    - url: "/api/v1/resource/"
    - method: 'POST'
    - expected_status: [200,201]
    - generator_binds: {auth_token: authgen}
    - headers: {template: {"X_AUTH": $auth_token}}

maybe you need to do the variable_bind in the test, not in config section

claudiobastos avatar Oct 16 '16 00:10 claudiobastos

@claudiobastos 's solution worked for me. Althought the following is not needed. " - variable_binds: {authid: '$auth_token'}"

amirma avatar Jan 13 '17 07:01 amirma