From e244aa2c7ccc2e5c58eecf81f57c199dbfddf3d4 Mon Sep 17 00:00:00 2001 From: Elita Lobo Date: Sun, 15 Mar 2015 23:18:07 +0530 Subject: [PATCH] Ports test from old test suite to Python * Test-restrict-lowercase.py: Tests --restrict-filename=lowercase feature * Test-restrict-ascii.py: Tests --restrict-filename=ascii feature * Test-restrict-uppercase.py: Tests --restrict-filename=uppercase feature *Test-nonexisting-quiet.py: Tests Wget's quiet feature * Test-start-pos.py: Tests Wget's --start-pos feature * Test-start-pos--continue.py Tests Wget's --start-pos with -c feature * Makefile.am: Adds newly added testfiles to test suite --- testenv/Makefile.am | 8 ++++- testenv/Test-nonexisting-quiet.py | 48 ++++++++++++++++++++++++++ testenv/Test-restrict-ascii.py | 67 +++++++++++++++++++++++++++++++++++++ testenv/Test-restrict-lowercase.py | 57 +++++++++++++++++++++++++++++++ testenv/Test-restrict-uppercase.py | 57 +++++++++++++++++++++++++++++++ testenv/Test-start-pos--continue.py | 55 ++++++++++++++++++++++++++++++ testenv/Test-start-pos.py | 51 ++++++++++++++++++++++++++++ 7 files changed, 342 insertions(+), 1 deletion(-) create mode 100644 testenv/Test-nonexisting-quiet.py create mode 100644 testenv/Test-restrict-ascii.py create mode 100644 testenv/Test-restrict-lowercase.py create mode 100644 testenv/Test-restrict-uppercase.py create mode 100644 testenv/Test-start-pos--continue.py create mode 100644 testenv/Test-start-pos.py diff --git a/testenv/Makefile.am b/testenv/Makefile.am index a4e0352..a275df2 100644 --- a/testenv/Makefile.am +++ b/testenv/Makefile.am @@ -53,7 +53,13 @@ if HAVE_PYTHON3 Test-Post.py \ Test-504.py \ Test--spider-r.py \ - Test-redirect-crash.py + Test-redirect-crash.py \ + Test-restrict-ascii.py \ + Test-restrict-lowercase.py \ + Test-restrict-uppercase.py \ + Test-nonexisting-quiet.py \ + Test-start-pos.py \ + Test-start-pos--continue.py # added test cases expected to fail here and under TESTS XFAIL_TESTS = diff --git a/testenv/Test-nonexisting-quiet.py b/testenv/Test-nonexisting-quiet.py new file mode 100644 index 0000000..5b22d0c --- /dev/null +++ b/testenv/Test-nonexisting-quiet.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python3 +from sys import exit +from test.http_test import HTTPTest +from misc.wget_file import WgetFile + +""" + Test for Wget nonexisting quiet. --quiet turns off Wget's output. +""" +TEST_NAME = "Test nonexisting quiet" +################################ File Definitions ############################################################################# +dummyfile = "This is a dummy file" + +A_File = WgetFile("dummy.html", dummyfile) + +WGET_OPTIONS = "--quiet" +WGET_URLS = [["nonexistent"]] + +Files = [[A_File]] + +ExpectedReturnCode = 8 +ExpectedDownloadedFiles = [] + +################### Pre and Post Test Hooks ############################### +pre_test = { + "ServerFiles" : Files, +} +test_options = { + "WgetCommands" :WGET_OPTIONS, + "Urls" :WGET_URLS +} +post_test = { + "ExpectedFiles" : ExpectedDownloadedFiles, + "ExpectedRetcode" : ExpectedReturnCode +} + +err = HTTPTest ( + name=TEST_NAME, + pre_hook=pre_test, + test_params=test_options, + post_hook=post_test +).begin () + +exit(err) + + + + + diff --git a/testenv/Test-restrict-ascii.py b/testenv/Test-restrict-ascii.py new file mode 100644 index 0000000..c974f68 --- /dev/null +++ b/testenv/Test-restrict-ascii.py @@ -0,0 +1,67 @@ +#!/usr/bin/env python3 +from sys import exit +from test.http_test import HTTPTest +from misc.wget_file import WgetFile + +""" + This program tests that --restrict-file-names=ascii can be used to + ensure that all high-valued bytes are escaped. The sample filename was + chosen because in former versions of Wget, one could either choose not + to escape any portion of the UTF-8 filename via + --restrict-file-names=nocontrol (which would only be helpful if one + was _on_ a UTF-8 system), or else Wget would escape _portions_ of + characters, leaving irrelevant "latin1"-looking characters combined + with percent-encoded "control" characters, instead of encoding all the + bytes of an entire non-ASCII UTF-8 character. +""" + +TEST_NAME = "Restrict filename:ascii" + +# "gnosis" in UTF-8 greek +gnosis = "%CE%B3%CE%BD%CF%89%CF%83%CE%B9%CF%82" +#################################### File Definitions ######################### + +mainpage = """ + + + Some Page Title + + +

