commit 1e351c9bc86f89ad022fb1e580182acbb4778dee Author: Arturo Filastò art@fuffa.org Date: Tue Feb 26 23:33:37 2013 +0100
Fix bug #7999 allowing tests to inherit from multiple test templates --- ooni/templates/dnst.py | 10 ++++++---- ooni/templates/httpt.py | 8 +++++--- ooni/templates/scapyt.py | 2 ++ ooni/templates/tcpt.py | 2 ++ 4 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/ooni/templates/dnst.py b/ooni/templates/dnst.py index 08d660a..caf4d04 100644 --- a/ooni/templates/dnst.py +++ b/ooni/templates/dnst.py @@ -28,6 +28,8 @@ class DNSTest(NetTestCase): queryTimeout = [1]
def _setUp(self): + super(DNSTest, self)._setUp() + self.report['queries'] = []
def performPTRLookup(self, address, dns_server): @@ -51,7 +53,7 @@ class DNSTest(NetTestCase): name = str(answer.payload.name) answers.append(representAnswer(answer))
- self.addToReport(query, resolver=dns_server, + DNSTest.addToReport(self, query, resolver=dns_server, query_type = 'PTR', answers=answers, name=name) return name
@@ -59,7 +61,7 @@ class DNSTest(NetTestCase): log.err("Failed to perform lookup") log.exception(failure) failure.trap(gaierror, TimeoutError) - self.addToReport(query, resolver=dns_server, + DNSTest.addToReport(self, query, resolver=dns_server, query_type = 'PTR', failure=failure) return None
@@ -89,13 +91,13 @@ class DNSTest(NetTestCase): addrs.append(addr) answers.append(representAnswer(answer))
- self.addToReport(query, resolver=dns_server, query_type='A', + DNSTest.addToReport(self, query, resolver=dns_server, query_type='A', answers=answers, addrs=addrs) return addrs
def gotError(failure): failure.trap(gaierror, TimeoutError) - self.addToReport(query, resolver=dns_server, query_type='A', + DNSTest.addToReport(self, query, resolver=dns_server, query_type='A', failure=failure) return failure
diff --git a/ooni/templates/httpt.py b/ooni/templates/httpt.py index a265f4c..5e6bc5d 100644 --- a/ooni/templates/httpt.py +++ b/ooni/templates/httpt.py @@ -54,6 +54,8 @@ class HTTPTest(NetTestCase): responses = []
def _setUp(self): + super(HTTPTest, self)._setUp() + try: import OpenSSL except: @@ -134,7 +136,7 @@ class HTTPTest(NetTestCase):
def _processResponseBody(self, response_body, request, response, body_processor): log.debug("Processing response body") - self.addToReport(request, response, response_body) + HTTPTest.addToReport(self, request, response, response_body) if body_processor: body_processor(response_body) else: @@ -205,7 +207,7 @@ class HTTPTest(NetTestCase): """ if not response: log.err("Got no response for request %s" % request) - self.addToReport(request, response) + HTTPTest.addToReport(self, request, response) return else: log.debug("Got response %s" % response) @@ -304,7 +306,7 @@ class HTTPTest(NetTestCase): def errback(failure, request): failure_string = handleAllFailures(failure) log.err("Error performing %s" % request) - self.addToReport(request, failure_string=failure_string) + HTTPTest.addToReport(self, request, failure_string=failure_string) return failure
d = agent.request(request['method'], request['url'], headers, diff --git a/ooni/templates/scapyt.py b/ooni/templates/scapyt.py index 5f6c7c8..cadc793 100644 --- a/ooni/templates/scapyt.py +++ b/ooni/templates/scapyt.py @@ -37,6 +37,8 @@ class BaseScapyTest(NetTestCase): ]
def _setUp(self): + super(BaseScapyTest, self)._setUp() + if not config.scapyFactory: log.debug("Scapy factoring not set, registering it.") config.scapyFactory = ScapyFactory(config.advanced.interface) diff --git a/ooni/templates/tcpt.py b/ooni/templates/tcpt.py index 323ead8..1acd6bb 100644 --- a/ooni/templates/tcpt.py +++ b/ooni/templates/tcpt.py @@ -57,6 +57,8 @@ class TCPTest(NetTestCase): port = None
def _setUp(self): + super(TCPTest, self)._setUp() + self.report['sent'] = [] self.report['received'] = []