summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Merickel <michael@merickel.org>2018-10-17 20:41:02 -0500
committerMichael Merickel <michael@merickel.org>2018-10-17 20:45:01 -0500
commitd3fe14781747539c470089208fa7aeb1b2cbbd6f (patch)
tree7bdd86bbe7b2526805b1aa11a485f00159be8cb9
parent66a767f0e1911543b77a4dd768821ee2ed40390a (diff)
downloadpyramid-d3fe14781747539c470089208fa7aeb1b2cbbd6f.tar.gz
pyramid-d3fe14781747539c470089208fa7aeb1b2cbbd6f.tar.bz2
pyramid-d3fe14781747539c470089208fa7aeb1b2cbbd6f.zip
fix the dummy request to support the new accept apis
-rw-r--r--CHANGES.rst11
-rw-r--r--docs/whatsnew-1.10.rst13
-rw-r--r--src/pyramid/testing.py18
-rw-r--r--tests/test_testing.py23
4 files changed, 59 insertions, 6 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index cc70dca8e..d04e84174 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -1,3 +1,14 @@
+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)
===================
diff --git a/docs/whatsnew-1.10.rst b/docs/whatsnew-1.10.rst
index b14771c9d..53eed6f87 100644
--- a/docs/whatsnew-1.10.rst
+++ b/docs/whatsnew-1.10.rst
@@ -87,14 +87,19 @@ Deprecations
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
@@ -104,10 +109,6 @@ Backward Incompatibilities
- :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
diff --git a/src/pyramid/testing.py b/src/pyramid/testing.py
index e2549f0b9..ea86f5852 100644
--- a/src/pyramid/testing.py
+++ b/src/pyramid/testing.py
@@ -2,6 +2,8 @@ import copy
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
@@ -340,6 +342,7 @@ class DummyRequest(
charset = 'UTF-8'
script_name = ''
_registry = None
+ _accept = None
request_iface = IRequest
def __init__(
@@ -350,6 +353,7 @@ class DummyRequest(
path='/',
cookies=None,
post=None,
+ accept=None,
**kw
):
if environ is None:
@@ -388,6 +392,7 @@ class DummyRequest(
self.virtual_root = None
self.marshalled = params # repoze.monty
self.session = DummySession()
+ self.accept = accept
self.__dict__.update(kw)
def _get_registry(self):
@@ -403,6 +408,19 @@ class DummyRequest(
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)
diff --git a/tests/test_testing.py b/tests/test_testing.py
index 90e30c94f..16c94ee19 100644
--- a/tests/test_testing.py
+++ b/tests/test_testing.py
@@ -303,6 +303,29 @@ class TestDummyRequest(unittest.TestCase):
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,):