+ Some text... +

+ + +""" +A_File = WgetFile(gnosis + ".html", mainpage) + +WGET_OPTIONS = "--restrict-file-names=ascii" +WGET_URLS = [[gnosis + ".html"]] + +Files = [[A_File]] + +ExpectedReturnCode = 0 +ExpectedDownloadedFiles = [A_File] + +######################### Pre and Post Test hooks ############################ +pre_test = { + "ServerFiles" :Files, +} +test_options = { + "WgetCommands" :WGET_OPTIONS, + "Urls" :WGET_URLS +} +post_test = { + "ExpectedFiles" : ExpectedDownloadedFiles, + "ExpectedRetcode" : ExpectedReturnCode +} + +err = HTTPTest ( + name=TEST_NAME, + pre_hook=pre_test, + test_params=test_options, + post_hook=post_test +).begin () + +exit(err) + diff --git a/testenv/Test-restrict-lowercase.py b/testenv/Test-restrict-lowercase.py new file mode 100644 index 0000000..e34eda6 --- /dev/null +++ b/testenv/Test-restrict-lowercase.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python3 +from sys import exit +from test.http_test import HTTPTest +from misc.wget_file import WgetFile +""" + Test if Wget converts filename to lowercase. +""" +TEST_NAME = "Restrict filename:lowercase" +#################################### File Definitions ######################### + +mainpage = """ + + + Some Page Title + + +

+ Some text... +

+ + +""" +filename = "SomeFile.html" + +A_File = WgetFile(filename, mainpage) +B_File = WgetFile(filename.lower(), mainpage) + +WGET_OPTIONS = "--restrict-file-names=lowercase" +WGET_URLS = [[filename]] + +Files = [[A_File]] + +ExpectedReturnCode = 0 +ExpectedDownloadedFiles = [B_File] + +######################### Pre and Post Test hooks ############################ +pre_test = { + "ServerFiles" :Files, +} +test_options = { + "WgetCommands" :WGET_OPTIONS, + "Urls" :WGET_URLS +} +post_test = { + "ExpectedFiles" : ExpectedDownloadedFiles, + "ExpectedRetcode" : ExpectedReturnCode +} + +err = HTTPTest ( + name=TEST_NAME, + pre_hook=pre_test, + test_params=test_options, + post_hook=post_test +).begin () + +exit(err) + diff --git a/testenv/Test-restrict-uppercase.py b/testenv/Test-restrict-uppercase.py new file mode 100644 index 0000000..4e3fed1 --- /dev/null +++ b/testenv/Test-restrict-uppercase.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python3 +from sys import exit +from test.http_test import HTTPTest +from misc.wget_file import WgetFile +""" + Test if Wget converts filename to uppercase. +""" +TEST_NAME = "Restrict filename:uppercase" +#################################### File Definitions ######################### + +mainpage = """ + + + Some Page Title + + +

