|
| 1 | +"""tests/test_full_request.py. |
| 2 | +
|
| 3 | +Test cases that rely on a command being ran against a running hug server |
| 4 | +
|
| 5 | +Copyright (C) 2016 Timothy Edmund Crosley |
| 6 | +
|
| 7 | +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated |
| 8 | +documentation files (the "Software"), to deal in the Software without restriction, including without limitation |
| 9 | +the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and |
| 10 | +to permit persons to whom the Software is furnished to do so, subject to the following conditions: |
| 11 | +
|
| 12 | +The above copyright notice and this permission notice shall be included in all copies or |
| 13 | +substantial portions of the Software. |
| 14 | +
|
| 15 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED |
| 16 | +TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 | +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
| 18 | +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 19 | +OTHER DEALINGS IN THE SOFTWARE. |
| 20 | +
|
| 21 | +""" |
| 22 | +import platform |
| 23 | +import time |
| 24 | +from subprocess import Popen |
| 25 | + |
| 26 | +import pytest |
| 27 | +import requests |
| 28 | + |
| 29 | +import hug |
| 30 | + |
| 31 | +TEST_HUG_API = """ |
| 32 | +import hug |
| 33 | +
|
| 34 | +
|
| 35 | +@hug.post("/test", output=hug.output_format.json) |
| 36 | +def post(body, response): |
| 37 | + print(body) |
| 38 | + return {'message': 'ok'} |
| 39 | +""" |
| 40 | + |
| 41 | + |
| 42 | +@pytest.mark.skipif(platform.python_implementation() == "PyPy", reason="Can't run hug CLI from travis PyPy") |
| 43 | +def test_hug_post(tmp_path): |
| 44 | + hug_test_file = (tmp_path / "hug_postable.py") |
| 45 | + hug_test_file.write_text(TEST_HUG_API) |
| 46 | + hug_server = Popen(['hug', '-f', str(hug_test_file), '-p', '3000']) |
| 47 | + time.sleep(5) |
| 48 | + requests.post('http://127.0.0.1:3000/test', {'data': 'here'}) |
| 49 | + hug_server.kill() |
0 commit comments