Ejemplo n.º 1
0
 def test_authenticated_user(self):
     environ = complete_environ(SCRIPT_NAME="/dev", PATH_INFO="/trac/wiki")
     request = _make_request(authenticated=True, **environ)
     # Running the app:
     app = MockApp("200 OK", [])
     call_wsgi_app(app, request, "/wiki")
     self.assertEqual("foobar", app.environ['REMOTE_USER'])
Ejemplo n.º 2
0
 def test_authenticated_user(self):
     environ = complete_environ(SCRIPT_NAME="/dev", PATH_INFO="/trac/wiki")
     request = _make_request(authenticated=True, **environ)
     # Running the app:
     app = MockApp("200 OK", [])
     call_wsgi_app(app, request, "/wiki")
     eq_("foobar", app.environ['REMOTE_USER'])
Ejemplo n.º 3
0
 def test_mount_point(self):
     environ = complete_environ(SCRIPT_NAME="/dev", PATH_INFO="/trac/wiki")
     request = _make_request(**environ)
     # Running the app:
     app = MockApp("200 OK", [])
     call_wsgi_app(app, request, "/wiki")
     eq_(app.environ['SCRIPT_NAME'], "/dev/trac")
     eq_(app.environ['PATH_INFO'], "/wiki")
Ejemplo n.º 4
0
 def test_mount_point(self):
     environ = complete_environ(SCRIPT_NAME="/dev", PATH_INFO="/trac/wiki")
     request = _make_request(**environ)
     # Running the app:
     app = MockApp("200 OK", [])
     call_wsgi_app(app, request, "/wiki")
     self.assertEqual(app.environ['SCRIPT_NAME'], "/dev/trac")
     self.assertEqual(app.environ['PATH_INFO'], "/wiki")
Ejemplo n.º 5
0
 def test_routing_args_are_removed(self):
     """The ``wsgiorg.routing_args`` environment key must be removed."""
     environ = {
         'wsgiorg.routing_args': ((), {}),
         'PATH_INFO': "/admin/models",
         }
     environ = complete_environ(**environ)
     request = _make_request(**environ)
     # Running the app:
     app = MockApp("200 OK", [])
     call_wsgi_app(app, request, "/models")
     ok_("wsgiorg.routing_args" not in app.environ)
Ejemplo n.º 6
0
 def test_routing_args_are_removed(self):
     """The ``wsgiorg.routing_args`` environment key must be removed."""
     environ = {
         'wsgiorg.routing_args': ((), {}),
         'PATH_INFO': "/admin/models",
         }
     environ = complete_environ(**environ)
     request = _make_request(**environ)
     # Running the app:
     app = MockApp("200 OK", [])
     call_wsgi_app(app, request, "/models")
     self.assertNotIn("wsgiorg.routing_args", app.environ)
Ejemplo n.º 7
0
 def test_original_environ_not_modified(self):
     """The original environ must have not been modified."""
     original_environ = complete_environ(SCRIPT_NAME="/blog",
                                         PATH_INFO="/admin/models")
     request = _make_request(**original_environ)
     expected_environ = original_environ.copy()
     # Running the app:
     app = MockApp("200 OK", [])
     call_wsgi_app(app, request, "/models")
     # Checking the environment after calling the WSGI application, but first
     # let's remove WebOb's ad-hoc attributes:
     del request.environ['webob.adhoc_attrs']
     eq_(request.environ, expected_environ)
Ejemplo n.º 8
0
 def test_webob_adhoc_attrs_are_removed(self):
     """WebOb's ad-hoc attributes must be removed."""
     environ = {
         'PATH_INFO': "/admin/models",
         'wsgiorg.routing_args': ((), {}),
         'webob.adhoc_attrs': {'foo': "bar"},
         }
     environ = complete_environ(**environ)
     request = _make_request(**environ)
     # Running the app:
     app = MockApp("200 OK", [])
     call_wsgi_app(app, request, "/models")
     ok_("webob.adhoc_attrs" not in app.environ)
