From 58081549e6fa3e12182ddefe5b95383dadf4fa2c Mon Sep 17 00:00:00 2001 From: Hubert Tarasiuk Date: Thu, 7 May 2015 18:45:10 +0200 Subject: [PATCH 3/6] Add test for condget requests. * testenv/Test-condget.py: the test * testenv/Makefile.am: add to tests list --- testenv/Makefile.am | 3 +- testenv/Test-condget.py | 84 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 1 deletion(-) create mode 100755 testenv/Test-condget.py diff --git a/testenv/Makefile.am b/testenv/Makefile.am index 9acf0f3..1058421 100644 --- a/testenv/Makefile.am +++ b/testenv/Makefile.am @@ -54,7 +54,8 @@ if HAVE_PYTHON3 Test-504.py \ Test--spider-r.py \ Test-redirect-crash.py \ - Test-reserved-chars.py + Test-reserved-chars.py \ + Test-condget.py # added test cases expected to fail here and under TESTS XFAIL_TESTS = diff --git a/testenv/Test-condget.py b/testenv/Test-condget.py new file mode 100755 index 0000000..3670c4d --- /dev/null +++ b/testenv/Test-condget.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python3 +from sys import exit +from test.http_test import HTTPTest +from misc.wget_file import WgetFile + +""" + Simple test for HTTP Conditional-GET Requests usiong the --condget command +""" +TEST_NAME = "HTTP Conditional-GET Requests" +############# File Definitions ############################################### +# Keep same length ! +Cont1 = """THIS IS 1 FILE""" +Cont2 = """THIS IS 2 FILE""" +Cont3 = """THIS IS 3 FILE""" +Cont4 = """THIS IS 4 FILE""" + +# Local Wget files +UpToDate_Local_File = WgetFile ("UpToDateFile", Cont1, timestamp="1995-01-01 00:00:00") +Outdated_Local_File = WgetFile ("UpdatedFile", Cont2, timestamp="1990-01-01 00:00:00") + +UpToDate_Rules = { + "SendHeader" : { + "Last-Modified" : "Sun, 01 Jan 1995 00:00:00 GMT", + }, + "Response": 304, + "ExpectHeader" : { + "If-Modified-Since" : "Sun, 01 Jan 1995 00:00:00 GMT" + }, +} + +Outdated_Rules = { + "SendHeader" : { + "Last-Modified" : "Thu, 01 Jan 2015 00:00:00 GMT", + }, + "ExpectHeader" : { + "If-Modified-Since" : "Mon, 01 Jan 1990 00:00:00 GMT", + }, +} + +UpToDate_Server_File = WgetFile ("UpToDateFile", Cont3, rules=UpToDate_Rules) +Updated_Server_File = WgetFile ("UpdatedFile", Cont4, rules=Outdated_Rules) + +WGET_OPTIONS = "--condget" +WGET_URLS = [["UpToDateFile", "UpdatedFile", ]] + +Files = [[UpToDate_Server_File, Updated_Server_File, ]] +Existing_Files = [UpToDate_Local_File, Outdated_Local_File] + +ExpectedReturnCode = 0 + +# The uptodate file should not be downloaded +ExpectedDownloadedFiles = [UpToDate_Local_File, Updated_Server_File] + +# Kind of hack to ensure proper request types +Request_List = [ + [ + "GET /UpToDateFile", + "GET /UpdatedFile", + ] +] + +################ Pre and Post Test Hooks ##################################### +pre_test = { + "ServerFiles" : Files, + "LocalFiles" : Existing_Files +} +test_options = { + "WgetCommands" : WGET_OPTIONS, + "Urls" : WGET_URLS +} +post_test = { + "ExpectedFiles" : ExpectedDownloadedFiles, + "ExpectedRetcode" : ExpectedReturnCode, + "FilesCrawled" : Request_List, +} + +err = HTTPTest ( + name=TEST_NAME, + pre_hook=pre_test, + test_params=test_options, + post_hook=post_test +).begin () + +exit (err) -- 2.4.0