API Automation using Python


So Today we cover one of the major implications of testing in Web 2.0 setting. Testing the REST apis. 

We will be using a library called pyresttest , a REST testing and API microbenchmarking tool. It allows us to have a simple configuration file defined in basic YAML or JSON and no hassle of writing separate unit tests is needed. The sad part is it supports out of the box only on Linux and Mac os, (better luck Windows users :p). However we have our workarounds on getting it running on windows.

In Windows we can use it by installing using pycurl. In Linux and it's siblings you can start using it on a breeze by installing it using the command 

apt-get install python-pycurl

Now a days in the era of cloud all the orchestration is done via a YAML configuration. AWS and CloudFoundry are the precursors in using YAML type configurations. 

Create a YAML file by using this command in your CMD 

pip install url yaml-file

In your YAML file enter the configuration as shown :


As you can see, tests are defined in YAML format.

There are 5 top level test syntax elements:

  • url: a simple test, fetches given url via GET request and checks for good response code
  • test: a fully defined test (see below)
  • benchmark: a fully defined benchmark (see below)
  • config or configuration: overall test configuration (timeout is the most common option)
  • import: import another test set file so you Don't Repeat Yourself

The major advantage of pyresttest is

  • It is written for an environment where Python is not the sole or primary language

So let's get our API's automated seamlessly using pyresttest and integrate DevOps into our application pipeline.

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.