RESTful API Testing Suite
Project description
Testing framework for RESTful APIs such as the OpenStack/Rackspace APIs
Overview
Stack-In-A-Box is a RESTful API Testing Framework for unit testing applications against the other services with support for OpenStack/Rackspace APIs.
Installing
Installation is simple:
pip install stackinabox
Goals
Enable Python modules to be unit tested against externals services and the OpenStack/Rackspace services (f.e Keystone) in particular in an environment entirely controlled by the unittest.
The service should be started/stopped and configured from the setup/teardown methods of the unittest
Support both Postive and Negative testing
Testing should be easy to do: - you shouldn’t need to know the ins and outs of each service - you should be able to register what you need (f.e keystone, swift) and have it just work
should be useable on systems like Travis (https://travis-ci.org/)
should be light on requirements - we don’t want to bloat your testing to fit our needs - if we have many requirements they could interfere with your requirements:w
The code being unit-tested should not be able to tell the difference of whether it is working with Stack-In-A-Box or the real thing - the should be nothing special about setting up the test - if you don’t turn on Stack-In-A-Box then the code should be able to call the real thing
Why not use framework X?
I considered a couple frameworks and tools, but they didn’t quite meet the goal.
For instance, mimic (https://github.com/rackerlabs/mimic) is a great tool for testing multiple things. However, you have to start/stop it separately from your tests. On the other hand, pretenders (https://github.com/pretenders) has a nice framework too, but it doesn’t actually use sockets.
What’s Provided?
It’s a work in progress. Here’s the list of current targets in-order:
Keystone v2
Keystone v3
Swift
Thus far Keystone v2 provides end-points for:
Listing tenants
Listing users
It also has support in the backend for:
tenant (add/remove/enable/disable)
users (add/remove/enable/disable, apikey, password)
tokens (add/remove, revoke, validate, admin tokens)
roles (add, assign)
Working with Frameworks
Stack-In-A-Box does not itself provide a socket interception framework. Out-of-the-box it supports two frameworks:
HTTPretty (https://github.com/gabrielfalcao/HTTPretty)
Responses (https://github.com/dropbox/responses)
You can use either one, and you must pull them in via your own test requirements.
Both of these are extremely easy to use as shown in the following examples:
HTTPretty
import unittest
import httpretty
import requests
import stackinabox.httpretty
from stackinabox.stack import StackInABox
from stackinabox.services.hello import HelloService
@httpretty.activate
class TestHttpretty(unittest.TestCase):
def setUp(self):
super(TestHttpretty, self).setUp()
StackInABox.register_service(HelloService())
def tearDown(self):
super(TestHttpretty, self).tearDown()
StackInABox.reset_services()
def test_basic(self):
stackinabox.httpretty.httpretty_registration('localhost')
res = requests.get('http://localhost/')
self.assertEqual(res.status_code, 200)
self.assertEqual(res.text, 'Hello')
assert False
Responses
import unittest
import responses
import requests
import stackinabox.responses
from stackinabox.stack import StackInABox
from stackinabox.services.hello import HelloService
@responses.activate
def test_basic_responses():
StackInABox.reset_services()
StackInABox.register_service(HelloService())
stackinabox.responses.responses_registration('localhost')
res = requests.get('http://localhost/hello/')
assert res.status_code == 200
assert res.text == 'Hello'
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file stackinabox-0.2.tar.gz
.
File metadata
- Download URL: stackinabox-0.2.tar.gz
- Upload date:
- Size: 10.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5bcba222b875a95aea90c560435898bf9650fd0f90374636372a3d661dc8f21e |
|
MD5 | 02fc5ffb562f2c75a468cb3b57501187 |
|
BLAKE2b-256 | 45b66bd2b35fc8112904fb1d8bb43af5c3c3573cf2f6aa82c6f6edf687b549cc |