-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhooks.py
29 lines (20 loc) · 1.12 KB
/
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
27
28
29
import json
import dredd_hooks
response_stash = {}
@dredd_hooks.after('/todo > Creates a task > 201 > application/json')
def save_created_task(transaction):
response_payload = transaction['real']['body']
task_id = json.loads(response_payload)['id']
response_stash['created_task_id'] = task_id
@dredd_hooks.before('/todo/{task_id} > Returns the details of a task > 200 > application/json')
def before_get_task(transaction):
transaction['fullPath'] = '/todo/' + response_stash['created_task_id']
transaction['request']['uri'] = '/todo/' + response_stash['created_task_id']
@dredd_hooks.before('/todo/{task_id} > Replaces an existing task > 200 > application/json')
def before_put_task(transaction):
transaction['fullPath'] = '/todo/' + response_stash['created_task_id']
transaction['request']['uri'] = '/todo/' + response_stash['created_task_id']
@dredd_hooks.before('/todo/{task_id} > Deletes an existing task > 204')
def before_delete_task(transaction):
transaction['fullPath'] = '/todo/' + response_stash['created_task_id']
transaction['request']['uri'] = '/todo/' + response_stash['created_task_id']