[Python-modules-commits] [webtest] 01/05: Import webtest_2.0.28.orig.tar.gz
Piotr Ożarowski
piotr at moszumanska.debian.org
Fri Sep 29 11:00:00 UTC 2017
This is an automated email from the git hooks/post-receive script.
piotr pushed a commit to branch master
in repository webtest.
commit 17e96f699f343b182d9cc6870fdc3552e167ea25
Author: Piotr Ożarowski <piotr at debian.org>
Date: Fri Sep 29 12:52:16 2017 +0200
Import webtest_2.0.28.orig.tar.gz
---
CHANGELOG.rst | 15 ++++++++++
PKG-INFO | 3 +-
RELEASING.rst | 70 ++++++++++++++++++++++++++++++++++++++++++++
WebTest.egg-info/PKG-INFO | 3 +-
WebTest.egg-info/SOURCES.txt | 1 +
docs/changelog.rst | 15 ++++++++++
setup.py | 3 +-
tests/test_app.py | 33 +++++++++++++++++++++
tests/test_forms.py | 31 ++++++++++++++++++++
tests/test_lint.py | 34 +++++++++++++++++----
tests/test_response.py | 8 +++--
tox.ini | 6 ++--
webtest/app.py | 18 ++++++++----
webtest/lint.py | 47 +++++++++++++++--------------
webtest/utils.py | 2 +-
15 files changed, 245 insertions(+), 44 deletions(-)
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 73a53cb..7f095e2 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -1,6 +1,21 @@
News
====
+2.0.28 (2017-08-01)
+-------------------
+
+- Fixed #185: Fix strict cookie policy
+
+- Fixed #146: Improve fields value checking when enctype is multipart
+
+- Fixed #119: Assertion error should be raised when you have non-string
+ response header
+
+- Bugfix: Allow to set an int value to form fields when enctype is multipart
+
+- Added py36 to tox.ini / .travis.yaml
+
+
2.0.27 (2017-03-15)
-------------------
diff --git a/PKG-INFO b/PKG-INFO
index f11b688..044a0d0 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: WebTest
-Version: 2.0.27
+Version: 2.0.28
Summary: Helper to test WSGI applications
Home-page: http://webtest.pythonpaste.org/
Author: Gael Pasgrimaud
@@ -32,3 +32,4 @@ Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
+Classifier: Programming Language :: Python :: 3.6
diff --git a/RELEASING.rst b/RELEASING.rst
new file mode 100644
index 0000000..f9265f3
--- /dev/null
+++ b/RELEASING.rst
@@ -0,0 +1,70 @@
+Releasing WebTest
+=================
+
+- For clarity, we define releases as follows.
+
+ - Alpha, beta, dev and similar statuses do not qualify whether a release is
+ major or minor. The term "pre-release" means alpha, beta, or dev.
+
+ - A release is final when it is no longer pre-release.
+
+ - A *major* release is where the first number either before or after the
+ first dot increases. Examples: 1.6 to 1.7a1, or 1.8 to 2.0.
+
+ - A *minor* or *bug fix* release is where the number after the second dot
+ increases. Example: 1.6 to 1.6.1.
+
+
+Releasing with zest.releaser
+----------------------------
+
+- First install `zest.releaser <https://pypi.python.org/pypi/zest.releaser>`_::
+
+ $ pip install zest.releaser[recommanded]
+
+- Add this to your ``~/.pypirc``::
+
+ [zest.releaser]
+ no-input = true
+ create-wheel = yes
+
+- Edit ``CHANGELOG.rst``
+
+- Run the fullrelease script::
+
+ $ fullrelease
+
+Marketing and communications
+----------------------------
+
+- Announce to Twitter::
+
+ WebTest 1.x released.
+
+ PyPI
+ https://pypi.python.org/pypi/webtest/2.x
+
+ Changes
+ http://docs.pylonsproject.org/projects/webtest
+
+ Issues
+ https://github.com/Pylons/webtest/issues
+
+- Announce to maillist::
+
+ WebTest 2.X.X has been released.
+
+ Here are the changes:
+
+ <<changes>>
+
+ You can install it via PyPI:
+
+ pip install WebTest==2.X
+
+ Enjoy, and please report any issues you find to the issue tracker at
+ https://github.com/Pylons/webtest/issues
+
+ Thanks!
+
+ - WebTest developers
diff --git a/WebTest.egg-info/PKG-INFO b/WebTest.egg-info/PKG-INFO
index f11b688..044a0d0 100644
--- a/WebTest.egg-info/PKG-INFO
+++ b/WebTest.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: WebTest
-Version: 2.0.27
+Version: 2.0.28
Summary: Helper to test WSGI applications
Home-page: http://webtest.pythonpaste.org/
Author: Gael Pasgrimaud
@@ -32,3 +32,4 @@ Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
+Classifier: Programming Language :: Python :: 3.6
diff --git a/WebTest.egg-info/SOURCES.txt b/WebTest.egg-info/SOURCES.txt
index 0676724..a505f09 100644
--- a/WebTest.egg-info/SOURCES.txt
+++ b/WebTest.egg-info/SOURCES.txt
@@ -2,6 +2,7 @@
CHANGELOG.rst
MANIFEST.in
README.rst
+RELEASING.rst
setup.cfg
setup.py
tox.ini
diff --git a/docs/changelog.rst b/docs/changelog.rst
index 73a53cb..7f095e2 100644
--- a/docs/changelog.rst
+++ b/docs/changelog.rst
@@ -1,6 +1,21 @@
News
====
+2.0.28 (2017-08-01)
+-------------------
+
+- Fixed #185: Fix strict cookie policy
+
+- Fixed #146: Improve fields value checking when enctype is multipart
+
+- Fixed #119: Assertion error should be raised when you have non-string
+ response header
+
+- Bugfix: Allow to set an int value to form fields when enctype is multipart
+
+- Added py36 to tox.ini / .travis.yaml
+
+
2.0.27 (2017-03-15)
-------------------
diff --git a/setup.py b/setup.py
index cd0eebf..7f1a064 100644
--- a/setup.py
+++ b/setup.py
@@ -5,7 +5,7 @@ import sys
from setuptools import setup
from setuptools import find_packages
-version = '2.0.27'
+version = '2.0.28'
install_requires = [
'six',
@@ -37,6 +37,7 @@ setup(name='WebTest',
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
+ "Programming Language :: Python :: 3.6",
],
keywords='wsgi test unit tests web',
author='Ian Bicking',
diff --git a/tests/test_app.py b/tests/test_app.py
index ed442b7..0c611fb 100644
--- a/tests/test_app.py
+++ b/tests/test_app.py
@@ -357,6 +357,39 @@ class TestCookies(unittest.TestCase):
self.assertEqual(res.request.environ['HTTP_COOKIE'], 'spam=eggs')
self.assertEqual(dict(res.request.cookies), {'spam': 'eggs'})
+ def test_cookie_policy(self):
+ from six.moves import http_cookiejar
+
+ def cookie_app(environ, start_response):
+ status = to_bytes("200 OK")
+ body = 'Cookie.'
+ headers = [
+ ('Content-Type', 'text/plain'),
+ ('Content-Length', str(len(body))),
+ ('Set-Cookie',
+ 'spam=eggs; secure; Domain=.example.org;'),
+ ]
+ start_response(status, headers)
+ return [to_bytes(body)]
+
+ policy = webtest.app.CookiePolicy()
+ flags = (
+ policy.DomainStrictNoDots |
+ policy.DomainRFC2965Match |
+ policy.DomainStrictNonDomain)
+ policy.strict_ns_domain |= flags
+ cookiejar = http_cookiejar.CookieJar(policy=policy)
+ app = webtest.TestApp(
+ cookie_app,
+ cookiejar=cookiejar,
+ extra_environ={'HTTP_HOST': 'example.org'})
+ res = app.get('/')
+ res = app.get('/')
+ self.assertFalse(app.cookies,
+ 'Response should not have set cookies')
+ self.assertNotIn('HTTP_COOKIE', res.request.environ)
+ self.assertEqual(dict(res.request.cookies), {})
+
class TestEnviron(unittest.TestCase):
diff --git a/tests/test_forms.py b/tests/test_forms.py
index 62f30e6..a9de93d 100644
--- a/tests/test_forms.py
+++ b/tests/test_forms.py
@@ -321,6 +321,8 @@ def select_app(environ, start_response):
headers = [
('Content-Type', 'text/html; charset=utf-8'),
('Content-Length', str(len(body)))]
+ # PEP 3333 requires native strings:
+ headers = [(str(k), str(v)) for k, v in headers]
start_response(status, headers)
return [body]
@@ -373,6 +375,8 @@ def select_app_without_values(environ, start_response):
headers = [
('Content-Type', 'text/html; charset=utf-8'),
('Content-Length', str(len(body)))]
+ # PEP 3333 requires native strings:
+ headers = [(str(k), str(v)) for k, v in headers]
start_response(status, headers)
return [body]
@@ -425,6 +429,8 @@ def select_app_without_default(environ, start_response):
headers = [
('Content-Type', 'text/html; charset=utf-8'),
('Content-Length', str(len(body)))]
+ # PEP 3333 requires native strings:
+ headers = [(str(k), str(v)) for k, v in headers]
start_response(status, headers)
return [body]
@@ -476,6 +482,8 @@ def select_app_unicode(environ, start_response):
headers = [
('Content-Type', 'text/html; charset=utf-8'),
('Content-Length', str(len(body)))]
+ # PEP 3333 requires native strings:
+ headers = [(str(k), str(v)) for k, v in headers]
start_response(status, headers)
if not isinstance(body, binary_type):
raise AssertionError('Body is not %s' % binary_type)
@@ -736,6 +744,7 @@ class TestSelect(unittest.TestCase):
display = multiple_form.submit("button")
self.assertIn("<p>You selected </p>", display, display)
+
class SingleUploadFileApp(object):
body = b"""
@@ -745,6 +754,7 @@ class SingleUploadFileApp(object):
<form method="POST" id="file_upload_form"
enctype="multipart/form-data">
<input name="file-field" type="file" value="some/path/file.txt" />
+ <input name="int-field" type="text" value="" />
<input name="button" type="submit" value="single">
</form>
</body>
@@ -768,6 +778,8 @@ class SingleUploadFileApp(object):
headers = [
('Content-Type', 'text/html; charset=utf-8'),
('Content-Length', str(len(body)))]
+ # PEP 3333 requires native strings:
+ headers = [(str(k), str(v)) for k, v in headers]
start_response(status, headers)
assert(isinstance(body, binary_type))
return [body]
@@ -940,6 +952,25 @@ class TestFileUpload(unittest.TestCase):
self.assertFile(uploaded_file1_name, uploaded_file1_contents, display)
self.assertFile(uploaded_file1_name, uploaded_file1_contents, display)
+ def test_post_int(self):
+ binary_data = struct.pack(str('255h'), *range(0, 255))
+ app = webtest.TestApp(SingleUploadFileApp())
+ res = app.get('/')
+ single_form = res.forms["file_upload_form"]
+ single_form.set("file-field", ('my_file.dat', binary_data))
+ single_form.set("int-field", 100)
+ # just check it does not raise
+ single_form.submit("button")
+
+ def test_invalid_types(self):
+ binary_data = struct.pack(str('255h'), *range(0, 255))
+ app = webtest.TestApp(SingleUploadFileApp())
+ res = app.get('/')
+ single_form = res.forms["file_upload_form"]
+ single_form.set("file-field", ('my_file.dat', binary_data))
+ single_form.set("int-field", SingleUploadFileApp())
+ self.assertRaises(ValueError, single_form.submit, "button")
+
def test_upload_invalid_content(self):
app = webtest.TestApp(SingleUploadFileApp())
res = app.get('/')
diff --git a/tests/test_lint.py b/tests/test_lint.py
index 60a30a5..6f2a963 100644
--- a/tests/test_lint.py
+++ b/tests/test_lint.py
@@ -114,6 +114,8 @@ class TestMiddleware2(unittest.TestCase):
headers = [
('Content-Type', 'text/plain; charset=utf-8'),
('Content-Length', str(len(body)))]
+ # PEP 3333 requires native strings:
+ headers = [(str(k), str(v)) for k, v in headers]
start_response(to_bytes('200 OK'), headers, ('stuff',))
return [body]
@@ -141,13 +143,33 @@ class TestCheckContentType(unittest.TestCase):
class TestCheckHeaders(unittest.TestCase):
- @unittest.skipIf(not PY3, 'Useless in Python2')
- def test_header_unicode_value(self):
- self.assertRaises(AssertionError, check_headers, [('X-Price', '100€')])
-
- @unittest.skipIf(not PY3, 'Useless in Python2')
+ @unittest.skipIf(PY3, 'unicode is str in Python3')
def test_header_unicode_name(self):
- self.assertRaises(AssertionError, check_headers, [('X-€', 'foo')])
+ headers = [(u'X-Price', str('100'))]
+ self.assertRaises(AssertionError, check_headers, headers)
+
+ @unittest.skipIf(PY3, 'unicode is str in Python3')
+ def test_header_unicode_value(self):
+ headers = [(str('X-Price'), u'100')]
+ self.assertRaises(AssertionError, check_headers, headers)
+
+ @unittest.skipIf(not PY3, 'bytes is str in Python2')
+ def test_header_bytes_name(self):
+ headers = [(b'X-Price', '100')]
+ self.assertRaises(AssertionError, check_headers, headers)
+
+ @unittest.skipIf(not PY3, 'bytes is str in Python2')
+ def test_header_bytes_value(self):
+ headers = [('X-Price', b'100')]
+ self.assertRaises(AssertionError, check_headers, headers)
+
+ def test_header_non_latin1_value(self):
+ headers = [(str('X-Price'), '100€')]
+ self.assertRaises(AssertionError, check_headers, headers)
+
+ def test_header_non_latin1_name(self):
+ headers = [('X-€', str('foo'))]
+ self.assertRaises(AssertionError, check_headers, headers)
class TestCheckEnviron(unittest.TestCase):
diff --git a/tests/test_response.py b/tests/test_response.py
index f73a281..f3dad7f 100644
--- a/tests/test_response.py
+++ b/tests/test_response.py
@@ -115,7 +115,8 @@ def links_app(environ, start_response):
]
if req.path_info in utf8_paths:
headers[0] = ('Content-Type', str('text/html; charset=utf-8'))
-
+ # PEP 3333 requires native strings:
+ headers = [(str(k), str(v)) for k, v in headers]
start_response(str(status), headers)
return [body]
@@ -127,7 +128,8 @@ def gzipped_app(environ, start_response):
('Content-Type', str('text/html')),
('Content-Encoding', str('gzip')),
]
-
+ # PEP 3333 requires native strings:
+ headers = [(str(k), str(v)) for k, v in headers]
start_response(str(status), headers)
return encoded_body
@@ -423,6 +425,8 @@ class TestFollow(unittest.TestCase):
remaining_redirects[0] -= 1
headers.append(('Content-Length', str(len(body))))
+ # PEP 3333 requires native strings:
+ headers = [(str(k), str(v)) for k, v in headers]
start_response(str(status), headers)
return [body]
diff --git a/tox.ini b/tox.ini
index 3875d00..3eafcc7 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,6 +1,6 @@
[tox]
skip_missing_interpreters=true
-envlist=py27,py33,py34,py35,coverage
+envlist=py27,py33,py34,py35,py36,coverage
[testenv]
setenv =
@@ -19,9 +19,9 @@ deps =
commands =
{envbindir}/python --version
{envbindir}/pip freeze
- py{26,27,33}: {envbindir}/nosetests --with-coverage --with-xunit --xunit-file=nosetests-{envname}.xml []
+ py{27,33}: {envbindir}/nosetests --with-coverage --with-xunit --xunit-file=nosetests-{envname}.xml []
py{27,33}: {envbindir}/coverage xml -o coverage-{envname}.xml
- py{34,35}: {envbindir}/nosetests
+ py{34,35,36}: {envbindir}/nosetests
[testenv:coverage]
deps =
diff --git a/webtest/app.py b/webtest/app.py
index 736a865..1c19e94 100644
--- a/webtest/app.py
+++ b/webtest/app.py
@@ -69,13 +69,13 @@ class CookiePolicy(http_cookiejar.DefaultCookiePolicy):
Domain=localhost."""
def return_ok_domain(self, cookie, request):
- if cookie.domain.endswith(request.origin_req_host):
+ if cookie.domain == '.localhost':
return True
return http_cookiejar.DefaultCookiePolicy.return_ok_domain(
self, cookie, request)
def set_ok_domain(self, cookie, request):
- if cookie.domain.endswith(request.origin_req_host):
+ if cookie.domain == '.localhost':
return True
return http_cookiejar.DefaultCookiePolicy.set_ok_domain(
self, cookie, request)
@@ -231,9 +231,10 @@ class TestApp(object):
Sets a cookie to be passed through with requests.
"""
- cookie_domain = self.extra_environ.get('HTTP_HOST', 'localhost')
+ cookie_domain = self.extra_environ.get('HTTP_HOST', '.localhost')
cookie_domain = cookie_domain.split(':', 1)[0]
- cookie_domain = '.' + cookie_domain
+ if '.' not in cookie_domain:
+ cookie_domain = "%s.local" % cookie_domain
value = escape_cookie_value(value)
cookie = http_cookiejar.Cookie(
version=0,
@@ -518,8 +519,15 @@ class TestApp(object):
file_info.append(value.content_type)
_append_file(file_info)
else:
- if isinstance(value, text_type):
+ if isinstance(value, int):
+ value = str(value).encode('utf8')
+ elif isinstance(value, text_type):
value = value.encode('utf8')
+ elif not isinstance(value, (bytes, str)):
+ raise ValueError((
+ 'Value for field {0} is a {1} ({2}). '
+ 'It must be str, bytes or an int'
+ ).format(key, type(value), value))
lines.extend([
b'--' + boundary,
b'Content-Disposition: form-data; name="' + key + b'"',
diff --git a/webtest/lint.py b/webtest/lint.py
index 6906089..8462f36 100644
--- a/webtest/lint.py
+++ b/webtest/lint.py
@@ -59,7 +59,8 @@ Some of the things this checks:
* That the headers is a list (not a subclass, not another kind of
sequence).
-* That the items of the headers are tuples of strings.
+* That the items of the headers are tuples of 'native' strings (i.e.
+ bytestrings in Python2, and unicode strings in Python3).
* That there is no 'status' header (that is used in CGI, but not in
WSGI).
@@ -412,12 +413,12 @@ def check_status(status):
"digits and a space (4th characters is not a space here)") % status
-def _assert_latin1_py3(string, message):
- if PY3 and type(string) is str:
- try:
- string.encode('latin1')
- except UnicodeEncodeError:
- raise AssertionError(message)
+def _assert_latin1_str(string, message):
+ assert type(string) is str, message
+ try:
+ string.encode('latin1')
+ except UnicodeEncodeError:
+ raise AssertionError(message)
def check_headers(headers):
@@ -430,30 +431,30 @@ def check_headers(headers):
% (item, type(item)))
assert len(item) == 2
name, value = item
- _assert_latin1_py3(
+ _assert_latin1_str(
name,
- "Headers values must be latin1 string or bytes."
- "%r is not a valid latin1 string" % (value,)
+ "Header names must be latin1 string "
+ "(not Py2 unicode or Py3 bytes type). "
+ "%r is not a valid latin1 string" % (name,)
)
- str_name = to_string(name)
- assert str_name.lower() != 'status', (
+ assert name.lower() != 'status', (
"The Status header cannot be used; it conflicts with CGI "
"script, and HTTP status is not given through headers "
"(value: %r)." % value)
- assert '\n' not in str_name and ':' not in str_name, (
+ assert '\n' not in name and ':' not in name, (
"Header names may not contain ':' or '\\n': %r" % name)
- assert header_re.search(str_name), "Bad header name: %r" % name
- assert not str_name.endswith('-') and not str_name.endswith('_'), (
+ assert header_re.search(name), "Bad header name: %r" % name
+ assert not name.endswith('-') and not name.endswith('_'), (
"Names may not end in '-' or '_': %r" % name)
- _assert_latin1_py3(
+ _assert_latin1_str(
value,
- "Headers values must be latin1 string or bytes."
+ "Header values must be latin1 string "
+ "(not Py2 unicode or Py3 bytes type)."
"%r is not a valid latin1 string" % (value,)
)
- str_value = to_string(value)
- assert not bad_header_value_re.search(str_value), (
+ assert not bad_header_value_re.search(value), (
"Bad header value: %r (bad char: %r)"
- % (str_value, bad_header_value_re.search(str_value).group(0)))
+ % (str_value, bad_header_value_re.search(value).group(0)))
def check_content_type(status, headers):
@@ -464,13 +465,11 @@ def check_content_type(status, headers):
NO_MESSAGE_TYPE = (204, 304)
length = None
for name, value in headers:
- str_name = to_string(name)
- if str_name.lower() == 'content-length' and value.isdigit():
+ if name.lower() == 'content-length' and value.isdigit():
length = int(value)
break
for name, value in headers:
- str_name = to_string(name)
- if str_name.lower() == 'content-type':
+ if name.lower() == 'content-type':
if code not in NO_MESSAGE_TYPE:
return
elif length == 0:
diff --git a/webtest/utils.py b/webtest/utils.py
index adb01f3..3eb7f90 100644
--- a/webtest/utils.py
+++ b/webtest/utils.py
@@ -97,7 +97,7 @@ class _RequestCookieAdapter(object):
"""
def __init__(self, request):
self._request = request
- self.origin_req_host = request.host.split(':')[0]
+ self.origin_req_host = request.host
def is_unverifiable(self):
return True # sure? Why not?
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/webtest.git
More information about the Python-modules-commits
mailing list