Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/globocom/bogus-test-server
A simple python bogus server to use in tests
https://github.com/globocom/bogus-test-server
Last synced: 3 months ago
JSON representation
A simple python bogus server to use in tests
- Host: GitHub
- URL: https://github.com/globocom/bogus-test-server
- Owner: globocom
- Archived: true
- Created: 2014-10-22T18:27:52.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2017-09-14T07:15:15.000Z (about 7 years ago)
- Last Synced: 2024-04-24T13:16:25.464Z (6 months ago)
- Language: Python
- Size: 199 KB
- Stars: 2
- Watchers: 13
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- starred-awesome - bogus-test-server - A simple python bogus server to use in tests (Python)
README
Bogus Test Server
=================This server is aimed for test only.
If your code talks with any REST api this is your project, you can fake any responses
the way you like, but by default it will return 200 to any url you request.Mocking any HTTP request
------------------------```python
b = Bogus() # creates a bogus instance but doesn't starts the server.
b.register("/index.html", lambda: ("your response body", 201)) # the handler registered must return both parameters.
url = b.serve() # this returns the server's url, but it also is accessible in the bogus object `url` property.
```With this done you'll have a server that receives any requests returning 200,
but when someone asks specifically for `/index.html` it'll return your response and status code
as defined in your function.You can also pass parameters to a request and receive them in your handler:
```python
b = Bogus()
b.register("/search", lambda x: ("Your search for {} didn't find anything".format(x), 200))
b.register("/foo/new", lambda: ("created", 201), headers={"Location": "http://localhost:8888/foo/1"})
b.serve()
```This will do the same as before, but if you don't pass a parameter to the `/search` endpoint
Bogus will give a 400 Bad Request response.If you want to serve only a set of endpoints in your server just pass the `promiscuous=False`
flag to the constructor, e.g.:```python
b = Bogus(promiscuous=False)
b.serve()
```This is just an example, if you do that Bogus server will respond 404 for every request,
since there's no handler registered to deal with anything.
As you may guessed this flag is True by default.