[tests] Add header.* action tests

personal/stbuehler/wip
Stefan Bühler 12 years ago
parent 2941105e28
commit 2240b5c354
  1. 6
      tests/base.py
  2. 76
      tests/t-header-modify.py

@ -145,7 +145,7 @@ var.vhosts = var.vhosts + [ "%s" : ${
print >> Env.log, "Test %s failed" % (self.name)
else:
print >> sys.stderr, "Test %s failed" % (self.name)
except Exception, e:
except BaseException, e:
failed = True
if self.todo:
print >> Env.log, "Test %s failed:" % (self.name)
@ -476,7 +476,7 @@ allow-listen {{ ip "127.0.0.1:{Env.port}"; }}
if self.prepared_files.has_key(fname):
try:
os.remove(os.path.join(Env.dir, fname))
except Exception, e:
except BaseException, e:
print >>sys.stderr, "Couldn't delete file '%s': %s" % (fname, e)
return False
return True
@ -495,7 +495,7 @@ allow-listen {{ ip "127.0.0.1:{Env.port}"; }}
if 0 == self.prepared_dirs[dirname]:
try:
os.rmdir(os.path.join(Env.dir, dirname))
except Exception, e:
except BaseException, e:
print >>sys.stderr, "Couldn't delete directory '%s': %s" % (dirname, e)
def PrepareFile(self, fname, content):

@ -0,0 +1,76 @@
# -*- coding: utf-8 -*-
from base import *
from requests import *
class TestHeaderAdd(CurlRequest):
# use capture from previous regex conditional
config = """
header.add "Test-Header" => "%{req.query}";
header.add "Test-Header" => "%{req.path}";
blank;
"""
URL = "/path?simple_query"
def CheckResponse(self):
h = map(lambda x: x[1], filter(lambda x: x[0] == "Test-Header", self.resp_header_list))
if len(h) != 2 or h[0] != "simple_query" or h[1] != "/path":
print >>Env.log, repr(h)
raise BaseException("Unexpected headers 'Test-Header'")
return True
class TestHeaderAppend(CurlRequest):
# use capture from previous regex conditional
config = """
header.append "Test-Header" => "%{req.query}";
header.append "Test-Header" => "%{req.path}";
blank;
"""
URL = "/path?simple_query"
def CheckResponse(self):
h = map(lambda x: x[1], filter(lambda x: x[0] == "Test-Header", self.resp_header_list))
if len(h) != 1 or h[0] != "simple_query, /path":
print >>Env.log, repr(h)
raise BaseException("Unexpected headers 'Test-Header'")
return True
class TestHeaderOverwrite(CurlRequest):
# use capture from previous regex conditional
config = """
header.overwrite "Test-Header" => "%{req.query}";
header.overwrite "Test-Header" => "%{req.path}";
blank;
"""
URL = "/path?simple_query"
def CheckResponse(self):
h = map(lambda x: x[1], filter(lambda x: x[0] == "Test-Header", self.resp_header_list))
if len(h) != 1 or h[0] != "/path":
print >>Env.log, repr(h)
raise BaseException("Unexpected headers 'Test-Header'")
return True
class TestHeaderRemove(CurlRequest):
# use capture from previous regex conditional
config = """
header.add "Test-Header" => "%{req.query}";
header.remove "Test-Header";
blank;
"""
URL = "/path?simple_query"
def CheckResponse(self):
h = map(lambda x: x[1], filter(lambda x: x[0] == "Test-Header", self.resp_header_list))
if len(h) != 0:
print >>Env.log, repr(h)
raise BaseException("Unexpected headers 'Test-Header'")
return True
class Test(GroupTest):
group = [
TestHeaderAdd,
TestHeaderAppend,
TestHeaderOverwrite,
TestHeaderRemove,
]
Loading…
Cancel
Save