Ejemplo n.º 9
0
 def test_http_status(self):
     environ = complete_environ(SCRIPT_NAME="/dev", PATH_INFO="/trac/wiki")
     request = _make_request(**environ)
     # Running the app and make a valid request:
     app_ok = MockApp("200 Alright", [])
     django_response_ok = call_wsgi_app(app_ok, request, "/wiki")
     eq_(200, django_response_ok.status_code)
     eq_("Alright", django_response_ok.status_reason)
     # Running the app and make an invalid request:
     app_bad = MockApp("403 What are you trying to do?", [])
     django_response_bad = call_wsgi_app(app_bad, request, "/wiki")
     eq_(403, django_response_bad.status_code)
     eq_("What are you trying to do?", django_response_bad.status_reason)
Ejemplo n.º 10
0
 def test_webob_adhoc_attrs_are_removed(self):
     """WebOb's ad-hoc attributes must be removed."""
     environ = {
         'PATH_INFO': "/admin/models",
         'wsgiorg.routing_args': ((), {}),
         'webob.adhoc_attrs': {'foo': "bar"},
         }
     environ = complete_environ(**environ)
     request = _make_request(**environ)
     # Running the app:
     app = MockApp("200 OK", [])
     call_wsgi_app(app, request, "/models")
     self.assertNotIn("webob.adhoc_attrs", app.environ)
Ejemplo n.º 11
0
 def test_original_environ_not_modified(self):
     """The original environ must have not been modified."""
     original_environ = complete_environ(SCRIPT_NAME="/blog",
                                         PATH_INFO="/admin/models")
     request = _make_request(**original_environ)
     expected_environ = original_environ.copy()
     # Running the app:
     app = MockApp("200 OK", [])
     call_wsgi_app(app, request, "/models")
     # Checking the environment after calling the WSGI application, but first
     # let's remove WebOb's ad-hoc attributes:
     del request.environ['webob.adhoc_attrs']
     self.assertEqual(request.environ, expected_environ)
Ejemplo n.º 12
0
 def test_http_status(self):
     environ = complete_environ(SCRIPT_NAME="/dev", PATH_INFO="/trac/wiki")
     request = _make_request(**environ)
     # Running the app and make a valid request:
     app_ok = MockApp("200 Alright", [])
     django_response_ok = call_wsgi_app(app_ok, request, "/wiki")
     self.assertEqual(200, django_response_ok.status_code)
     self.assertEqual("Alright", django_response_ok.status_reason)
     # Running the app and make an invalid request:
     app_bad = MockApp("403 What are you trying to do?", [])
     django_response_bad = call_wsgi_app(app_bad, request, "/wiki")
     self.assertEqual(403, django_response_bad.status_code)
     self.assertEqual("What are you trying to do?", django_response_bad.status_reason)
Ejemplo n.º 13
0
 def test_closure_response(self):
     """The .close() method in the response (if any) must be kept."""
     app = MockClosingApp("200 It is OK", [])
     # Running a request:
     environ = complete_environ(SCRIPT_NAME="/dev", PATH_INFO="/blog/posts")
     request = _make_request(**environ)
     django_response = call_wsgi_app(app, request, "/posts")
     # Checking the .close() call:
     self.assertFalse(app.app_iter.closed)
     django_response.close()
     self.assertTrue(app.app_iter.closed)
Ejemplo n.º 14
0
 def test_closure_response(self):
     """The .close() method in the response (if any) must be kept."""
     app = MockClosingApp("200 It is OK", [])
     # Running a request:
     environ = complete_environ(SCRIPT_NAME="/dev", PATH_INFO="/blog/posts")
     request = _make_request(**environ)
     django_response = call_wsgi_app(app, request, "/posts")
     # Checking the .close() call:
     assert_false(app.app_iter.closed)
     django_response.close()
     ok_(app.app_iter.closed)
