michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: """The test case itsself, and associated stuff""" michael@0: michael@0: import string michael@0: michael@0: class BaseTest: michael@0: def __init__(self): michael@0: self.res = -1 michael@0: self.reason = None michael@0: michael@0: def parse_config(self, config): michael@0: self.files = [] michael@0: michael@0: for line in config.readlines(): michael@0: line = string.strip(line) michael@0: self.files.append({'file': line, 'read': 0}) michael@0: michael@0: baseName = 'index' michael@0: michael@0: def verify_request(self, req): michael@0: """Check that the request is valid. michael@0: michael@0: Also needs to update any internal 'read' stuff""" michael@0: michael@0: ## XXXXX michael@0: ## This needs to be done using exceptions, maybe michael@0: ## XXXXX michael@0: michael@0: for i in self.files: michael@0: if i['file'] == req.fname: michael@0: if i['read'] == 1: michael@0: self.res = 0 michael@0: self.reason = "File %s was read twice" % (req.fname) michael@0: return 0 michael@0: i['read'] = 1 michael@0: break michael@0: elif i['read'] == 0: michael@0: self.res = 0 michael@0: self.reason = "File %s requested, expected %s" % (req.fname, i['file']) michael@0: return 0 michael@0: michael@0: ### Simplistic for now... michael@0: res = req.headers.getheader('Host') michael@0: michael@0: return res michael@0: michael@0: def result(self): michael@0: if self.res == -1: michael@0: for i in self.files: michael@0: if i['read'] == 0: michael@0: self.res = 0 michael@0: self.reason = "%s not read" % (i['file']) michael@0: return self.res, self.reason michael@0: self.res = 1 michael@0: michael@0: return self.res, self.reason michael@0: michael@0: tester = BaseTest