| 1 |
#!/usr/bin/env python3 |
| 2 |
from sys import exit |
| 3 |
from test.http_test import HTTPTest |
| 4 |
from misc.wget_file import WgetFile |
| 5 |
|
| 6 |
""" |
| 7 |
This test ensures that Wget link conversion works also on HTTP error pages. |
| 8 |
""" |
| 9 |
############# File Definitions ############################################### |
| 10 |
a_x_FileContent = """ |
| 11 |
<!DOCTYPE html> |
| 12 |
<html lang="en"> |
| 13 |
<head> |
| 14 |
<meta charset="UTF-8"> |
| 15 |
<title></title> |
| 16 |
</head> |
| 17 |
<body> |
| 18 |
<a href="/b/y.html"></a> |
| 19 |
</body> |
| 20 |
</html> |
| 21 |
""" |
| 22 |
a_x_LocalFileContent = """ |
| 23 |
<!DOCTYPE html> |
| 24 |
<html lang="en"> |
| 25 |
<head> |
| 26 |
<meta charset="UTF-8"> |
| 27 |
<title></title> |
| 28 |
</head> |
| 29 |
<body> |
| 30 |
<a href="../b/y.html"></a> |
| 31 |
</body> |
| 32 |
</html> |
| 33 |
""" |
| 34 |
|
| 35 |
error_FileContent = '404 page content' |
| 36 |
error_FileRules = { |
| 37 |
'Response': 404 , |
| 38 |
'SendHeader': { |
| 39 |
'Content-Length': len(error_FileContent), |
| 40 |
'Content-Type': 'text/plain', |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
a_x_File = WgetFile ("a/x.html", a_x_FileContent) |
| 45 |
robots_File = WgetFile ("robots.txt", '') |
| 46 |
error_File = WgetFile ("b/y.html", error_FileContent, rules=error_FileRules) |
| 47 |
|
| 48 |
B_File = WgetFile ("a/x.html", a_x_LocalFileContent) |
| 49 |
|
| 50 |
WGET_OPTIONS = "--no-host-directories -r -l2 --convert-links --content-on-error" |
| 51 |
WGET_URLS = [["a/x.html"]] |
| 52 |
|
| 53 |
Files = [[a_x_File, robots_File, error_File]] |
| 54 |
|
| 55 |
ExpectedReturnCode = 8 |
| 56 |
ExpectedDownloadedFiles = [B_File, robots_File, error_File] |
| 57 |
|
| 58 |
################ Pre and Post Test Hooks ##################################### |
| 59 |
pre_test = { |
| 60 |
"ServerFiles" : Files |
| 61 |
} |
| 62 |
test_options = { |
| 63 |
"WgetCommands" : WGET_OPTIONS, |
| 64 |
"Urls" : WGET_URLS |
| 65 |
} |
| 66 |
post_test = { |
| 67 |
"ExpectedFiles" : ExpectedDownloadedFiles, |
| 68 |
"ExpectedRetcode" : ExpectedReturnCode |
| 69 |
} |
| 70 |
|
| 71 |
err = HTTPTest ( |
| 72 |
pre_hook=pre_test, |
| 73 |
test_params=test_options, |
| 74 |
post_hook=post_test |
| 75 |
).begin () |
| 76 |
|
| 77 |
exit (err) |