Code Monkey home page Code Monkey logo

bogus-test-server's Introduction

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

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:

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.:

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.

bogus-test-server's People

Contributors

flavianmissi avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

flavianmissi

bogus-test-server's Issues

Copyright holder and license

Hi,
Could you please add LICENSE file and put the copyright holder and license inside each file? This way there is no chance of someone stumbling across a piece of code without being exposed to the license.

give more information on a request at a url

Now the user can only access the paths that bogus responded to. We should find a way to pass more information to the user, like the method used on the requests, what parameters were passed, and any more things we can think it's useful.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.