Giter VIP home page Giter VIP logo

rest_api_demo_tester's Introduction

REST API Tester

This repo was created as a solution for the following challenge: REST API Demo v1.2

Recommendations after testing

Fix dependency issue on API

Werkzeug 0.16.1 is not compatible with the most current version of Flask. But updating Werkzeug will cause flask-restplus to not work. The community switched to flask-restx as flask-restplus lacked sufficient support.

I recommend two options:

  • Switch to flask-restx for a proper fix, but that could prove changing a lot of the code
  • Add Flask==1.1.1 to the dependencies (What I did). Forcing a compatible version of Flask

For the latter, please check my changes to:

  • ./rest_api_demo-techtest1.2/requirements.txt
  • ./rest_api_demo-techtest1.2/setup.py

Bugs found

Category name missing first letter

When POSTING a new category, the name will miss the first letter

Blog Posts won't update past the first page

Out of the scope as this endpoint wasn't supposed to be tested, but I found it manually and decided to add it. When using GET Blog posts you can't go past the first page.

Getting started

The API was not functioning from the start due to Python dependency issues. I added a quick fix to it and it is also on this repo, inside the rest_api_demo-techtest1.2 folder.

Database folder

If you choose to use the API from this Repo, everything is already configured. If not, please change database_path on config.json to the db.sqlite file of your API instalation. Also ensure you have writing permission to the same folder.

This is because the test resets the database to a default stage by copying the database from the default_database folder.

Python requirements

This application requires Python 3.6+ To install the requirements pip is necessary

It is highly recommended to set up a virtual environment before.

To install the requirements simply call

pip install -r requirements.txt

The requirements are:

  • PyTest for testing
  • requests for interacting with HTTP protocol
  • colorama, pytest-html and ansi2html for a colourful report

Running the Test suite

  • On Linux
./run_test.sh
  • On Windows 8+ (Not tested!)

Windows PowerShell is required

./run_test.ps1
  • Any command line
py.test test_REST_API.py -v --html=report.html --self-contained-html 

Tests

Reset database to default

Rewrites the db.sqlite file to a default stage

GET Blog categories

  • Sends a GET request for /api/blog/categories
  • Checks HTTP response code
  • Checks if 'id', and 'name' are in the response
  • Checks if there is nothing else in the response

POST, GET, and DELETE Blog Categories

  • Posts a blog category
  • Check if it was posted using GET
    • endpoint: /blog/categories/
  • Deletes it

3 test cases for category names:

  • "Category name"
  • "A category name that is quite longer"
  • "Category@name-with1symbols."

POST, GET and DELETE with big payload

  • Same tests as above but
  • Starts with a payload of random characters of size 100
  • Sends the big payload and increases the next by 50
  • Repeat 5 times
  • Check for errors

POST, GET by id, and DELETE Blog Categories

Same as above but using GET for the following endpoint:

  • /blog/categories/{id}

POST, GET by id, and DELETE with big payload

  • Same tests as above but
  • Starts with a payload of random characters of size 100
  • Sends the big payload and increases the next by 50
  • Repeat 5 times
  • Check for errors

POST, DELETE and GET Blog categories

  • Posts a blog category
  • Deletes it
  • Check if it was deleted using GET

3 test cases for category id and names:

  • 4, "Category name"
  • 5, "A category name that is quite longer"
  • 6, "Category@name-with1symbols."

POST, PUT, GET and DELETE Blog categories

  • Posts a blog category
  • Updates it with PUT
  • Check if it was properly updated with GET
  • Deletes it

3 test cases for category id and names:

  • 4, "Category name"
  • 5, "A category name that is quite longer"
  • 6, "Category@name-with1symbols."

POST, PUT, GET and DELETE with big payload

  • Same tests as above but
  • Starts with a payload of random characters of size 100
  • Sends the big payload and increases the next by 50
  • Repeat 5 times
  • Check for errors

GET invalid id format

  • Tries getting 100 unexisting ids
  • Tries getting 100 non integer ids at random
  • Check that each case is rejected

POST invalid id format

  • Tries posting 100 invalid ids at random and checks they are rejected
    • Random ids will be random characters of random length
    • Excluding digits and ':'

POST invalid name format

  • Tries posting 100 invalid 'name' format and checks if they are rejected
    • Random names will be random floats and integers

PUT invalid id format

  • Tries updating 100 missing ids
  • Tries updating 100 invalid ids at random and checks they are rejected
    • Random ids will be random characters of random length
    • Excluding digits and ':'

PUT invalid name format

  • Tries updating 100 invalid 'name' format and checks if they are rejected
    • Random names will be random floats and integers

DELETE invalid id format

  • Tries deleting 100 non existing ids and checks if they are rejected
  • Tries deleting 100 invalid ids at random and checks if they are rejected
    • Random ids will be random characters of random length

Test Blog post GET

  • Extra test just to cover one issue I found manually
  • Tries to get posts with random 'page' and 'per_page' parameters
  • Checks if the 'page' and 'per_page' numbers are consistent
  • Checks if 'per_page' and 'pages' are mathematically consistent with 'total'

rest_api_demo_tester's People

Contributors

gbritoda avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.