Placebo is a tool for mocking external API's in python applications.
Project description
Placebo is a utility that help mock api endpoints in a reusable and composable way.
To use placebo first we should create a placebo class for our mock. Placebo class represents a response for certain request. If url and http method of any request matches with mock, response that is described in placebo class will be return. We can create a placebo mock like this:
from placebo import Placebo class UsersResponse(Placebo): url = 'http://www.acme.com/api/v1/users/' body = json.dumps([{'name': 'Huseyin', 'last_name': 'Yilmaz'}])
Main interface for a placebo object is a decorator. Any function that decorated with a placebo class will be mocked with that placebo class.
@UserResponse.decorate def users_api_test(self): ...
You can decorate any function or method with this decorator. Even django views! This makes development against external apis very easy.
@UserResponse.decorate def users_list_view(request): ...
If your code is using multiple api endpoints you can easily stack placebo decorators on top of each other.
@AuthResponse.decorate @UserResponse.decorate def test_valid_get_user(request): ... @AuthResponse.decorate(status=401) @UserResponse.decorate def test_cannot_authenticate(request): ... @AuthResponse.decorate @UserResponse.decorate(status=503) def test_api_is_not_available(request): ...
For more information, please refer to documentation
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 python-placebo-1.0.1.tar.gz
.
File metadata
- Download URL: python-placebo-1.0.1.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 271b3692fea5a45c918c9c4fa26fb90bbe921788336dd211b9506fdeda924e2a |
|
MD5 | 264f0df1248fd63884d7d0767edf9b5e |
|
BLAKE2b-256 | e9977ef9683099972fc33c6ecf85fccb9f14dfc0891a27fa68a679d8a8b1a491 |