tools/httptester/BaseTest.py

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:356572f423f9
1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
5 """The test case itsself, and associated stuff"""
6
7 import string
8
9 class BaseTest:
10 def __init__(self):
11 self.res = -1
12 self.reason = None
13
14 def parse_config(self, config):
15 self.files = []
16
17 for line in config.readlines():
18 line = string.strip(line)
19 self.files.append({'file': line, 'read': 0})
20
21 baseName = 'index'
22
23 def verify_request(self, req):
24 """Check that the request is valid.
25
26 Also needs to update any internal 'read' stuff"""
27
28 ## XXXXX
29 ## This needs to be done using exceptions, maybe
30 ## XXXXX
31
32 for i in self.files:
33 if i['file'] == req.fname:
34 if i['read'] == 1:
35 self.res = 0
36 self.reason = "File %s was read twice" % (req.fname)
37 return 0
38 i['read'] = 1
39 break
40 elif i['read'] == 0:
41 self.res = 0
42 self.reason = "File %s requested, expected %s" % (req.fname, i['file'])
43 return 0
44
45 ### Simplistic for now...
46 res = req.headers.getheader('Host')
47
48 return res
49
50 def result(self):
51 if self.res == -1:
52 for i in self.files:
53 if i['read'] == 0:
54 self.res = 0
55 self.reason = "%s not read" % (i['file'])
56 return self.res, self.reason
57 self.res = 1
58
59 return self.res, self.reason
60
61 tester = BaseTest

mercurial