testrest
Framework for writing test for RESTful APIs
How to use it
Create some tests, (from example.py)
import testrest
api = testrest.Api("http://localhost:8080")
collections = api.endpoint("collections")
collections.test("Create new collection", "POST", 201,data ={'Password':"dynamite-dance-123"})
collections.test("Handle wrong password", "POST", 403,data ={'Key':"failed-key"})
collections.test("Handle empty", "POST", 400)
collections.test("Get collections", "GET", 200)
collection_item = collections.json_response["Payload"]
api.endpoint("documents").test("Crate document","POST", 201, data = {'Collection':collection_item, 'Content': "Append me"})
document_item = api.endpoint("documents").json_response['Payload']
api.endpoint("documents", document_item).test("Update document","PUT", 20, data = {'Content': "Append me"})
run file,
python example.py
0:00:00.045434 NOK POST http://localhost:8080/collections/ "Create new collection"
-- Expected:201 Got:403
-- Response:{"Code":403,"Payload":"","Message":""}
0:00:00.006414 OK POST http://localhost:8080/collections/ "Handle wrong password"
0:00:00.005459 OK POST http://localhost:8080/collections/ "Handle empty"
0:00:00.004964 NOK GET http://localhost:8080/collections/ "Get collections"
-- Expected:200 Got:405
-- Response:{"Code":405,"Payload":"","Message":"MethodNotAllowed"}
0:00:00.009587 NOK POST http://localhost:8080/documents/ "Crate document"
-- Expected:201 Got:500
-- Response:{"Code":500,"Payload":"","Message":""}
0:00:00.008102 NOK PUT http://localhost:8080/documents/ "Update document"
-- Expected:20 Got:405
-- Response:{"Code":405,"Payload":"","Message":"MethodNotAllowed"}