Back to index

python3.2  3.2.2
Classes | Public Member Functions | Public Attributes
test.test_httpservers.SimpleHTTPServerTestCase Class Reference
Inheritance diagram for test.test_httpservers.SimpleHTTPServerTestCase:
Inheritance graph
[legend]
Collaboration diagram for test.test_httpservers.SimpleHTTPServerTestCase:
Collaboration graph
[legend]

List of all members.

Classes

class  request_handler

Public Member Functions

def setUp
def tearDown
def check_status_and_reason
def test_get
def test_head
def test_invalid_requests
def request

Public Attributes

 cwd
 data
 tempdir
 tempdir_name
 server_started
 thread
 connection

Detailed Description

Definition at line 214 of file test_httpservers.py.


Member Function Documentation

def test.test_httpservers.SimpleHTTPServerTestCase.check_status_and_reason (   self,
  response,
  status,
  data = None 
)

Definition at line 239 of file test_httpservers.py.

00239 
00240     def check_status_and_reason(self, response, status, data=None):
00241         body = response.read()
00242         self.assertTrue(response)
00243         self.assertEqual(response.status, status)
00244         self.assertIsNotNone(response.reason)
00245         if data:
00246             self.assertEqual(data, body)

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_httpservers.BaseTestCase.request (   self,
  uri,
  method = 'GET',
  body = None,
  headers = {} 
) [inherited]

Definition at line 68 of file test_httpservers.py.

00068 
00069     def request(self, uri, method='GET', body=None, headers={}):
00070         self.connection = http.client.HTTPConnection(self.HOST, self.PORT)
00071         self.connection.request(method, uri, body, headers)
00072         return self.connection.getresponse()
00073 

Here is the caller graph for this function:

Reimplemented from test.test_httpservers.BaseTestCase.

Definition at line 218 of file test_httpservers.py.

00218 
00219     def setUp(self):
00220         BaseTestCase.setUp(self)
00221         self.cwd = os.getcwd()
00222         basetempdir = tempfile.gettempdir()
00223         os.chdir(basetempdir)
00224         self.data = b'We are the knights who say Ni!'
00225         self.tempdir = tempfile.mkdtemp(dir=basetempdir)
00226         self.tempdir_name = os.path.basename(self.tempdir)
00227         with open(os.path.join(self.tempdir, 'test'), 'wb') as temp:
00228             temp.write(self.data)

Here is the caller graph for this function:

Reimplemented from test.test_httpservers.BaseTestCase.

Definition at line 229 of file test_httpservers.py.

00229 
00230     def tearDown(self):
00231         try:
00232             os.chdir(self.cwd)
00233             try:
00234                 shutil.rmtree(self.tempdir)
00235             except:
00236                 pass
00237         finally:
00238             BaseTestCase.tearDown(self)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 247 of file test_httpservers.py.

00247 
00248     def test_get(self):
00249         #constructs the path relative to the root directory of the HTTPServer
00250         response = self.request(self.tempdir_name + '/test')
00251         self.check_status_and_reason(response, 200, data=self.data)
00252         response = self.request(self.tempdir_name + '/')
00253         self.check_status_and_reason(response, 200)
00254         response = self.request(self.tempdir_name)
00255         self.check_status_and_reason(response, 301)
00256         response = self.request('/ThisDoesNotExist')
00257         self.check_status_and_reason(response, 404)
00258         response = self.request('/' + 'ThisDoesNotExist' + '/')
00259         self.check_status_and_reason(response, 404)
00260         with open(os.path.join(self.tempdir_name, 'index.html'), 'w') as f:
00261             response = self.request('/' + self.tempdir_name + '/')
00262             self.check_status_and_reason(response, 200)
00263             if os.name == 'posix':
00264                 # chmod won't work as expected on Windows platforms
00265                 os.chmod(self.tempdir, 0)
00266                 response = self.request(self.tempdir_name + '/')
00267                 self.check_status_and_reason(response, 404)
00268                 os.chmod(self.tempdir, 0o755)

Here is the call graph for this function:

Definition at line 269 of file test_httpservers.py.

00269 
00270     def test_head(self):
00271         response = self.request(
00272             self.tempdir_name + '/test', method='HEAD')
00273         self.check_status_and_reason(response, 200)
00274         self.assertEqual(response.getheader('content-length'),
00275                          str(len(self.data)))
00276         self.assertEqual(response.getheader('content-type'),
00277                          'application/octet-stream')

Here is the call graph for this function:

Definition at line 278 of file test_httpservers.py.

00278 
00279     def test_invalid_requests(self):
00280         response = self.request('/', method='FOO')
00281         self.check_status_and_reason(response, 501)
00282         # requests must be case sensitive,so this should fail too
00283         response = self.request('/', method='get')
00284         self.check_status_and_reason(response, 501)
00285         response = self.request('/', method='GETs')
00286         self.check_status_and_reason(response, 501)
00287 

Here is the call graph for this function:


Member Data Documentation

Definition at line 69 of file test_httpservers.py.

Definition at line 220 of file test_httpservers.py.

Definition at line 223 of file test_httpservers.py.

Definition at line 58 of file test_httpservers.py.

Definition at line 224 of file test_httpservers.py.

Definition at line 225 of file test_httpservers.py.

Definition at line 59 of file test_httpservers.py.


The documentation for this class was generated from the following file: