Debian Codegraph @

testenv/Test-k.py

raw
1 #!/usr/bin/env python3
2
3 import platform
4 from sys import exit
5 from test.http_test import HTTPTest
6
7 from misc.wget_file import WgetFile
8
9 """
10 Test that Wget handles the --convert-links (-k) option correctly.
11
12 Also tests that the --restrict-file-names option works as expected by using a
13 filename with restricted characters and ensuring that it uses the correct
14 characterset based on the current OS
15 """
16
17 ############################## File Definitions ##############################
18 index = """
19 <html>
20 <head>
21 <title>Index</title>
22 </head>
23 <body>
24 <a href="site;sub:.html">Site</a>
25 </body>
26 </html>
27 """
28
29 converted = """
30 <html>
31 <head>
32 <title>Index</title>
33 </head>
34 <body>
35 <a href="./site%3Bsub:.html">Site</a>
36 </body>
37 </html>
38 """
39
40 site = """
41 <html>
42 <head>
43 <title>Site</title>
44 </head>
45 <body>
46 Subsite
47 </body>
48 </html>
49 """
50
51 IndexPage = WgetFile("index.html", index)
52 SubSite = WgetFile("site;sub:.html", site)
53 LocalIndexPage = WgetFile("index.html", converted)
54
55 print(platform.system())
56 restrict = "unix" if platform.system() in ["Linux", "Darwin"] else "windows"
57
58 WGET_OPTIONS = f"-k -r -nH --restrict-file-names={restrict}"
59 WGET_URLS = [["index.html"]]
60
61 Files = [[IndexPage, SubSite]]
62
63 ExpectedReturnCode = 0
64 ExpectedDownloadedFiles = [LocalIndexPage, SubSite]
65
66 ########################### Pre and Post Test Hooks ##########################
67 pre_test = {
68 "ServerFiles": Files,
69 }
70 test_options = {
71 "WgetCommands": WGET_OPTIONS,
72 "Urls": WGET_URLS
73 }
74 post_test = {
75 "ExpectedFiles": ExpectedDownloadedFiles,
76 "ExpectedRetcode": ExpectedReturnCode
77 }
78
79 err = HTTPTest(
80 pre_hook=pre_test,
81 test_params=test_options,
82 post_hook=post_test,
83 ).begin()
84
85 exit(err)