Skip to main content

Python REST Service Test utility

Project description

This software is the sole property of Prime Solutions Group, Inc.

Project Title:

REST Harness Python Client

REST Harness is a tool to stand in the place of another REST service. This can be used to Mock out a service that doesn't exist yet, or where we need to reproduce a particular set of inputs from an opaque service. It can also serve as a simple shared cache. This library contains a client that can be used to interact with the REST Harness web server.

Getting Started:

Requirements/Built with:
Python3
requests

Import

Usage: from rhclient import client
client.configUrl("base url") (before configuration, base url is http://localhost:5000)

Methods

(Subject to change)

create_path(self, path, rc, return_value, delay=0)


Parameters:

self : default parameter
path : required, specifies the path of the endpoint you would like to create
rc : required, specifies the return code you would like to receive upon hitting the created endpoint
return_value : required, specifies the value you would like to return from the created endpoint
delay : optional, can be used to force an endpoint to wait for a specified amount of time before returning its contents.(useful for mimicking a bad connection)

Description

Creates an endpoint on a REST Harness web server given parameters as information

Examples:

client.create_path("/test", 200, "test data")
Creates an endpoint at /test that returns "test data" upon access.
client.create_path("/test", 203, {"prop1" : "value1", "prop2" : "value2"}, 3)
Creates an endpoint at /test that returns the provided JSON data after a 3 second delay upon access.

create_paths(self, path)


Parameters:

self : default parameter
path : required, contains all data of each path you would like to create in a JSON object, list, or other compatible data structure

Description:

Creates multiple endpoints given a list of endpoints and their parameters

Examples:

client.create_paths({"/path1" : {"delay" : 0, "rc" : 200, "return_value" : "test test"}, "/path2" : {"delay" : 0, "rc" : 204, "return_value" : "test test"}, "/path3" : {"delay" : 2, "rc" : 200, "return_value" : "returned something"}, "/path4" : {"delay" : 1, "rc" : 202, "return_value" : "test something"},})
Creates 4 endpoints: /path1, /path2, /path3, and /path4 which return their corresponding return codes and return values after a given delay.

get_path(self, path)


Parameters:

self : default parameter
path : required, specifies the path of the endpoint you would like to get data from

Description:

Hits an endpoint and returns the information associated with it.

Examples:

client.create_path("/test", 200, "test data")
...(some code)
client.get_path("/test")
Creates an endpoint at /test, then hits the endpoint and returns "test data" upon access.

client.create_path("/test", 203, {"prop1" : "value1", "prop2" : "value2"}, 3)
...(some code)
client.get_path("/test")
Creates an endpoint at /test, then hits the endpoint and returns the JSON return value after a 3 second delay.

get_all(self)


Parameters

self : default parameter

Description:

Gets all information from all created paths and returns it in a JSON format.

Examples:

client.create_path("/test", 200, "test data")
client.create_path("/test2", 203, {"prop1" : "value1", "prop2" : "value2"}, 3)
...(some code)
client.get_path("/test")
Creates an endpoint at /test and /test2, then gets all information associated with both endpoints(no programmable delay) as a JSON object.

update_path(self, path, rc, return_value, delay=0)


Parameters:

self : default parameter
path : required, specifies the path of the endpoint you would like to update
rc : required, specifies the return code you would like to receive upon hitting the updated endpoint
return_value : required, specifies the value you would like to return from the updated endpoint
delay : optional, can be used to force an endpoint to wait for a specified amount of time before returning its contents.(useful for mimicking a bad connection)

Description

Updates an endpoint on a REST Harness web server given parameters as information

Examples:

client.create_path("/test", 200, "test data")
client.update_path("/test", 203, {"prop1" : "value1", "prop2" : "value2"}, 3)
Creates an endpoint at /test, then updates its return value and return code so that it returns different values when hit

delete_path(self, path)


Parameters:

self : default parameter
path : required, specifies the path of the endpoint you would like to delete

Description

Deletes an endpoint on a REST Harness web server given a path as a parameter

Examples:

client.create_path("/test", 200, "test data")
...(some code)
client.delete_path("/test")
Deletes the /test endpoint from the REST Harness server.

Notes:

To be determined at a later date.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rhclient-0.1.3.tar.gz (6.9 kB view hashes)

Uploaded Source

Built Distribution

rhclient-0.1.3-py3-none-any.whl (4.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page