tools/httptester/BaseTest.py
author Simon Montagu <smontagu@smontagu.org>
Sun, 07 Nov 2010 11:56:26 +0200
changeset 57057 8cbe835425964fab8e13b0e789d13b2dcf38d433
parent 1 9b2a99adc05e53cd4010de512f50118594756650
child 98529 f4157e8c410708d76703f19e4dfb61859bfe32d8
permissions -rw-r--r--
Update Unicode data files to version 6.0. Bug 606917, r=emk, a=bsmedberg

"""The test case itsself, and associated stuff"""

import string

class BaseTest:
    def __init__(self):
        self.res = -1
        self.reason = None
    
    def parse_config(self, config):
        self.files = []

        for line in config.readlines():
            line = string.strip(line)
            self.files.append({'file': line, 'read': 0})

    baseName = 'index'

    def verify_request(self, req):
        """Check that the request is valid.

        Also needs to update any internal 'read' stuff"""
        
        ## XXXXX
        ## This needs to be done using exceptions, maybe
        ## XXXXX
        
        for i in self.files:
            if i['file'] == req.fname:
                if i['read'] == 1:
                    self.res = 0
                    self.reason = "File %s was read twice" % (req.fname)
                    return 0
                i['read'] = 1
                break
            elif i['read'] == 0:
                self.res = 0
                self.reason = "File %s requested, expected %s" % (req.fname, i['file'])
                return 0

        ### Simplistic for now...
        res = req.headers.getheader('Host')

        return res

    def result(self):
        if self.res == -1:
            for i in self.files:
                if i['read'] == 0:
                    self.res = 0
                    self.reason = "%s not read" % (i['file'])
                    return self.res, self.reason
            self.res = 1
            
        return self.res, self.reason

tester = BaseTest