bddrest icon indicating copy to clipboard operation
bddrest copied to clipboard

Provide a mockup server

Open pylover opened this issue 7 years ago • 4 comments

Please provide a mockup server to serve the generate yaml files as HTTP REST api.

For example:


bddrest mockup --bind [9.9.9.9:]8090 --base-url apiv1 myfile.yml yourfile.yml *.yml

pylover avatar Jun 19 '18 10:06 pylover

According to the discussion with Vahid and the rest of the back-end team, it is been decided to go through this task with this sequential parts:

  1. Test: Write bunch of tests that will satisfy our needs from our mockup server
  2. Wsgi server and wsgi application: For satisfy our tests we should have a wsgi server and application
  3. Controllers: Rest controllers with regex dispaching
  4. Cli: Argument parser for bring this feature into bash cli

mehrdad1373pedramfar avatar Jun 25 '18 05:06 mehrdad1373pedramfar

This http-server in restfulpy.testing.mockup.http.py is going to be so useful:

@contextlib.contextmanager
def http_server(app=None, handler_class=WSGIRequestHandler, server_class=WSGIServer, bind=('', 0)):
    server = server_class(bind, handler_class)
    if app:
        assert isinstance(server, WSGIServer)
        server.set_app(app)
    thread = threading.Thread(target=server.serve_forever, name='sa-media test server.', daemon=True)
    thread.start()
    url = 'http://localhost:%s' % server.server_address[1]
    yield server, url
    server.shutdown()
    thread.join()

mehrdad1373pedramfar avatar Jun 25 '18 05:06 mehrdad1373pedramfar

But there is a few things that should be mentioned here:

  • we need to bind our mockup-server to given port(not random), it means that if user didn't set a port we should have default port

mehrdad1373pedramfar avatar Jun 25 '18 05:06 mehrdad1373pedramfar

Nice, Thanks.

pylover avatar Jun 26 '18 17:06 pylover