Skip to main content

Merge pull request #3 from alexwlchan/check-webarchive-saved-correctly

ID
19acc20
date
2024-05-16 21:52:08+00:00
author
Alex Chan <alex@alexwlchan.net>
parents
f1e8707, b5a11a4
message
Merge pull request #3 from alexwlchan/check-webarchive-saved-correctly

Test that we get a correctly formatted webarchive file
changed files
3 files, 58 additions

Changed files

.gitattributes (0) → .gitattributes (46)

diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..e891c1d
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1 @@
+tests/fixtures/*.html linguist-generated=true

tests/fixtures/example.com.html (0) → tests/fixtures/example.com.html (1248)

diff --git a/tests/fixtures/example.com.html b/tests/fixtures/example.com.html
new file mode 100644
index 0000000..5569a47
--- /dev/null
+++ b/tests/fixtures/example.com.html
@@ -0,0 +1,45 @@
+<!DOCTYPE html><html><head>
+    <title>Example Domain</title>
+
+    <meta charset="utf-8">
+    <meta http-equiv="Content-type" content="text/html; charset=utf-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1">
+    <style type="text/css">
+    body {
+        background-color: #f0f0f2;
+        margin: 0;
+        padding: 0;
+        font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
+        
+    }
+    div {
+        width: 600px;
+        margin: 5em auto;
+        padding: 2em;
+        background-color: #fdfdff;
+        border-radius: 0.5em;
+        box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);
+    }
+    a:link, a:visited {
+        color: #38488f;
+        text-decoration: none;
+    }
+    @media (max-width: 700px) {
+        div {
+            margin: 0 auto;
+            width: auto;
+        }
+    }
+    </style>    
+</head>
+
+<body>
+<div>
+    <h1>Example Domain</h1>
+    <p>This domain is for use in illustrative examples in documents. You may use this
+    domain in literature without prior coordination or asking for permission.</p>
+    <p><a href="https://www.iana.org/domains/example">More information...</a></p>
+</div>
+
+
+</body></html>
\ No newline at end of file

tests/test_save_safari_webarchive.py (3416) → tests/test_save_safari_webarchive.py (3764)

diff --git a/tests/test_save_safari_webarchive.py b/tests/test_save_safari_webarchive.py
index c472a18..4e0a8fe 100755
--- a/tests/test_save_safari_webarchive.py
+++ b/tests/test_save_safari_webarchive.py
@@ -2,6 +2,7 @@
 
 import os
 import pathlib
+import plistlib
 
 import pytest
 
@@ -26,6 +27,17 @@ def test_creates_a_single_archive(out_path: pathlib.Path) -> None:
     assert result["stderr"] is None
     assert out_path.exists()
 
+    with open(out_path, "rb") as in_file:
+        webarchive = plistlib.load(in_file)
+
+    main_resource = webarchive["WebMainResource"]
+
+    assert main_resource["WebResourceURL"] == "https://example.com/"
+    assert (
+        main_resource["WebResourceData"]
+        == open("tests/fixtures/example.com.html", "rb").read()
+    )
+
 
 def test_does_not_overwrite_existing_archive(out_path: pathlib.Path) -> None:
     out_path.write_text("This should still be here later")