Ejemplo n.º 15
0
 def test_cookies_sent(self):
     environ = complete_environ(SCRIPT_NAME="/dev", PATH_INFO="/trac/wiki")
     request = _make_request(**environ)
     headers = [
         ("Set-Cookie", "arg1=val1"),
         ("Set-Cookie", "arg2=val2; expires=Fri,%2031-Dec-2010%2023:59:59%20GMT"),
         ("Set-Cookie", "arg3=val3; path=/"),
         ("Set-Cookie", "arg4=val4; path=/wiki"),
         ("Set-Cookie", "arg5=val5; domain=.example.org"),
         ("Set-Cookie", "arg6=val6; max-age=3600"),
         ("Set-Cookie", "arg7=val7; expires=Fri,%2031-Dec-2010%2023:59:59%20GMT; max-age=3600; domain=.example.org; path=/wiki"),
         # Now let's try an Unicode cookie:
         ("Set-Cookie", u"arg8=val8; max-age=3600"),
         # TODO: The "secure" cookie *attribute* is broken in SimpleCookie.
         # See: http://bugs.python.org/issue1028088
         #("Set-Cookie", "arg9=val9; secure"),
         ]
     expected_cookies = {
         'arg1': {'value': "val1"},
         'arg2': {'value': "val2", 'expires': "Fri,%2031-Dec-2010%2023:59:59%20GMT"},
         'arg3': {'value': "val3", 'path': "/"},
         'arg4': {'value': "val4", 'path': "/wiki"},
         'arg5': {'value': "val5", 'domain': ".example.org"},
         'arg6': {'value': "val6", 'max-age': "3600"},
         'arg7': {
             'value': "val7",
             'expires': "Fri,%2031-Dec-2010%2023:59:59%20GMT",
             'path': "/wiki",
             'domain': ".example.org",
             'max-age': "3600",
             },
         'arg8': {'value': "val8", 'max-age': "3600"},
         # Why the next item as disabled? Check the `headers` variable above
         #'arg9': {'value': "val9", 'secure': True},
         }
     # Running the app:
     app = MockApp("200 OK", headers)
     django_response = call_wsgi_app(app, request, "/wiki")
     # Checking the cookies:
     eq_(len(expected_cookies), len(django_response.cookies))
     # Finally, let's check each cookie:
     for (cookie_set_name, cookie_set) in django_response.cookies.items():
         expected_cookie = expected_cookies[cookie_set_name]
         expected_cookie_value = expected_cookie.pop("value")
         eq_(expected_cookie_value, cookie_set.value,
                          'Cookie "%s" has a wrong value ("%s")' %
                          (cookie_set_name, cookie_set.value))
         for (attr_key, attr_val) in expected_cookie.items():
             eq_(cookie_set[attr_key], attr_val,
                              'Attribute "%s" in cookie "%s" is wrong (%s)' %
                              (attr_key, cookie_set_name, cookie_set[attr_key]))
Ejemplo n.º 16
0
 def test_cookies_sent(self):
     environ = complete_environ(SCRIPT_NAME="/dev", PATH_INFO="/trac/wiki")
     request = _make_request(**environ)
     headers = [
         ("Set-Cookie", "arg1=val1"),
         ("Set-Cookie", "arg2=val2; expires=Fri,%2031-Dec-2010%2023:59:59%20GMT"),
         ("Set-Cookie", "arg3=val3; path=/"),
         ("Set-Cookie", "arg4=val4; path=/wiki"),
         ("Set-Cookie", "arg5=val5; domain=.example.org"),
         ("Set-Cookie", "arg6=val6; max-age=3600"),
         ("Set-Cookie", "arg7=val7; expires=Fri,%2031-Dec-2010%2023:59:59%20GMT; max-age=3600; domain=.example.org; path=/wiki"),
         # Now let's try an Unicode cookie:
         ("Set-Cookie", u"arg8=val8; max-age=3600"),
         # TODO: The "secure" cookie *attribute* is broken in SimpleCookie.
         # See: http://bugs.python.org/issue1028088
         #("Set-Cookie", "arg9=val9; secure"),
         ]
     expected_cookies = {
         'arg1': {'value': "val1"},
         'arg2': {'value': "val2", 'expires': "Fri,%2031-Dec-2010%2023:59:59%20GMT"},
         'arg3': {'value': "val3", 'path': "/"},
         'arg4': {'value': "val4", 'path': "/wiki"},
         'arg5': {'value': "val5", 'domain': ".example.org"},
         'arg6': {'value': "val6", 'max-age': "3600"},
         'arg7': {
             'value': "val7",
             'expires': "Fri,%2031-Dec-2010%2023:59:59%20GMT",
             'path': "/wiki",
             'domain': ".example.org",
             'max-age': "3600",
             },
         'arg8': {'value': "val8", 'max-age': "3600"},
         # Why the next item as disabled? Check the `headers` variable above
         #'arg9': {'value': "val9", 'secure': True},
         }
     # Running the app:
     app = MockApp("200 OK", headers)
     django_response = call_wsgi_app(app, request, "/wiki")
     # Checking the cookies:
     self.assertEqual(len(expected_cookies), len(django_response.cookies))
     # Finally, let's check each cookie:
     for (cookie_set_name, cookie_set) in django_response.cookies.items():
         expected_cookie = expected_cookies[cookie_set_name]
         expected_cookie_value = expected_cookie.pop("value")
         self.assertEqual(expected_cookie_value, cookie_set.value,
                          'Cookie "%s" has a wrong value ("%s")' %
                          (cookie_set_name, cookie_set.value))
         for (attr_key, attr_val) in expected_cookie.items():
             self.assertEqual(cookie_set[attr_key], attr_val,
                              'Attribute "%s" in cookie "%s" is wrong (%s)' %
                              (attr_key, cookie_set_name, cookie_set[attr_key]))
