HTTP Testing with GABBI


I’ve come across Gabbi, a simple declarative HTTP testing framework, which uses YAML files and Python to run HTTP component testing.
I found it a bit difficult to get into, so heres a simple set of examples and use-cases.
I’ve made some simple examples which you can find on my GitHub: Checkout my Gabbi Examples

Why Choose Gabbi?

It’s Simple
Tests are Readable
It’s Extendable
It’s for ANY HTTP stack
You don’t need to know Python

Getting Started

Test Declaration

# Various tests of Google

- name: Google Issues Redirect
  desc: Test for a redirect from
  method: GET
  status: 301||302


- name: Google Redirect Resolves OK
  desc: Follow the redirect from Google verify we get a valid page
  method: GET
  redirects: True
  status: 200
    Set-Cookie: /.../
    Server: gws
    Content-Type: text/html; charset=ISO-8859-1

- name: Uploads forbidden
  desc: POST some data to and see we get rejected
  method: POST
  data: "user=me"
  status: 405
    Server: gws
    Content-Type: text/html; charset=UTF-8
    Allow: GET, HEAD

Simple HTTP Tests



import cookielib, urllib, urllib2, os
from gabbi import fixture
param = {'username':'admin', 'password':'password'}

class NoRedirectHandler(urllib2.HTTPRedirectHandler):
    """ Disable redirect 
    def http_error_302(self, req, fp, code, msg, headers):
        print "Redirect"
        return urllib2.HTTPRedirectHandler.http_error_302(self, req, fp, code, msg, headers)
    http_error_301 = http_error_303 = http_error_307 = http_error_302

class AuthenticationFixture(fixture.GabbiFixture):

    def start_fixture(self):
        """Create some sample data
        p = urllib.urlencode(param)
        cj = cookielib.CookieJar()
        opener = urllib2.build_opener(NoRedirectHandler, urllib2.HTTPCookieProcessor(cj))
        response = urllib2.urlopen(url, p)
        cookies = { k.value for k in cj}
        os.environ['cookie'] = "ci_session=%s" % cookies['ci_session'] #c[0].split(';')[0]
        cookie = "ci_session=%s" % cookies['ci_session']
    def stop_fixture(self):

Running Tests

Tests can be run using gabbi-run, called per test script (per yaml file) or using an automated test loader. Fixtures aren’t supported through gabbi-run.

gabbi-run: Useful for initial prototyping and development gabbi-run [host[:port]] < /my/test.yaml Full automation and permits the use of fixtures

Automating Tests

I’ve used Gabbi to develop automated tests for my MyPOS Web Application, developed with CodeIgniter/PHP
Gabbi Tests can be run