diff options
author | Florian Apolloner <florian@apolloner.eu> | 2013-02-26 09:53:47 +0100 |
---|---|---|
committer | Florian Apolloner <florian@apolloner.eu> | 2013-02-26 14:36:57 +0100 |
commit | 89f40e36246100df6a11316c31a76712ebc6c501 (patch) | |
tree | 6e65639683ddaf2027908d1ecb1739e0e2ff853b /tests/wsgi | |
parent | b3d2ccb5bfbaf6e7fe1f98843baaa48c35a70950 (diff) | |
download | django-89f40e36246100df6a11316c31a76712ebc6c501.tar.gz |
Merged regressiontests and modeltests into the test root.
Diffstat (limited to 'tests/wsgi')
-rw-r--r-- | tests/wsgi/__init__.py | 0 | ||||
-rw-r--r-- | tests/wsgi/models.py | 0 | ||||
-rw-r--r-- | tests/wsgi/tests.py | 99 | ||||
-rw-r--r-- | tests/wsgi/urls.py | 10 | ||||
-rw-r--r-- | tests/wsgi/wsgi.py | 2 |
5 files changed, 111 insertions, 0 deletions
diff --git a/tests/wsgi/__init__.py b/tests/wsgi/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/wsgi/__init__.py diff --git a/tests/wsgi/models.py b/tests/wsgi/models.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/wsgi/models.py diff --git a/tests/wsgi/tests.py b/tests/wsgi/tests.py new file mode 100644 index 0000000000..0b8c9d2b67 --- /dev/null +++ b/tests/wsgi/tests.py @@ -0,0 +1,99 @@ +from __future__ import unicode_literals + +from django.core.exceptions import ImproperlyConfigured +from django.core.servers.basehttp import get_internal_wsgi_application +from django.core.wsgi import get_wsgi_application +from django.test import TestCase +from django.test.client import RequestFactory +from django.test.utils import override_settings +from django.utils import six, unittest + + +class WSGITest(TestCase): + urls = "regressiontests.wsgi.urls" + + def test_get_wsgi_application(self): + """ + Verify that ``get_wsgi_application`` returns a functioning WSGI + callable. + + """ + application = get_wsgi_application() + + environ = RequestFactory()._base_environ( + PATH_INFO="/", + CONTENT_TYPE="text/html; charset=utf-8", + REQUEST_METHOD="GET" + ) + + response_data = {} + + def start_response(status, headers): + response_data["status"] = status + response_data["headers"] = headers + + response = application(environ, start_response) + + self.assertEqual(response_data["status"], "200 OK") + self.assertEqual( + response_data["headers"], + [('Content-Type', 'text/html; charset=utf-8')]) + self.assertEqual( + bytes(response), + b"Content-Type: text/html; charset=utf-8\r\n\r\nHello World!") + + +class GetInternalWSGIApplicationTest(unittest.TestCase): + @override_settings(WSGI_APPLICATION="regressiontests.wsgi.wsgi.application") + def test_success(self): + """ + If ``WSGI_APPLICATION`` is a dotted path, the referenced object is + returned. + + """ + app = get_internal_wsgi_application() + + from .wsgi import application + + self.assertTrue(app is application) + + + @override_settings(WSGI_APPLICATION=None) + def test_default(self): + """ + If ``WSGI_APPLICATION`` is ``None``, the return value of + ``get_wsgi_application`` is returned. + + """ + # Mock out get_wsgi_application so we know its return value is used + fake_app = object() + def mock_get_wsgi_app(): + return fake_app + from django.core.servers import basehttp + _orig_get_wsgi_app = basehttp.get_wsgi_application + basehttp.get_wsgi_application = mock_get_wsgi_app + + try: + app = get_internal_wsgi_application() + + self.assertTrue(app is fake_app) + finally: + basehttp.get_wsgi_application = _orig_get_wsgi_app + + + @override_settings(WSGI_APPLICATION="regressiontests.wsgi.noexist.app") + def test_bad_module(self): + with six.assertRaisesRegex(self, + ImproperlyConfigured, + r"^WSGI application 'regressiontests.wsgi.noexist.app' could not be loaded; Error importing.*"): + + get_internal_wsgi_application() + + + @override_settings(WSGI_APPLICATION="regressiontests.wsgi.wsgi.noexist") + def test_bad_name(self): + with six.assertRaisesRegex(self, + ImproperlyConfigured, + r"^WSGI application 'regressiontests.wsgi.wsgi.noexist' could not be loaded; Module.*"): + + get_internal_wsgi_application() diff --git a/tests/wsgi/urls.py b/tests/wsgi/urls.py new file mode 100644 index 0000000000..9639f0fd34 --- /dev/null +++ b/tests/wsgi/urls.py @@ -0,0 +1,10 @@ +from django.conf.urls import url, patterns +from django.http import HttpResponse + +def helloworld(request): + return HttpResponse("Hello World!") + +urlpatterns = patterns( + "", + url("^$", helloworld) + ) diff --git a/tests/wsgi/wsgi.py b/tests/wsgi/wsgi.py new file mode 100644 index 0000000000..400457f152 --- /dev/null +++ b/tests/wsgi/wsgi.py @@ -0,0 +1,2 @@ +# This is just to test finding, it doesn't have to be a real WSGI callable +application = object() |