test_http.py
Go to the documentation of this file.
00001 # -*- coding: utf-8 -*-
00002 from tests.compat import unittest
00003 from webob import Request
00004 from webtest.debugapp import debug_app
00005 from webtest import http
00006 
00007 
00008 class TestServer(unittest.TestCase):
00009 
00010     def setUp(self):
00011         self.s = http.StopableWSGIServer.create(debug_app)
00012 
00013     def test_server(self):
00014         s = self.s
00015         s.wait()
00016         self.assertEqual(200,
00017                          http.check_server(s.adj.host, s.adj.port,
00018                                            '/__application__'))
00019         self.assertEqual(200,
00020                          http.check_server(s.adj.host, s.adj.port,
00021                                            '/__file__?__file__=' + __file__))
00022         self.assertEqual(404,
00023                          http.check_server(s.adj.host, s.adj.port,
00024                                            '/__file__?__file__=XXX'))
00025 
00026         self.assertEqual(304,
00027                          http.check_server(s.adj.host, s.adj.port,
00028                                            '/?status=304'))
00029 
00030     def test_wsgi_wrapper(self):
00031         s = self.s
00032         s.wait()
00033         req = Request.blank('/__application__')
00034         resp = req.get_response(s.wrapper)
00035         self.assertEqual(resp.status_int, 200)
00036 
00037         req = Request.blank('/__file__?__file__=' + __file__)
00038         resp = req.get_response(s.wrapper)
00039         self.assertEqual(resp.status_int, 200)
00040 
00041         req = Request.blank('/__file__?__file__=XXX')
00042         resp = req.get_response(s.wrapper)
00043         self.assertEqual(resp.status_int, 404)
00044 
00045         req = Request.blank('/?status=304')
00046         resp = req.get_response(s.wrapper)
00047         self.assertEqual(resp.status_int, 304)
00048 
00049     def tearDown(self):
00050         self.s.shutdown()
00051 
00052 
00053 class TestBrokenServer(unittest.TestCase):
00054 
00055     def test_shutdown_non_running(self):
00056         host, port = http.get_free_port()
00057         s = http.StopableWSGIServer(debug_app, host=host, port=port)
00058         self.assertFalse(s.wait(retries=-1))
00059         self.assertTrue(s.shutdown())
00060 
00061 
00062 class TestClient(unittest.TestCase):
00063 
00064     def test_no_server(self):
00065         host, port = http.get_free_port()
00066         self.assertEqual(0, http.check_server(host, port, retries=2))


webtest
Author(s): AlexV
autogenerated on Sat Mar 25 2017 03:32:05