+ Some text... +

+ + +""" +filename = "SomeFile.html" + +A_File = WgetFile(filename, mainpage) +B_File = WgetFile(filename.upper(), mainpage) + +WGET_OPTIONS = "--restrict-file-names=uppercase" +WGET_URLS = [[filename]] + +Files = [[A_File]] + +ExpectedReturnCode = 0 +ExpectedDownloadedFiles = [B_File] + +######################### Pre and Post Test hooks ############################ +pre_test = { + "ServerFiles" :Files, +} +test_options = { + "WgetCommands" :WGET_OPTIONS, + "Urls" :WGET_URLS +} +post_test = { + "ExpectedFiles" : ExpectedDownloadedFiles, + "ExpectedRetcode" : ExpectedReturnCode +} + +err = HTTPTest ( + name=TEST_NAME, + pre_hook=pre_test, + test_params=test_options, + post_hook=post_test +).begin () + +exit(err) + diff --git a/testenv/Test-start-pos--continue.py b/testenv/Test-start-pos--continue.py new file mode 100644 index 0000000..dfc1a38 --- /dev/null +++ b/testenv/Test-start-pos--continue.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python3 +from sys import exit +from test.http_test import HTTPTest +from misc.wget_file import WgetFile + +""" + Tests if Wget correctly starts downloading bytes from the given start position (--start-pos=OFFSET) in the file. +""" +TEST_NAME = "Test start-pos" +################################ File Definitions ############################################################################# +File1 = "12345678910" +File2 = "This is an existing file" +File3 = "2345678910" + +File1_rules = { + "SendHeader" : { + "Response" : 206 + } +} + +A_File = WgetFile("somefile.txt", File1, rules=File1_rules) +B_File = WgetFile("somefile.txt", File2) +C_File = WgetFile("somefile.txt.1", File3) + +WGET_OPTIONS = "--start-pos=1 --continue --debug" +WGET_URLS = [["somefile.txt"]] + +Files = [[A_File]] +Existing_Files = [B_File] + +ExpectedReturnCode = 0 +ExpectedDownloadedFiles = [B_File, C_File] + +################### 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 +} + +err = HTTPTest ( + name=TEST_NAME, + pre_hook=pre_test, + test_params=test_options, + post_hook=post_test +).begin () + +exit(err) diff --git a/testenv/Test-start-pos.py b/testenv/Test-start-pos.py new file mode 100644 index 0000000..5502b2b --- /dev/null +++ b/testenv/Test-start-pos.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python3 +from sys import exit +from test.http_test import HTTPTest +from misc.wget_file import WgetFile + +""" + Tests if Wget correctly starts downloading bytes from the given start position (--start-pos=OFFSET) in the file. +""" +TEST_NAME = "Test start-pos" +################################ File Definitions ############################################################################# +File1 = "12345678910" +File2 = "2345678910" + +File1_rules = { + "SendHeader" : { + "Response" : 206 + } +} + +A_File = WgetFile("File1", File1, rules=File1_rules) +B_File = WgetFile("File1", File2) + +WGET_OPTIONS = "--start-pos=1" +WGET_URLS = [["File1"]] + +Files = [[A_File]] + +ExpectedReturnCode = 0 +ExpectedDownloadedFiles = [B_File] + +################### Pre and Post Test Hooks ############################### +pre_test = { + "ServerFiles" : Files, +} +test_options = { + "WgetCommands" :WGET_OPTIONS, + "Urls" :WGET_URLS, +} +post_test = { + "ExpectedFiles" : ExpectedDownloadedFiles, + "ExpectedRetcode" : ExpectedReturnCode +} + +err = HTTPTest ( + name=TEST_NAME, + pre_hook=pre_test, + test_params=test_options, + post_hook=post_test +).begin () + +exit(err) -- 2.1.4