Skip to main content

Python HTTP Tests for Humans.

Project description

# Requestests

This is an testing/validation extension on top of the ever-so-popular [requests library](https://github.com/kennethreitz/requests). The library relies on duck typing to add testability of a response object. Given that, leveraging the validation mechanism in requestests is both lightweight and simple!

## Installation

The library can be installed via:

pip install requestests

## Usage

Using the built-in validations in requestests is intended to be an extremely intuitive extension of using requests:

>>> import requestests
>>> r = requestests.get('https://api.github.com/user', auth=('user', 'pass'))
>>> r.validate_code(requests.code.ok)
>>> r.validate_header_like('Content-Type', 'application/json')
>>> r.encoding
'utf-8'
>>> r.text
u'{"type":"User"...'
>>> r.json()
{u'disk_usage': 368627, u'private_gists': 484, ...}

What is happening is that the assertion operation is being abstracted out. The traditional method of asserting on the response:

r = requests.get(’https://api.github.com/user’) assert r.status_code == requests.codes.ok, “Expecting a 200 response code”

can be simplified to this:

r = requestests.get(’https://api.github.com.user’) r.validate_code(requests.code.ok)

## Or even to this r = requestests.get(’https://api.github.com.user’).validate_code(requests.code.ok)

Validations follow the builder paradigm, so operations can be chained together:

entity = requestests.get(’https://api.github.com.user’)

.validate_code(requests.code.ok) .validate_header_like(‘Content-Type’, ‘application/json’) .json()

What happens in this scenario is that if any of the validations fails, an AssertionError is raised; otherwise, at the end of this requests, you would have:

  1. Validated that the request was successful

  2. Validated the ‘Content-Type’ is ‘application/json’

  3. and deserialized the response.text

## Documentation

The projects homepage can be found [here](https://github.com/gradeawarrior/requestests).

## Package Dependencies:

# Copyright

Copyright (c) 2016 Peter Salas. See LICENSE for further details.

Release History

### 1.2.2 (2017-01-09)

New Features

  • Fixing major issue with installing requestests v1.2.1 from PyPi server

### 1.2.1 (2017-01-09)

New Features

  • Fixing major issue with installing requestests v1.2.0 from PyPi server

  • Updates to licensing information

### 1.2.0 (2016-11-16)

New Features

  • Migration of ownership to personal Github account for continued support and enhancements

  • Update of documentation for easier readability on both github and pypi

  • Development enhancements to use virtualenv versus system python environment

### 1.1.2 (2016-09-29)

New Features

  • A more comprehensive set of Validation methods for evaluating things like (i) response codes, (ii) response content, (iii) response headers, and (iv) time-to-last-byte (ttlb)

  • Adding better assertion debug messages for determining what failed and why. For example: http://www.google.com/foobar - 200 == 301, which basically means that the request to http://www.google.com/foobar failed because we were expecting 200 but got a 301

  • Adding several unit-tests for ensuring the code continues to work

### 1.0.0 (2016-06-01)

New Features

  • First release of requestests testing tool for the world

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

requestests-1.2.2.tar.gz (8.9 kB view details)

Uploaded Source

File details

Details for the file requestests-1.2.2.tar.gz.

File metadata

File hashes

Hashes for requestests-1.2.2.tar.gz
Algorithm Hash digest
SHA256 1497b72fb260044c1a58244bab9ec38c344facaf2040150f39eabe663f96d55b
MD5 73a4acae6c6368ca31bf6687267d75ae
BLAKE2b-256 6a4de48c34c7fd92df4aa3aa2ec42251685c28783f9b47c06e2e0dc95bdca9e1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page