This project uses the following API endpoint https://jsonplaceholder.typicode.com/
The scripts therein does the following:
- Does a GET request to the /users endpoint.
- Validates the response code to be 200.
- Validates the response time to be less than 200ms.
- Iterates over all elements of the json response body and print out all company names ending in “ Group”.
- Clone the repository
$ git clone https://github.com/jaymutuku/python-api-tests
$ cd to python-api-tests/
$ pip3 install virtualenv
$ virtual -p python3 venv
$ source venv/bin/activate
Incase you get an error in the second step above: command 'virtualenv' not found ... Then
$ sudo apt install virtualenv
$ pip install requests ijson
You don't need to install the unittest library is a built-in library.
$ pip freeze > requirements.txt
- Discover and run the tests!
$ python -m unittest discover
- Expected Output
Company Name: Johns Group
Company Name: Abernathy Group
.Response Status: 200
.Response Time: 0.478977
F
======================================================================
FAIL: test_response_time (users_test.test_users.APITests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/<username>/Desktop/humanitec/answers/python-api-tests/users_test/test_users.py", line 20, in test_response_time
self.assertLess(responseTime,0.2)
AssertionError: 0.478977 not less than 0.2
----------------------------------------------------------------------
Ran 3 tests in 1.587s
FAILED (failures=1)