Skip to main content

Don’t rely on httpstat.us for the tests

ID
126840b
date
2024-05-20 21:40:05+00:00
author
Alex Chan <alex@alexwlchan.net>
parent
f599151
message
Don't rely on httpstat.us for the tests

The service seems to have broken in the last few days, and now my tests
are failing -- better to run a local server in tests, which I can rely
on.
changed files
3 files, 14 additions, 3 deletions

Changed files

dev_requirements.in (20) → dev_requirements.in (38)

diff --git a/dev_requirements.in b/dev_requirements.in
index 9cda381..3369167 100644
--- a/dev_requirements.in
+++ b/dev_requirements.in
@@ -1,2 +1,3 @@
 pytest
+pytest-httpserver
 pytest-xdist

dev_requirements.txt (397) → dev_requirements.txt (537)

diff --git a/dev_requirements.txt b/dev_requirements.txt
index 8d6f16c..606375b 100644
--- a/dev_requirements.txt
+++ b/dev_requirements.txt
@@ -1,5 +1,5 @@
 #
-# This file is autogenerated by pip-compile with Python 3.11
+# This file is autogenerated by pip-compile with Python 3.12
 # by the following command:
 #
 #    pip-compile dev_requirements.in
@@ -8,6 +8,8 @@ execnet==2.1.1
     # via pytest-xdist
 iniconfig==2.0.0
     # via pytest
+markupsafe==2.1.5
+    # via werkzeug
 packaging==24.0
     # via pytest
 pluggy==1.5.0
@@ -16,5 +18,9 @@ pytest==8.2.0
     # via
     #   -r dev_requirements.in
     #   pytest-xdist
+pytest-httpserver==1.0.10
+    # via -r dev_requirements.in
 pytest-xdist==3.6.1
     # via -r dev_requirements.in
+werkzeug==3.0.3
+    # via pytest-httpserver

tests/test_save_safari_webarchive.py (3780) → tests/test_save_safari_webarchive.py (3985)

diff --git a/tests/test_save_safari_webarchive.py b/tests/test_save_safari_webarchive.py
index aaaf34f..db08d35 100755
--- a/tests/test_save_safari_webarchive.py
+++ b/tests/test_save_safari_webarchive.py
@@ -6,6 +6,7 @@ import plistlib
 import re
 
 import pytest
+from pytest_httpserver import HTTPServer
 
 from utils import save_safari_webarchive
 
@@ -72,9 +73,12 @@ def test_it_fails_if_you_supply_the_wrong_arguments(argv: list[str]) -> None:
 
 @pytest.mark.parametrize("status_code", ["403", "404", "410", "500"])
 def test_it_fails_if_non_200_status_code(
-    status_code: str, out_path: pathlib.Path
+    httpserver: HTTPServer, status_code: str, out_path: pathlib.Path
 ) -> None:
-    url = f"https://httpstat.us/{status_code}"
+    httpserver.expect_request("/error").respond_with_data(
+        "Boom!", status=int(status_code), content_type="text/plain"
+    )
+    url = f"http://localhost:{httpserver.port}/error"
 
     result = save_safari_webarchive([url, out_path])