Browse Source

Update accept header specification [WIP]

Zane Kansil 10 years ago
parent
commit
6b308f0595

+ 1 - 1
toolset/benchmark/test_types/db_type.py

@@ -8,7 +8,7 @@ class DBTestType(FrameworkTestType):
     def __init__(self):
         kwargs = {
             'name': 'db',
-            'accept_header': self.accept_json,
+            'accept_header': self.accept('json'),
             'requires_db': True,
             'args': ['db_url']
         }

+ 1 - 1
toolset/benchmark/test_types/fortune_type.py

@@ -7,7 +7,7 @@ class FortuneTestType(FrameworkTestType):
     def __init__(self):
         kwargs = {
             'name': 'fortune',
-            'accept_header': self.accept_html,
+            'accept_header': self.accept('html'),
             'requires_db': True,
             'args': ['fortune_url']
         }

+ 11 - 7
toolset/benchmark/test_types/framework_test_type.py

@@ -21,24 +21,28 @@ class FrameworkTestType:
   exist a member `X.spam = 'foobar'`. 
   '''
 
-  accept_json = "Accept: application/json,text/html;q=0.9,application/xhtml+xml;q=0.9,application/xml;q=0.8,*/*;q=0.7"
-  accept_html = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
-  accept_plaintext = "Accept: text/plain,text/html;q=0.9,application/xhtml+xml;q=0.9,application/xml;q=0.8,*/*;q=0.7"
-
-  def __init__(self, name, requires_db = False, accept_header = None, args = []):
+  def __init__(self, name, requires_db=False, accept_header=None, args=[]):
     self.name = name
     self.requires_db = requires_db
     self.args = args
     self.out = sys.stdout
     self.err = sys.stderr
-    self.accept_header = accept_header
     if accept_header is None:
-      self.accept_header = self.accept_plaintext
+      self.accept_header = self.accept('json')
+    else:
+      self.accept_header = accept_header
 
     self.passed = None
     self.failed = None
     self.warned = None
 
+  def accept(self, content_type):
+    return {
+      'json': 'application/json,text/html;q=0.9,application/xhtml+xml;q=0.9,application/xml;q=0.8,*/*;q=0.7',
+      'html': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
+      'plaintext': 'text/plain,text/html;q=0.9,application/xhtml+xml;q=0.9,application/xml;q=0.8,*/*;q=0.7'
+    }[content_type]
+
   def setup_out_err(self, out, err):
     '''Sets up file-like objects for logging. Used in 
     cases where it is hard just return the output. Any

+ 1 - 1
toolset/benchmark/test_types/json_type.py

@@ -8,7 +8,7 @@ class JsonTestType(FrameworkTestType):
     def __init__(self):
         kwargs = {
             'name': 'json',
-            'accept_header': self.accept_json,
+            'accept_header': self.accept('json'),
             'requires_db': False,
             'args': ['json_url']
         }

+ 1 - 1
toolset/benchmark/test_types/plaintext_type.py

@@ -7,7 +7,7 @@ class PlaintextTestType(FrameworkTestType):
         kwargs = {
             'name': 'plaintext',
             'requires_db': False,
-            'accept_header': self.accept_plaintext,
+            'accept_header': self.accept('plaintext'),
             'args': ['plaintext_url']
         }
         FrameworkTestType.__init__(self, **kwargs)

+ 1 - 1
toolset/benchmark/test_types/query_type.py

@@ -15,7 +15,7 @@ class QueryTestType(DBTestType):
     def __init__(self):
         kwargs = {
             'name': 'query',
-            'accept_header': self.accept_json,
+            'accept_header': self.accept('json'),
             'requires_db': True,
             'args': ['query_url']
         }

+ 1 - 1
toolset/benchmark/test_types/update_type.py

@@ -9,7 +9,7 @@ class UpdateTestType(QueryTestType):
     def __init__(self):
         kwargs = {
             'name': 'update',
-            'accept_header': self.accept_json,
+            'accept_header': self.accept('json'),
             'requires_db': True,
             'args': ['update_url']
         }