1#!/usr/bin/env python3 2from sys import exit 3from test.http_test import HTTPTest 4from misc.wget_file import WgetFile 5 6""" 7 This test executed Wget in Spider mode with recursive retrieval. 8""" 9############# File Definitions ############################################### 10mainpage = """ 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 25secondpage = """ 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 39thirdpage = """ 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 53dummyfile = "Don't care." 54 55 56index_html = WgetFile ("index.html", mainpage) 57secondpage_html = WgetFile ("secondpage.html", secondpage) 58thirdpage_html = WgetFile ("thirdpage.html", thirdpage) 59dummy_txt = WgetFile ("dummy.txt", dummyfile) 60 61Request_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 76WGET_OPTIONS = "--spider -r" 77WGET_URLS = [[""]] 78 79Files = [[index_html, secondpage_html, thirdpage_html, dummy_txt]] 80 81ExpectedReturnCode = 8 82ExpectedDownloadedFiles = [] 83 84################ Pre and Post Test Hooks ##################################### 85pre_test = { 86 "ServerFiles" : Files 87} 88test_options = { 89 "WgetCommands" : WGET_OPTIONS, 90 "Urls" : WGET_URLS 91} 92post_test = { 93 "ExpectedFiles" : ExpectedDownloadedFiles, 94 "ExpectedRetcode" : ExpectedReturnCode, 95 "FilesCrawled" : Request_List 96} 97 98err = HTTPTest ( 99 pre_hook=pre_test, 100 test_params=test_options, 101 post_hook=post_test 102).begin () 103 104exit (err) 105