O'Reilly logo

Python Requests Essentials by Bala Subrahmanyam Varanasi, Rakesh Vidya Chandra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Working with HTTPretty

There are three main steps to be followed while dealing with HTTPretty:

  1. Enable HTTPretty
  2. Register the uniform resource locator to HTTPretty
  3. Disable HTTPretty

We should enable HTTPretty initially, so that it will apply monkey patching; that is, a dynamic replacement of the attributes of the socket module. We will be using the function register_uri for registering the uniform resource locator. The register_uri function takes class, uri and body as arguments:

   method: register_uri(class, uri, body)

And at the end of our testing process, we should disable HTTPretty so that it doesn't alter the behavior of the other. Let us take a look at using HTTPretty with an example:

import httpretty
import requests
from sure import expect
 

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required