Browse Source

Add FortuneTestType

Hamilton Turner 10 years ago
parent
commit
91dab9ae05

+ 2 - 1
toolset/benchmark/test_types/__init__.py

@@ -4,4 +4,5 @@ from json_type import JsonTestType
 from plaintext_type import PlaintextTestType
 from db_type import DBTestType
 from query_type import QueryTestType
-from update_type import UpdateTestType
+from update_type import UpdateTestType
+from fortune_type import FortuneTestType

+ 35 - 0
toolset/benchmark/test_types/fortune_type.py

@@ -0,0 +1,35 @@
+from benchmark.test_types.framework_test_type import FrameworkTestType
+from benchmark.fortune_html_parser import FortuneHTMLParser
+
+class FortuneTestType(FrameworkTestType):
+  def __init__(self):
+    args = ['fortune_url']
+    FrameworkTestType.__init__(self, name='fortune', 
+      requires_db=True, 
+      accept_header=self.accept_html, 
+      args=args)
+
+  def get_url(self):
+    return self.fortune_url
+
+  def verify(self, base_url):
+    '''Parses the given HTML string and asks the 
+    FortuneHTMLParser whether the parsed string is a 
+    valid fortune response
+    '''
+    url = base_url + self.fortune_url
+    body = self._curl(url)
+    
+    # Empty response
+    if body is None:
+      return [('fail','No response', url)]
+    elif len(body) == 0:
+      return [('fail','Empty Response', url)]
+
+    parser = FortuneHTMLParser()
+    parser.feed(body)
+    if parser.isValidFortune(self.out):
+      return [('pass','',url)]
+    else:
+      return [('fail','Invalid according to FortuneHTMLParser',url)]
+

+ 0 - 4
toolset/benchmark/test_types/framework_test_type.py

@@ -105,8 +105,4 @@ class FrameworkTestType:
     # for their URL so the base class can't know which arg is the URL
     raise NotImplementedError("Subclasses must provide verify")
 
-class FortuneTestType(FrameworkTestType):
-  def __init__(self):
-    args = ['fortune_url']
-    FrameworkTestType.__init__(self, name='fortune', requires_db=True, args=args)