Debian Codegraph @

testenv/Test-https-k.py

raw
1 #!/usr/bin/env python3
2
3 import os
4 import platform
5 from sys import exit
6
7 from test.base_test import HTTPS, SKIP_TEST
8 from test.http_test import HTTPTest
9 from misc.wget_file import WgetFile
10
11 """
12 Test that Wget handles the --convert-links (-k) option correctly.
13
14 Ensure that when downloading, Wget retains the protocol of the host URL
15 if the link wasn't followed and an absolute link is to be added to the
16 local file.
17 """
18
19 if os.getenv('SSL_TESTS') is None:
20 exit(SKIP_TEST)
21
22 ############################## File Definitions ##############################
23
24 index = """
25 <html>
26 <head>
27 <title>Index</title>
28 </head>
29 <body>
30 <a href="sub.html">Site</a>
31 <a href="missing.xhtml">Missing</a>
32 <a href="//localhost:{{port}}/missing2.html">Missing2</a>
33 </body>
34 </html>
35 """
36
37 converted = """
38 <html>
39 <head>
40 <title>Index</title>
41 </head>
42 <body>
43 <a href="sub.html">Site</a>
44 <a href="https://localhost:{{port}}/missing.xhtml">Missing</a>
45 <a href="https://localhost:{{port}}/missing2.html">Missing2</a>
46 </body>
47 </html>
48 """
49
50 site = """
51 <html>
52 <head>
53 <title>Site</title>
54 </head>
55 <body>
56 Subsite
57 </body>
58 </html>
59 """
60
61 IndexPage = WgetFile("index.html", index)
62 SubSite = WgetFile("sub.html", site)
63 LocalIndexPage = WgetFile("index.html", converted)
64
65 print(platform.system())
66 restrict = "unix" if platform.system() in ["Linux", "Darwin"] else "windows"
67
68 WGET_OPTIONS = "-k -r -nH --reject-regex '.*\\.xhtml' --no-check-certificate"
69 WGET_URLS = [["index.html"]]
70
71 Files = [[IndexPage, SubSite]]
72
73 Servers = [HTTPS]
74
75 ExpectedReturnCode = 8
76 ExpectedDownloadedFiles = [LocalIndexPage, SubSite]
77
78 ########################### Pre and Post Test Hooks ##########################
79 pre_test = {
80 "ServerFiles": Files,
81 }
82 test_options = {
83 "WgetCommands": WGET_OPTIONS,
84 "Urls": WGET_URLS
85 }
86 post_test = {
87 "ExpectedFiles": ExpectedDownloadedFiles,
88 "ExpectedRetcode": ExpectedReturnCode
89 }
90
91 err = HTTPTest(
92 pre_hook=pre_test,
93 test_params=test_options,
94 post_hook=post_test,
95 protocols=Servers,
96 ).begin()
97
98 exit(err)