Giter Site home page Giter Site logo

shubham-padia / dredd-hooks-python Goto Github PK

View Code? Open in Web Editor NEW

This project forked from apiaryio/dredd-hooks-python

0.0 1.0 0.0 52 KB

Python Hooks for Dredd API Testing Framework

Home Page: http://dredd.rtfd.org/en/latest/hooks-python/

License: MIT License

Ruby 6.96% Python 65.01% Gherkin 28.03%

dredd-hooks-python's Introduction

Python Hooks Bridge for Dredd API Testing Framework

image

About

This package contains a bridge between Dredd API Testing Framework and Python environment to ease implementation of testing hooks provided by Dredd. Write Dredd hooks in Python to glue together API Blueprint with your Python project

Usage example:

import dredd_hooks as hooks

@hooks.before_all
def foo(transactions):
    for t in transactions:
        t['request']['headers']['content-type'] = 'application/json'

Download

You can see all the available versions at PyPI.

From source (tar.gz or checkout)

Unpack the archive, enter the dredd-hooks-python directory and run:

python setup.py install

Setuptools/PyPI

Alternatively it can be installed from PyPI, either manually downloading the files and installing as described above or using:

pip install dredd_hooks

Usage

  1. Create a hook file in hooks.py:
import dredd_hooks as hooks

@hooks.before("Machines > Machines collection > Get Machines")
def before_hook(transaction):
    transaction['skip'] = "true"
  1. Run it with Dredd:

    $ dredd apiary.apib localhost:3000 --language python --hookfiles ./hooks.py

API

Module dredd_hooks defines following decorators before, after, before_all, after_all, before_each, after_each, before_validation, before_each_validation. before, before_validation and after hooks are identified by transaction name.

You can combine those decorators together. So one function can be used for different hooks but be aware that some hooks have a list of all transactions as an argument and not a single transaction.

import dredd_hooks as hooks

@hooks.after_all
@hooks.before_all
@hooks.before_each
@hooks.after_each
@hooks.before_validation('Machines > Machines collection > Get Machines')
@hooks.before("Machines > Machines collection > Get Machines")
@hooks.after("Machines > Machines collection > Get Machines")
def multi_hook_function(trans):
   if isinstance(trans, list):
       print('called with list of transactions')
   else:
       if trans['name'] == 'Machines > Machines collection > Get Machines':
           trans['skip'] = 'true'

Usage is very similar to sync JS hooks API

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-newfeature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push (git push origin my-new-feature)
  5. Create a new Pull Request

Testing

Don't forget about tests, see test directory. The project uses unittest package and tox.

For integration test with Dredd interface the project uses ruby based aruba so to get it running make sure you have Ruby installed and then do:

$ bundle install

After the setup you can run the test easily with:

$ bundle exec cucumber

More details about the integration test can be found in the dredd-hooks-template repo

copyright

Copyright (c) 2015 Apiary Czech Republic, s.r.o.

license

MIT, see LICENSE for details.

dredd-hooks-python's People

Contributors

geekbrother avatar honzajavorek avatar kylef avatar martijnarts avatar romansklenar avatar shubham-padia avatar w-vi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.