Browse Source

Create PlaintextTestType

Hamilton Turner 10 years ago
parent
commit
b0eba3287b

+ 0 - 15
toolset/benchmark/framework_test.py

@@ -389,21 +389,6 @@ class FrameworkTest:
       err_str += "Got exception when trying to validate the update test: {exception}\n".format(exception=traceback.format_exc())
     return (True, ) if len(err_str) == 0 else (False, err_str)
 
-  ############################################################
-  #
-  ############################################################
-  def validatePlaintext(self, jsonString, out, err):
-    err_str = ""
-    if jsonString is None or len(jsonString) == 0:
-      err_str += "Empty Response"
-      return (False, err_str)
-    try:
-      if not jsonString.lower().strip() == "hello, world!":
-        err_str += "Expected 'Hello, World!', got '{message}'.\n".format(message=jsonString.strip())
-    except:
-      err_str += "Got exception when trying to validate the plaintext test: {exception}\n".format(exception=traceback.format_exc())
-    return (True, ) if len(err_str) == 0 else (False, err_str)
-
   ############################################################
   # start(benchmarker)
   # Start the test using it's setup file

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

@@ -1,3 +1,4 @@
 
 from framework_test_type import *
-from json_type import JsonTestType
+from json_type import JsonTestType
+from plaintext_type import PlaintextTestType

+ 1 - 6
toolset/benchmark/test_types/framework_test_type.py

@@ -90,8 +90,7 @@ class FrameworkTestType:
     - urlTested is the URL that was queried
     '''
     # TODO make String result into an enum to enforce
-    # raise NotImplementedError("Subclasses must provide verify")
-    return [('pass','', '')]
+    raise NotImplementedError("Subclasses must provide verify")
 
   def get_url(self):
     '''Returns the URL for this test, like '/json'''
@@ -120,7 +119,3 @@ class UpdateTestType(FrameworkTestType):
     args = ['update_url']
     FrameworkTestType.__init__(self, name='update', requires_db=True, args=args)
 
-class PlaintextTestType(FrameworkTestType):
-  def __init__(self):
-    args = ['plaintext_url']
-    FrameworkTestType.__init__(self, name='plaintext', requires_db=False, args=args)

+ 32 - 0
toolset/benchmark/test_types/plaintext_type.py

@@ -0,0 +1,32 @@
+from benchmark.test_types.framework_test_type import FrameworkTestType
+
+class PlaintextTestType(FrameworkTestType):
+  def __init__(self):
+    args = ['plaintext_url']
+    FrameworkTestType.__init__(self, name='plaintext', requires_db=False, accept_header=self.accept_plaintext, args=args)
+
+  def verify(self, base_url):
+    url = base_url + self.plaintext_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)]
+
+    # Case insensitive
+    orig = body
+    body = body.lower()
+
+    if "hello, world!" not in body:
+      return [('fail', "Could not find 'Hello, World!' in response", url)]
+
+    if len("hello, world!") < len(body):
+      return [('warn', '''Server is returning more data than is required.
+        This may negatively affect benchmark performance''', url)]
+
+    return [('pass', '', url)]
+
+  def get_url(self):
+    return self.plaintext_url