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.