test_https.py 1.4 KB

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