| 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 executed Wget in Spider mode with recursive retrieval. |
| 8 |
""" |
| 9 |
############# File Definitions ############################################### |
| 10 |
mainpage = """ |
| 11 |
<html> |
| 12 |
<head> |
| 13 |
<title>Main Page</title> |
| 14 |
</head> |
| 15 |
<body> |
| 16 |
<p> |
| 17 |
Some text and a link to a <a href="http://localhost:{{port}}/secondpage.html">second page</a>. |
| 18 |
Also, a <a href="http://localhost:{{port}}/nonexistent">broken link</a>. |
| 19 |
</p> |
| 20 |
</body> |
| 21 |
</html> |
| 22 |
""" |
| 23 |
|
| 24 |
|
| 25 |
secondpage = """ |
| 26 |
<html> |
| 27 |
<head> |
| 28 |
<title>Second Page</title> |
| 29 |
</head> |
| 30 |
<body> |
| 31 |
<p> |
| 32 |
Some text and a link to a <a href="http://localhost:{{port}}/thirdpage.html">third page</a>. |
| 33 |
Also, a <a href="http://localhost:{{port}}/nonexistent">broken link</a>. |
| 34 |
</p> |
| 35 |
</body> |
| 36 |
</html> |
| 37 |
""" |
| 38 |
|
| 39 |
thirdpage = """ |
| 40 |
<html> |
| 41 |
<head> |
| 42 |
<title>Third Page</title> |
| 43 |
</head> |
| 44 |
<body> |
| 45 |
<p> |
| 46 |
Some text and a link to a <a href="http://localhost:{{port}}/dummy.txt">text file</a>. |
| 47 |
Also, another <a href="http://localhost:{{port}}/againnonexistent">broken link</a>. |
| 48 |
</p> |
| 49 |
</body> |
| 50 |
</html> |
| 51 |
""" |
| 52 |
|
| 53 |
dummyfile = "Don't care." |
| 54 |
|
| 55 |
|
| 56 |
index_html = WgetFile ("index.html", mainpage) |
| 57 |
secondpage_html = WgetFile ("secondpage.html", secondpage) |
| 58 |
thirdpage_html = WgetFile ("thirdpage.html", thirdpage) |
| 59 |
dummy_txt = WgetFile ("dummy.txt", dummyfile) |
| 60 |
|
| 61 |
Request_List = [ |
| 62 |
[ |
| 63 |
"HEAD /", |
| 64 |
"GET /", |
| 65 |
"GET /robots.txt", |
| 66 |
"HEAD /secondpage.html", |
| 67 |
"GET /secondpage.html", |
| 68 |
"HEAD /nonexistent", |
| 69 |
"HEAD /thirdpage.html", |
| 70 |
"GET /thirdpage.html", |
| 71 |
"HEAD /dummy.txt", |
| 72 |
"HEAD /againnonexistent" |
| 73 |
] |
| 74 |
] |
| 75 |
|
| 76 |
WGET_OPTIONS = "--spider -r" |
| 77 |
WGET_URLS = [[""]] |
| 78 |
|
| 79 |
Files = [[index_html, secondpage_html, thirdpage_html, dummy_txt]] |
| 80 |
|
| 81 |
ExpectedReturnCode = 8 |
| 82 |
ExpectedDownloadedFiles = [] |
| 83 |
|
| 84 |
################ Pre and Post Test Hooks ##################################### |
| 85 |
pre_test = { |
| 86 |
"ServerFiles" : Files |
| 87 |
} |
| 88 |
test_options = { |
| 89 |
"WgetCommands" : WGET_OPTIONS, |
| 90 |
"Urls" : WGET_URLS |
| 91 |
} |
| 92 |
post_test = { |
| 93 |
"ExpectedFiles" : ExpectedDownloadedFiles, |
| 94 |
"ExpectedRetcode" : ExpectedReturnCode, |
| 95 |
"FilesCrawled" : Request_List |
| 96 |
} |
| 97 |
|
| 98 |
err = HTTPTest ( |
| 99 |
pre_hook=pre_test, |
| 100 |
test_params=test_options, |
| 101 |
post_hook=post_test |
| 102 |
).begin () |
| 103 |
|
| 104 |
exit (err) |