Skip to content

Guidelines about Dredd hooks

Shubham Padia edited this page Jun 24, 2017 · 1 revision

This section assumes that you're familiar with Dredd, dredd hooks and how both of them work. Before going further ensure that you've also read the following:

Guidelines:

  • Currently the hooks make sure that a fresh database is created before each request, so each of the request is running in an isolated manner.
  • Please populate the database further with request specific data in the before hook of each request.
  • Make sure you add a docstring in each function with the request method and url endpoint to be tested. e.g POST /events/1/discount-codes
  • In the docstring, do not use syntax like POST /events/{identifier}/discount-codes instead of POST /events/1/discount-codes. Mention the identifier of the resource to be tested explicitly.
  • Please do not use any functions from api/helpers or helpers in the hook file, the tests should be independent from them.
  • Please ensure that your hook function names are according to the following example. For Event Topics, each hook function name should start with event_topic. Please take care that the terms in the function name are singular. Followed by event topic should be the name of the request method. In terms of GET, get_detail and get_list are used.

Determining the transaction names:

  • e.g for
# Group Discount Codes
Discount Codes related to the events.

---- filler for attribute tables --- 

## Discount Code Collection [/events/{event_id}/discount-codes{?page%5bsize%5d,page%5bnumber%5d,sort,filter}] 

----- filler ---

### List All Discount Codes [GET]
Get a list of Discount Codes.

the transaction name will be

@hooks.before("Discount Codes > Discount Code Collection > List All Discount Codes")
def discount_code_get_list(transaction):
    """
    GET /events/1/discount-codes
    :param transaction:
    :return:
    """
    transaction['skip'] = True