Source

CherryPy / cherrypy / test / webtest.py

Diff from to

File cherrypy/test/webtest.py

 be of further significance to your tests).
 """
 
-import os
 import pprint
 import re
 import socket
 from cherrypy._cpcompat import basestring, ntob, py3k, HTTPConnection, HTTPSConnection, unicodestr
 
 
-
 def interface(host):
     """Return an IP address for a client connection given the server host.
 
     status = None
     headers = None
     body = None
-    
+
     encoding = 'utf-8'
-    
+
     time = None
 
     def get_conn(self, auto_open=False):
     def getPage(self, url, headers=None, method="GET", body=None, protocol=None):
         """Open the url with debugging support. Return status, headers, body."""
         ServerError.on = False
-        
+
         if isinstance(url, unicodestr):
             url = url.encode('utf-8')
         if isinstance(body, unicodestr):
             body = body.encode('utf-8')
-        
+
         self.url = url
         self.time = None
         start = time.time()
                 msg = '%r:%r not in headers' % (key, value)
         self._handlewebError(msg)
 
+    def assertHeaderIn(self, key, values, msg=None):
+        """Fail if header indicated by key doesn't have one of the values."""
+        lowkey = key.lower()
+        for k, v in self.headers:
+            if k.lower() == lowkey:
+                matches = [value for value in values if str(value) == v]
+                if matches:
+                    return matches
+
+        if msg is None:
+            msg = '%(key)r not in %(values)r' % vars()
+        self._handlewebError(msg)
+
     def assertHeaderItemValue(self, key, value, msg=None):
         """Fail if the header does not contain the specified value"""
         actual_value = self.assertHeader(key, msg=msg)
                 def putrequest(self, method, url):
                     if self._HTTPConnection__response and self._HTTPConnection__response.isclosed():
                         self._HTTPConnection__response = None
-                    
+
                     if self._HTTPConnection__state == http.client._CS_IDLE:
                         self._HTTPConnection__state = http.client._CS_REQ_STARTED
                     else:
                         raise http.client.CannotSendRequest()
-                    
+
                     self._method = method
                     if not url:
-                        url = b'/'
-                    request = b' '.join((method.encode("ASCII"), url,
-                                         self._http_vsn_str.encode("ASCII")))
+                        url = ntob('/')
+                    request = ntob(' ').join((method.encode("ASCII"), url,
+                                              self._http_vsn_str.encode("ASCII")))
                     self._output(request)
                 import types
                 conn.putrequest = types.MethodType(putrequest, conn)
-                
+
                 conn.putrequest(method.upper(), url)
 
             for key, value in headers:
         print("")
         print("".join(traceback.format_exception(*exc)))
         return True
-