Debian Codegraph @

testenv/Test-504.py

raw
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 handles a 504 Gateway Timeout response
8 correctly.
9 Since, we do not have a direct mechanism for conditionally sending responses
10 via the HTTP Server, I've used a workaround.
11 The server will always respond to a request for File1 with a 504 Gateway
12 Timeout. Using the --tries=2 option, we ensure that Wget attempts the file
13 only twice and then move on to the next file. Finally, check the exact
14 requests that the Server received and compare them, in order, to the
15 expected sequence of requests.
16
17 In this case, we expect Wget to attempt File1 twice and File2 once. If Wget
18 considered 504 as a general Server Error, it would be a fatal failure and
19 Wget would request File1 only once.
20 """
21 ############# File Definitions ###############################################
22 File1 = """All happy families are alike;
23 Each unhappy family is unhappy in its own way"""
24 File2 = "Anyone for chocochip cookies?"
25
26 File1_rules = {
27 "Response" : 504
28 }
29
30 A_File = WgetFile ("File1", File1, rules=File1_rules)
31 B_File = WgetFile ("File2", File2)
32
33 Request_List = [
34 [
35 "GET /File1",
36 "GET /File1",
37 "GET /File2",
38 ]
39 ]
40
41
42 WGET_OPTIONS = "--tries=2"
43 WGET_URLS = [["File1", "File2"]]
44
45 Files = [[A_File, B_File]]
46
47 ExpectedReturnCode = 4
48 ExpectedDownloadedFiles = [B_File]
49
50 ################ Pre and Post Test Hooks #####################################
51 pre_test = {
52 "ServerFiles" : Files
53 }
54 test_options = {
55 "WgetCommands" : WGET_OPTIONS,
56 "Urls" : WGET_URLS
57 }
58 post_test = {
59 "ExpectedFiles" : ExpectedDownloadedFiles,
60 "ExpectedRetcode" : ExpectedReturnCode,
61 "FilesCrawled" : Request_List
62 }
63
64 err = HTTPTest (
65 pre_hook=pre_test,
66 test_params=test_options,
67 post_hook=post_test
68 ).begin ()
69
70 exit (err)