Ejemplo n.º 17
0
 def test_string_as_response(self):
     app = MockApp("200 It is OK", [("X-HEADER", "Foo")])
     # Running a request:
     environ = complete_environ(SCRIPT_NAME="/dev", PATH_INFO="/blog/posts")
     request = _make_request(**environ)
     django_response = call_wsgi_app(app, request, "/posts")
     # Checking the response:
     http_response = (
         "X-HEADER: Foo\n"
         "Content-Type: text/html; charset=utf-8\n"
         "X-Actual-Status-Reason: 200 It is OK\n"
         "\n"
         "body"
         )
     self.assertEqual(http_response, str(django_response))
Ejemplo n.º 18
0
 def test_string_as_response(self):
     app = MockApp("200 It is OK", [("X-HEADER", "Foo")])
     # Running a request:
     environ = complete_environ(SCRIPT_NAME="/dev", PATH_INFO="/blog/posts")
     request = _make_request(**environ)
     django_response = call_wsgi_app(app, request, "/posts")
     # Checking the response:
     http_response = (
         "X-HEADER: Foo\n"
         "Content-Type: text/html; charset=utf-8\n"
         "X-Actual-Status-Reason: 200 It is OK\n"
         "\n"
         "body"
         )
     eq_(http_response, str(django_response))
Ejemplo n.º 19
0
 def test_write_response(self):
     app = MockWriteApp("200 It is OK", [("X-HEADER", "Foo")])
     # Running a request:
     environ = complete_environ(SCRIPT_NAME="/dev", PATH_INFO="/blog/posts")
     request = _make_request(**environ)
     django_response = call_wsgi_app(app, request, "/posts")
     # Checking the response:
     assert_false(django_response._is_string)
     ok_(django_response.has_header("X-HEADER"))
     http_response = (
         "X-HEADER: Foo\n"
         "Content-Type: text/html; charset=utf-8\n"
         "X-Actual-Status-Reason: 200 It is OK\n"
         "\n"
         "body as iterable"
         )
     eq_(http_response, str(django_response))
Ejemplo n.º 20
0
 def test_headers_are_copied_over(self):
     environ = complete_environ(SCRIPT_NAME="/dev", PATH_INFO="/trac/wiki")
     request = _make_request(**environ)
     headers = [
         ("X-Foo", "bar"),
         ("Content-Type", "text/plain"),
         ]
     # The same headers, but set in the format used by HttpResponse
     expected_headers = {
         'x-foo': ("X-Foo", "bar"),
         'content-type': ("Content-Type", "text/plain"),
         'x-actual-status-reason': ("X-Actual-Status-Reason", "200 OK"),
         }
     # Running the app:
     app = MockApp("200 OK", headers)
     django_response = call_wsgi_app(app, request, "/wiki")
     eq_(expected_headers, django_response._headers)
Ejemplo n.º 21
0
 def test_headers_are_copied_over(self):
     environ = complete_environ(SCRIPT_NAME="/dev", PATH_INFO="/trac/wiki")
     request = _make_request(**environ)
     headers = [
         ("X-Foo", "bar"),
         ("Content-Type", "text/plain"),
         ]
     # The same headers, but set in the format used by HttpResponse
     expected_headers = {
         'x-foo': ("X-Foo", "bar"),
         'content-type': ("Content-Type", "text/plain"),
         'x-actual-status-reason': ("X-Actual-Status-Reason", "200 OK"),
         }
     # Running the app:
     app = MockApp("200 OK", headers)
     django_response = call_wsgi_app(app, request, "/wiki")
     self.assertEqual(expected_headers, django_response._headers)
Ejemplo n.º 22
0
def tileserver(request, path_info):
    return call_wsgi_app(tilestache, request, path_info)