Skip to main content

# 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

Release files for requestests 1.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for requestests 1.2.2
File Size Uploaded
requestests-1.2.2.tar.gz 8.9 kB Details

Release files / requestests-1.2.2.tar.gz

Download URL requestests-1.2.2.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
1497b72fb260044c1a58244bab9ec38c344facaf2040150f39eabe663f96d55b
BLAKE2b-256 checksum
How to use checksums
6a4de48c34c7fd92df4aa3aa2ec42251685c28783f9b47c06e2e0dc95bdca9e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.2.2 This release

1 release file

1.2.1

1 release file

1.2.0

1 release file

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page