tools/httptester/BaseTest.py

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/tools/httptester/BaseTest.py	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,61 @@
     1.4 +# This Source Code Form is subject to the terms of the Mozilla Public
     1.5 +# License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 +# file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.7 +
     1.8 +"""The test case itsself, and associated stuff"""
     1.9 +
    1.10 +import string
    1.11 +
    1.12 +class BaseTest:
    1.13 +    def __init__(self):
    1.14 +        self.res = -1
    1.15 +        self.reason = None
    1.16 +    
    1.17 +    def parse_config(self, config):
    1.18 +        self.files = []
    1.19 +
    1.20 +        for line in config.readlines():
    1.21 +            line = string.strip(line)
    1.22 +            self.files.append({'file': line, 'read': 0})
    1.23 +
    1.24 +    baseName = 'index'
    1.25 +
    1.26 +    def verify_request(self, req):
    1.27 +        """Check that the request is valid.
    1.28 +
    1.29 +        Also needs to update any internal 'read' stuff"""
    1.30 +        
    1.31 +        ## XXXXX
    1.32 +        ## This needs to be done using exceptions, maybe
    1.33 +        ## XXXXX
    1.34 +        
    1.35 +        for i in self.files:
    1.36 +            if i['file'] == req.fname:
    1.37 +                if i['read'] == 1:
    1.38 +                    self.res = 0
    1.39 +                    self.reason = "File %s was read twice" % (req.fname)
    1.40 +                    return 0
    1.41 +                i['read'] = 1
    1.42 +                break
    1.43 +            elif i['read'] == 0:
    1.44 +                self.res = 0
    1.45 +                self.reason = "File %s requested, expected %s" % (req.fname, i['file'])
    1.46 +                return 0
    1.47 +
    1.48 +        ### Simplistic for now...
    1.49 +        res = req.headers.getheader('Host')
    1.50 +
    1.51 +        return res
    1.52 +
    1.53 +    def result(self):
    1.54 +        if self.res == -1:
    1.55 +            for i in self.files:
    1.56 +                if i['read'] == 0:
    1.57 +                    self.res = 0
    1.58 +                    self.reason = "%s not read" % (i['file'])
    1.59 +                    return self.res, self.reason
    1.60 +            self.res = 1
    1.61 +            
    1.62 +        return self.res, self.reason
    1.63 +
    1.64 +tester = BaseTest

mercurial