Skip to main content

Merge pull request #10 from alexwlchan/run-tests-off-flask

ID
2a1c04d
date
2024-05-20 21:42:30+00:00
author
Alex Chan <alex@alexwlchan.net>
parents
ef7350a, 126840b
message
Merge pull request #10 from alexwlchan/run-tests-off-flask

Don't rely on httpstat.us for the tests
changed files
4 files, 27 additions, 13 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/conftest.py (0) → tests/conftest.py (294)

diff --git a/tests/conftest.py b/tests/conftest.py
new file mode 100644
index 0000000..489122c
--- /dev/null
+++ b/tests/conftest.py
@@ -0,0 +1,13 @@
+import pathlib
+
+import pytest
+
+
+@pytest.fixture
+def out_path(tmp_path: pathlib.Path) -> None:
+    """
+    Returns a temporary path where we can write a webarchive.
+
+    Any files written to this path will be cleaned up at the end of the test.
+    """
+    return tmp_path / "example.webarchive"

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

diff --git a/tests/test_save_safari_webarchive.py b/tests/test_save_safari_webarchive.py
index 03e9e94..db08d35 100755
--- a/tests/test_save_safari_webarchive.py
+++ b/tests/test_save_safari_webarchive.py
@@ -6,20 +6,11 @@ import plistlib
 import re
 
 import pytest
+from pytest_httpserver import HTTPServer
 
 from utils import save_safari_webarchive
 
 
-@pytest.fixture
-def out_path(tmp_path: pathlib.Path) -> None:
-    """
-    Returns a temporary path where we can write a webarchive.
-
-    Any files written to this path will be cleaned up at the end of the test.
-    """
-    return tmp_path / "example.webarchive"
-
-
 def test_creates_a_single_archive(out_path: pathlib.Path) -> None:
     result = save_safari_webarchive(["https://example.com", out_path])
 
@@ -82,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])