{"id":25444403,"url":"https://github.com/theelous3/overly","last_synced_at":"2025-11-01T18:30:33.768Z","repository":{"id":57449963,"uuid":"148950567","full_name":"theelous3/overly","owner":"theelous3","description":"An overly configurable http server for client testing.","archived":false,"fork":false,"pushed_at":"2020-05-28T16:27:50.000Z","size":75,"stargazers_count":6,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-13T03:35:59.886Z","etag":null,"topics":["client","configurable","decorators","end-to-end-testing","http","https","local","pytest","python3","server","tests","unit-test"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/theelous3.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-16T00:29:35.000Z","updated_at":"2022-11-27T10:02:38.000Z","dependencies_parsed_at":"2022-09-01T19:12:48.177Z","dependency_job_id":null,"html_url":"https://github.com/theelous3/overly","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theelous3%2Foverly","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theelous3%2Foverly/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theelous3%2Foverly/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theelous3%2Foverly/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/theelous3","download_url":"https://codeload.github.com/theelous3/overly/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238837902,"owners_count":19539080,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["client","configurable","decorators","end-to-end-testing","http","https","local","pytest","python3","server","tests","unit-test"],"created_at":"2025-02-17T15:30:33.692Z","updated_at":"2025-11-01T18:30:33.721Z","avatar_url":"https://github.com/theelous3.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Overly - the most overly configurable test http/s server this side of the moon.\n\n### Huh?\n\nIf you've ever found yourself wanting a test http/s server that you can do the weirdest imaginable things with, overly is for you.\n\nLet's start simple. Say we want to emulate the well known ``/get`` endpoint at httpbin.org, and stick it on a unit/pytest.\nWe use ``overly.Server`` as a decorator, passing it a series of steps to do when it gets a request. The decorator injects the server object in to the test, kinda like a fixture.\n\n```python\nimport requests\nfrom overly import Server, delay, send_request_as_json, finish\n\n@Server((\"localhost\", 25001), steps=[delay(2), send_request_as_json, finish])\ndef test_json_send(server):\n    r = requests.post(\n        server.http_test_url, json={\"key_1\": True, \"key_2\": \"cheesestring\"}\n    )\n    pprint(r.json())\n\n# The response is:\n#\n# 'body': '{\"key_1\": true, \"key_2\": \"cheesestring\"}',\n# 'files': [],\n# 'forms': [],\n# 'headers': [\n#     ['host', 'localhost:25001'],\n#     ['user-agent', 'python-requests/2.19.1'],\n#     ['accept-encoding', 'gzip, deflate'],\n#     ['accept', '*/*'],\n#     ['connection', 'keep-alive'],\n#     ['content-length', '40'],\n#     ['content-type', 'application/json']],\n# 'http_version': '1.1',\n# 'json': [\n#     {\n#         'json': {'key_1': True, 'key_2': 'cheesestring'}\n#     }\n# ],\n# 'method': 'POST',\n# 'path': '/',\n# 'target': '/'}\n```\n\nSimples! Now Let's Get Weird.\n\nWant to see if your client will handle a redirect from ``https://example.com``, to ``https://example.com/doowap``, that returns a 404 page that's eight gigabytes, but the server only starts sending data 43 seconds later and kills the socket before finishing, just for kicks? We'll enforce the request order too so we don't accidentally write our tests to miss the redirection case, and skip the first redirect. Alrighty then:\n\n```python\nfrom functools import partial\n\nfrom overly import (\n    Server,\n    ssl_socket_wrapper,\n    HttpMethods,\n    send_303,\n    send_404,\n    delay,\n    just_kill\n)\n\ntest_loc = (\"localhost\", 25001)\n\neight_gigs = 1 * (1024 ** 3) * 8)\n\nServer(\n    test_loc,\n    max_requests=2,\n    ordered_steps=True,\n    ssl_socket_wrapper=ssl_socket_wrapper,\n    steps=[\n        [\n            (HttpMethods.GET, \"/\"),\n            partial(send_303, headers=(\"location\", \"/doowap\")),\n            finish\n        ],\n        [\n            (HttpMethods.GET, \"/doowap\"),\n            delay(43),\n            partial(send_404, data=b\"x\" * eight_gigs,\n            just_kill\n        ]\n    ]\n).run()\n```\n\n\nBam. The worst 404 page of all time. The above can be used as a decorator, just like before. We can also just run the server with ``Server.run()`` for easy messing about.\n\nAs was mentioned, and as you can see, overly is overly configurabe :D All of your bases are covered!\n\nThe ``Server`` is concurrent, so you can test all of your weird async / threaded / voodoo clients, with keep-alive support.\n\n### Can you explain wtf I just looked at?\n\nSure!\n\nI'll break down the first example in detail.\n\nThe ``Server`` object can be used to wrap a function as a decorator. When the wrapped function is called, before it is run, overly starts the server in a thread, waits until the server declares it's listening socket is ready to go, and then runs whatever callable was passed to it. This also works with async calls, by passing a wrapper around your async func that invokes it correctly. [An example of that is here.](https://github.com/theelous3/asks/blob/master/tests/test_anyio.py#L49)\n\nThe ``Server`` threads off new clients as they connect, pairing them with a ``ClientHandler`` instance. It's through the client handler that we communicate with the connected client, and fetch data about the request.\n\n``Server`` takes what I call \"steps\" as arguments. A step is any callable at all. [There are many built in steps](https://github.com/theelous3/overly/blob/master/overly/steps.py), and it's very straight forward to write a new one. Steps are invoked by the client handler. The client handler will pass its self to any step it invokes, and so all steps must accept at least one argument (the client handler.)\n\nThe first step we use is `delay`. `delay` is a simple function that just ``time.sleep``s for `t` seconds.\n\nSecondly, we have ``send_request_as_json``. It a much more complex function, but given all it does it's still simple in theory. It takes a reference to the client handler as an argument, as described above. It accesses the underlying h11 request metadata object through ``client_hanlder.request``, and the request body through ``client_handler.request_body``.\n\nIt constructs a ``dict`` appropriate for jsoning as a response, and uses ``client_handler.http_send`` to send back ``h11.Response`` and ``h11.Data`` objects.\n\nIf you're unfamiliar with [h11](https://github.com/python-hyper/h11) that's about all you need to know, but you can read some more through the link there.\n\nFinally we use ``finish`` to cleanly end the connection and inform both the client and our underlying ``h11.connection`` object we are finished with the request.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheelous3%2Foverly","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftheelous3%2Foverly","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheelous3%2Foverly/lists"}