Browse Source

Move JsonTestType into separate file

Hamilton Turner 11 years ago
parent
commit
ee7856d613

+ 1 - 1
toolset/benchmark/benchmarker.py

@@ -2,7 +2,7 @@ from setup.linux.installer import Installer
 from setup.linux import setup_util
 
 from benchmark import framework_test
-from benchmark.test_types.framework_test_type import *
+from benchmark.test_types import *
 from utils import header
 from utils import gather_tests
 from utils import gather_frameworks

+ 1 - 1
toolset/benchmark/framework_test.py

@@ -1,6 +1,6 @@
 from benchmark.fortune_html_parser import FortuneHTMLParser
 from setup.linux import setup_util
-from benchmark.test_types.framework_test_type import *
+from benchmark.test_types import *
 
 import importlib
 import os

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

@@ -1 +1,3 @@
-# Benchmark
+
+from framework_test_type import *
+from json_type import JsonTestType

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

@@ -104,50 +104,6 @@ class FrameworkTestType:
     # for their URL so the base class can't know which arg is the URL
     raise NotImplementedError("Subclasses must provide verify")
 
-
-class JsonTestType(FrameworkTestType):
-  def __init__(self):
-    args = ['json_url']
-    FrameworkTestType.__init__(self, name='json', requires_db=False, accept_header=self.accept_json, args=args)
-
-  def get_url(self):
-    return self.json_url
-
-  def verify(self, base_url):
-    '''Validates the response is a JSON object of 
-    { 'message' : 'hello, world!' }. Case insensitive and 
-    quoting style is ignored
-    '''
-
-    url = base_url + self.json_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)]
-  
-    # Valid JSON? 
-    try: 
-      response = json.loads(body)
-    except ValueError as ve:
-      return [('fail',"Invalid JSON - %s" % ve, url)]
-    
-    # Make everything case insensitive
-    response = {k.lower(): v.lower() for k,v in response.iteritems()}
-
-    if "message" not in response:
-      return [('fail',"No JSON key 'message'", url)]
-
-    if len(response) != 1:
-      return [('warn',"Too many JSON key/value pairs, expected 1", url)]
-
-    if response['message'] != 'hello, world!':
-      return [('fail',"Expected message of 'hello, world!', got '%s'"%response['message'], url)]
-
-    return [('pass','',url)]
-
 class DBTestType(FrameworkTestType):
   def __init__(self):
     args = ['db_url']

+ 44 - 0
toolset/benchmark/test_types/json_type.py

@@ -0,0 +1,44 @@
+from benchmark.test_types.framework_test_type import FrameworkTestType
+
+class JsonTestType(FrameworkTestType):
+  def __init__(self):
+    args = ['json_url']
+    FrameworkTestType.__init__(self, name='json', requires_db=False, accept_header=self.accept_json, args=args)
+
+  def get_url(self):
+    return self.json_url
+
+  def verify(self, base_url):
+    '''Validates the response is a JSON object of 
+    { 'message' : 'hello, world!' }. Case insensitive and 
+    quoting style is ignored
+    '''
+
+    url = base_url + self.json_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)]
+  
+    # Valid JSON? 
+    try: 
+      response = json.loads(body)
+    except ValueError as ve:
+      return [('fail',"Invalid JSON - %s" % ve, url)]
+    
+    # Make everything case insensitive
+    response = {k.lower(): v.lower() for k,v in response.iteritems()}
+
+    if "message" not in response:
+      return [('fail',"No JSON key 'message'", url)]
+
+    if len(response) != 1:
+      return [('warn',"Too many JSON key/value pairs, expected 1", url)]
+
+    if response['message'] != 'hello, world!':
+      return [('fail',"Expected message of 'hello, world!', got '%s'"%response['message'], url)]
+
+    return [('pass','',url)]