Merge pull request #3396 from mmerickel/fix-dummy-request-accept
fix the dummy request to support the new accept apis
| | |
| | | unreleased |
| | | ========== |
| | | |
| | | Bug Fixes |
| | | --------- |
| | | |
| | | - Fix the ``pyramid.testing.DummyRequest`` to support the new |
| | | ``request.accept`` API so that ``acceptable_offers`` is available even |
| | | when code sets the value to a string. |
| | | See https://github.com/Pylons/pyramid/pull/3396 |
| | | |
| | | 1.10a1 (2018-10-15) |
| | | =================== |
| | | |
| | |
| | | Backward Incompatibilities |
| | | -------------------------- |
| | | |
| | | - On Python 3.4+ the ``repoze.lru`` dependency is dropped. If you were using this package directly in your apps you should make sure that you are depending on it directly within your project. |
| | | - Removed ``pyramid.config.Configurator.set_request_property`` which had been deprecated since :app:`Pyramid` 1.5. |
| | | Instead use :meth:`pyramid.config.Configurator.add_request_method` with ``reify=True`` or ``property=True``. |
| | | See https://github.com/Pylons/pyramid/pull/3368 |
| | | |
| | | - On Python 3.4+ the ``repoze.lru`` dependency is dropped. |
| | | If you were using this package directly in your apps you should make sure that you are depending on it directly within your project. |
| | | See https://github.com/Pylons/pyramid/pull/3140 |
| | | |
| | | - Remove the ``permission`` argument from :meth:`pyramid.config.Configurator.add_route`. |
| | | This was an argument left over from a feature removed in :app:`Pyramid` 1.5 and has had no effect since then. |
| | | See https://github.com/Pylons/pyramid/pull/3299 |
| | | |
| | | - Modify the builtin session implementations to set ``SameSite='Lax'`` on cookies. |
| | | - Modified the builtin session implementations to set ``SameSite='Lax'`` on cookies. |
| | | This affects :func:`pyramid.session.BaseCookieSessionFactory`, :func:`pyramid.session.SignedCookieSessionFactory`, and :func:`pyramid.session.UnencryptedCookieSessionFactoryConfig`. |
| | | See https://github.com/Pylons/pyramid/pull/3300 |
| | | |
| | |
| | | |
| | | - :meth:`pyramid.config.Configurator.add_notfound_view` uses default redirect class exception :class:`pyramid.httpexceptions.HTTPTemporaryRedirect` instead of previous :class:`pyramid.httpexceptions.HTTPFound`. |
| | | See https://github.com/Pylons/pyramid/pull/3328 |
| | | |
| | | - Removed ``pyramid.config.Configurator.set_request_property`` which had been deprecated since :app:`Pyramid` 1.5. |
| | | Instead use :meth:`pyramid.config.Configurator.add_request_method` with ``reify=True`` or ``property=True``. |
| | | See https://github.com/Pylons/pyramid/pull/3368 |
| | | |
| | | - Removed the ``principal`` keyword argument from :func:`pyramid.security.remember` which had been deprecated since :app:`Pyramid` 1.6 and replaced by the ``userid`` argument. |
| | | See https://github.com/Pylons/pyramid/pull/3369 |
| | |
| | | import os |
| | | from contextlib import contextmanager |
| | | |
| | | from webob.acceptparse import create_accept_header |
| | | |
| | | from zope.interface import implementer, alsoProvides |
| | | |
| | | from pyramid.interfaces import IRequest, ISession |
| | |
| | | charset = 'UTF-8' |
| | | script_name = '' |
| | | _registry = None |
| | | _accept = None |
| | | request_iface = IRequest |
| | | |
| | | def __init__( |
| | |
| | | path='/', |
| | | cookies=None, |
| | | post=None, |
| | | accept=None, |
| | | **kw |
| | | ): |
| | | if environ is None: |
| | |
| | | self.virtual_root = None |
| | | self.marshalled = params # repoze.monty |
| | | self.session = DummySession() |
| | | self.accept = accept |
| | | self.__dict__.update(kw) |
| | | |
| | | def _get_registry(self): |
| | |
| | | |
| | | registry = property(_get_registry, _set_registry, _del_registry) |
| | | |
| | | def _set_accept(self, value): |
| | | self._accept = create_accept_header(value) |
| | | |
| | | def _get_accept(self): |
| | | if self._accept is None: |
| | | self._accept = create_accept_header(None) |
| | | return self._accept |
| | | |
| | | def _del_accept(self): |
| | | self._accept = None |
| | | |
| | | accept = property(_get_accept, _set_accept, _del_accept) |
| | | |
| | | @reify |
| | | def response(self): |
| | | f = _get_response_factory(self.registry) |
| | |
| | | self.assertEqual(resp.__class__, Response) |
| | | self.assertTrue(request.response is resp) # reified |
| | | |
| | | def test_default_accept(self): |
| | | request = self._makeOne() |
| | | self.assertEqual( |
| | | request.accept.acceptable_offers(['text/html']), |
| | | [('text/html', 1.0)], |
| | | ) |
| | | |
| | | request.accept = 'text/plain' |
| | | self.assertEqual(request.accept.acceptable_offers(['text/html']), []) |
| | | |
| | | del request.accept |
| | | self.assertEqual( |
| | | request.accept.acceptable_offers(['text/html']), |
| | | [('text/html', 1.0)], |
| | | ) |
| | | |
| | | def test_accept__init__(self): |
| | | request = self._makeOne(accept='text/plain') |
| | | self.assertEqual( |
| | | request.accept.acceptable_offers(['text/html', 'text/plain']), |
| | | [('text/plain', 1.0)], |
| | | ) |
| | | |
| | | |
| | | class TestDummyTemplateRenderer(unittest.TestCase): |
| | | def _getTargetClass(self,): |