test_https.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import requests
  2. from pytest_localserver import https
  3. from pytest_localserver import plugin
  4. # define test fixture here again in order to run tests without having to
  5. # install the plugin anew every single time
  6. httpsserver = plugin.httpsserver
  7. def test_httpsserver_funcarg(httpsserver):
  8. assert isinstance(httpsserver, https.SecureContentServer)
  9. assert httpsserver.is_alive()
  10. assert httpsserver.server_address
  11. def test_server_does_not_serve_file_at_startup(httpsserver):
  12. assert httpsserver.code == 204
  13. assert httpsserver.content == ""
  14. def test_some_content_retrieval(httpsserver):
  15. httpsserver.serve_content("TEST!")
  16. resp = requests.get(httpsserver.url, verify=False)
  17. assert resp.text == "TEST!"
  18. assert resp.status_code == 200
  19. def test_GET_request(httpsserver):
  20. httpsserver.serve_content("TEST!", headers={"Content-type": "text/plain"})
  21. resp = requests.get(httpsserver.url, headers={"User-Agent": "Test method"}, verify=False)
  22. assert resp.text == "TEST!"
  23. assert resp.status_code == 200
  24. assert "text/plain" in resp.headers["Content-type"]
  25. def test_HEAD_request(httpsserver):
  26. httpsserver.serve_content("TEST!", headers={"Content-type": "text/plain"})
  27. print(httpsserver.url)
  28. resp = requests.head(httpsserver.url, verify=False)
  29. assert resp.status_code == 200
  30. assert resp.headers["Content-type"] == "text/plain"