-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhooks.py
26 lines (17 loc) · 938 Bytes
/
hooks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import json
import dredd_hooks
response_stash = {}
@dredd_hooks.after('/todo/ > Creates an task > 201 > application/json')
def save_created_task(transaction):
response_payload = transaction['results']['fields']['body']['values']['actual']
task_id = json.loads(response_payload)['id']
response_stash['created_task_id'] = task_id
@dredd_hooks.before('/todo/{item_id} > Returns the details of a task > 200 > application/json')
def before_get_task(transaction):
transaction['fullPath'] = '/todo/' + response_stash['created_task_id']
@dredd_hooks.before('/todo/{item_id} > Updates an existing task > 200 > application/json')
def before_put_task(transaction):
transaction['fullPath'] = '/todo/' + response_stash['created_task_id']
@dredd_hooks.before('/todo/{item_id} > Deletes an existing task > 204')
def before_delete_task(transaction):
transaction['fullPath'] = '/todo/' + response_stash['created_task_id']