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