From 552cc72fd0957420c7354f3619799aef38788c5e Mon Sep 17 00:00:00 2001
From: "Dale R. Worley" <address@hidden>
Date: Tue, 23 Aug 2016 18:09:16 -0400
Subject: [PATCH 3/4] Add tests for recursion and redirection.
[31;01m---[39;49;00m
testenv/Makefile.am | 3 +++
testenv/Test-recursive-basic.py | 57 +++++++++++++++++++++++++++++++++++++++
testenv/Test-recursive-include.py | 56 ++++++++++++++++++++++++++++++++++++++
testenv/Test-redirect.py | 57 +++++++++++++++++++++++++++++++++++++++
4 files changed, 173 insertions(+)
create mode 100755 testenv/Test-recursive-basic.py
create mode 100755 testenv/Test-recursive-include.py
create mode 100755 testenv/Test-redirect.py
[01mdiff --git a/testenv/Makefile.am b/testenv/Makefile.am[39;49;00m
[01mindex faf86a9..deef18e 100644[39;49;00m
[31;01m--- a/testenv/Makefile.am[39;49;00m
[32m+++ b/testenv/Makefile.am[39;49;00m
[01m[35m@@ -73,6 +73,9 @@ if HAVE_PYTHON3[39;49;00m
Test-pinnedpubkey-pem-fail-https.py \
Test-pinnedpubkey-pem-https.py \
Test-Post.py \
[32m+ Test-recursive-basic.py \[39;49;00m
[32m+ Test-recursive-include.py \[39;49;00m
[32m+ Test-redirect.py \[39;49;00m
Test-redirect-crash.py \
Test--rejected-log.py \
Test-reserved-chars.py \
[01mdiff --git a/testenv/Test-recursive-basic.py
b/testenv/Test-recursive-basic.py[39;49;00m
new file mode 100755
[01mindex 0000000..f425ea2[39;49;00m
[31;01m--- /dev/null[39;49;00m
[32m+++ b/testenv/Test-recursive-basic.py[39;49;00m
[01m[35m@@ -0,0 +1,57 @@[39;49;00m
[32m+#!/usr/bin/env python3[39;49;00m
[32m+from sys import exit[39;49;00m
[32m+from test.http_test import HTTPTest[39;49;00m
[32m+from test.base_test import HTTP, HTTPS[39;49;00m
[32m+from misc.wget_file import WgetFile[39;49;00m
[32m+[39;49;00m
[32m+"""[39;49;00m
[32m+ Basic test of --recursive.[39;49;00m
[32m+"""[39;49;00m
[32m+############# File Definitions
###############################################[39;49;00m
[32m+File1 = """<html><body>[39;49;00m
[32m+<a href=\"/a/File2.html\">text</a>[39;49;00m
[32m+<a href=\"/b/File3.html\">text</a>[39;49;00m
[32m+</body></html>"""[39;49;00m
[32m+File2 = "With lemon or cream?"[39;49;00m
[32m+File3 = "Surely you're joking Mr. Feynman"[39;49;00m
[32m+[39;49;00m
[32m+File1_File = WgetFile ("a/File1.html", File1)[39;49;00m
[32m+File2_File = WgetFile ("a/File2.html", File2)[39;49;00m
[32m+File3_File = WgetFile ("b/File3.html", File3)[39;49;00m
[32m+[39;49;00m
[32m+WGET_OPTIONS = "--recursive --no-host-directories"[39;49;00m
[32m+WGET_URLS = [["a/File1.html"]][39;49;00m
[32m+[39;49;00m
[32m+Servers = [HTTP][39;49;00m
[32m+[39;49;00m
[32m+Files = [[File1_File, File2_File, File3_File]][39;49;00m
[32m+Existing_Files = [][39;49;00m
[32m+[39;49;00m
[32m+ExpectedReturnCode = 0[39;49;00m
[32m+ExpectedDownloadedFiles = [File1_File, File2_File, File3_File][39;49;00m
[32m+Request_List = [["GET /a/File1.html",[39;49;00m
[32m+ "GET /a/File2.html",[39;49;00m
[32m+ "GET /b/File3.html"]][39;49;00m
[32m+[39;49;00m
[32m+################ Pre and Post Test Hooks
#####################################[39;49;00m
[32m+pre_test = {[39;49;00m
[32m+ "ServerFiles" : Files,[39;49;00m
[32m+ "LocalFiles" : Existing_Files[39;49;00m
[32m+}[39;49;00m
[32m+test_options = {[39;49;00m
[32m+ "WgetCommands" : WGET_OPTIONS,[39;49;00m
[32m+ "Urls" : WGET_URLS[39;49;00m
[32m+}[39;49;00m
[32m+post_test = {[39;49;00m
[32m+ "ExpectedFiles" : ExpectedDownloadedFiles,[39;49;00m
[32m+ "ExpectedRetcode" : ExpectedReturnCode[39;49;00m
[32m+}[39;49;00m
[32m+[39;49;00m
[32m+err = HTTPTest ([39;49;00m
[32m+ pre_hook=pre_test,[39;49;00m
[32m+ test_params=test_options,[39;49;00m
[32m+ post_hook=post_test,[39;49;00m
[32m+ protocols=Servers[39;49;00m
[32m+).begin ()[39;49;00m
[32m+[39;49;00m
[32m+exit (err)[39;49;00m
[01mdiff --git a/testenv/Test-recursive-include.py
b/testenv/Test-recursive-include.py[39;49;00m
new file mode 100755
[01mindex 0000000..1fe33cd[39;49;00m
[31;01m--- /dev/null[39;49;00m
[32m+++ b/testenv/Test-recursive-include.py[39;49;00m
[01m[35m@@ -0,0 +1,56 @@[39;49;00m
[32m+#!/usr/bin/env python3[39;49;00m
[32m+from sys import exit[39;49;00m
[32m+from test.http_test import HTTPTest[39;49;00m
[32m+from test.base_test import HTTP, HTTPS[39;49;00m
[32m+from misc.wget_file import WgetFile[39;49;00m
[32m+[39;49;00m
[32m+"""[39;49;00m
[32m+ Basic test of --recursive.[39;49;00m
[32m+"""[39;49;00m
[32m+############# File Definitions
###############################################[39;49;00m
[32m+File1 = """<html><body>[39;49;00m
[32m+<a href=\"/a/File2.html\">text</a>[39;49;00m
[32m+<a href=\"/b/File3.html\">text</a>[39;49;00m
[32m+</body></html>"""[39;49;00m
[32m+File2 = "With lemon or cream?"[39;49;00m
[32m+File3 = "Surely you're joking Mr. Feynman"[39;49;00m
[32m+[39;49;00m
[32m+File1_File = WgetFile ("a/File1.html", File1)[39;49;00m
[32m+File2_File = WgetFile ("a/File2.html", File2)[39;49;00m
[32m+File3_File = WgetFile ("b/File3.html", File3)[39;49;00m
[32m+[39;49;00m
[32m+WGET_OPTIONS = "--recursive --no-host-directories
--include-directories=a"[39;49;00m
[32m+WGET_URLS = [["a/File1.html"]][39;49;00m
[32m+[39;49;00m
[32m+Servers = [HTTP][39;49;00m
[32m+[39;49;00m
[32m+Files = [[File1_File, File2_File, File3_File]][39;49;00m
[32m+Existing_Files = [][39;49;00m
[32m+[39;49;00m
[32m+ExpectedReturnCode = 0[39;49;00m
[32m+ExpectedDownloadedFiles = [File1_File, File2_File][39;49;00m
[32m+Request_List = [["GET /a/File1.html",[39;49;00m
[32m+ "GET /a/File2.html"]][39;49;00m
[32m+[39;49;00m
[32m+################ Pre and Post Test Hooks
#####################################[39;49;00m
[32m+pre_test = {[39;49;00m
[32m+ "ServerFiles" : Files,[39;49;00m
[32m+ "LocalFiles" : Existing_Files[39;49;00m
[32m+}[39;49;00m
[32m+test_options = {[39;49;00m
[32m+ "WgetCommands" : WGET_OPTIONS,[39;49;00m
[32m+ "Urls" : WGET_URLS[39;49;00m
[32m+}[39;49;00m
[32m+post_test = {[39;49;00m
[32m+ "ExpectedFiles" : ExpectedDownloadedFiles,[39;49;00m
[32m+ "ExpectedRetcode" : ExpectedReturnCode[39;49;00m
[32m+}[39;49;00m
[32m+[39;49;00m
[32m+err = HTTPTest ([39;49;00m
[32m+ pre_hook=pre_test,[39;49;00m
[32m+ test_params=test_options,[39;49;00m
[32m+ post_hook=post_test,[39;49;00m
[32m+ protocols=Servers[39;49;00m
[32m+).begin ()[39;49;00m
[32m+[39;49;00m
[32m+exit (err)[39;49;00m
[01mdiff --git a/testenv/Test-redirect.py b/testenv/Test-redirect.py[39;49;00m
new file mode 100755
[01mindex 0000000..02adf52[39;49;00m
[31;01m--- /dev/null[39;49;00m
[32m+++ b/testenv/Test-redirect.py[39;49;00m
[01m[35m@@ -0,0 +1,57 @@[39;49;00m
[32m+#!/usr/bin/env python3[39;49;00m
[32m+from sys import exit[39;49;00m
[32m+from test.http_test import HTTPTest[39;49;00m
[32m+from test.base_test import HTTP, HTTPS[39;49;00m
[32m+from misc.wget_file import WgetFile[39;49;00m
[32m+[39;49;00m
[32m+"""[39;49;00m
[32m+ This is a Prototype Test File.[39;49;00m
[32m+ Ideally this File should be copied and edited to write new
tests.[39;49;00m
[32m+"""[39;49;00m
[32m+############# File Definitions
###############################################[39;49;00m
[32m+File2 = "Would you like some Tea?"[39;49;00m
[32m+[39;49;00m
[32m+File1_rules = {[39;49;00m
[32m+ "Response" : 301,[39;49;00m
[32m+ "SendHeader" : {"Location" : "/File2.txt"}[39;49;00m
[32m+}[39;49;00m
[32m+[39;49;00m
[32m+# /File1.txt is only a redirect, and so has no file content.[39;49;00m
[32m+File1_File = WgetFile ("File1.txt", "", rules=File1_rules)[39;49;00m
[32m+# File1_Retrieved is what will be retrieved for URL /File1.txt.[39;49;00m
[32m+File1_Retrieved = WgetFile ("File1.txt", File2)[39;49;00m
[32m+File2_File = WgetFile ("File2.txt", File2)[39;49;00m
[32m+[39;49;00m
[32m+WGET_OPTIONS = ""[39;49;00m
[32m+WGET_URLS = [["File1.txt"]][39;49;00m
[32m+[39;49;00m
[32m+Servers = [HTTP][39;49;00m
[32m+[39;49;00m
[32m+Files = [[File1_File, File2_File]][39;49;00m
[32m+Existing_Files = [][39;49;00m
[32m+[39;49;00m
[32m+ExpectedReturnCode = 0[39;49;00m
[32m+ExpectedDownloadedFiles = [File1_Retrieved][39;49;00m
[32m+[39;49;00m
[32m+################ Pre and Post Test Hooks
#####################################[39;49;00m
[32m+pre_test = {[39;49;00m
[32m+ "ServerFiles" : Files,[39;49;00m
[32m+ "LocalFiles" : Existing_Files[39;49;00m
[32m+}[39;49;00m
[32m+test_options = {[39;49;00m
[32m+ "WgetCommands" : WGET_OPTIONS,[39;49;00m
[32m+ "Urls" : WGET_URLS[39;49;00m
[32m+}[39;49;00m
[32m+post_test = {[39;49;00m
[32m+ "ExpectedFiles" : ExpectedDownloadedFiles,[39;49;00m
[32m+ "ExpectedRetcode" : ExpectedReturnCode[39;49;00m
[32m+}[39;49;00m
[32m+[39;49;00m
[32m+err = HTTPTest ([39;49;00m
[32m+ pre_hook=pre_test,[39;49;00m
[32m+ test_params=test_options,[39;49;00m
[32m+ post_hook=post_test,[39;49;00m
[32m+ protocols=Servers[39;49;00m
[32m+).begin ()[39;49;00m
[32m+[39;49;00m
[32m+exit (err)[39;49;00m
[31;01m-- [39;49;00m
2.10.0.rc0.17.gd63263a