From e2c7bbf5566f5be4d1b5b58d3e23948b4dc9b651 Mon Sep 17 00:00:00 2001 From: Michael Merickel Date: Mon, 12 Nov 2018 23:27:59 -0600 Subject: get rid of NativeIO alias and a few others --- tests/test_scripts/test_prequest.py | 21 ++++++--------------- tests/test_scripts/test_pserve.py | 5 ++--- 2 files changed, 8 insertions(+), 18 deletions(-) (limited to 'tests/test_scripts') diff --git a/tests/test_scripts/test_prequest.py b/tests/test_scripts/test_prequest.py index 1521172bc..aadde719a 100644 --- a/tests/test_scripts/test_prequest.py +++ b/tests/test_scripts/test_prequest.py @@ -1,3 +1,4 @@ +from io import StringIO import unittest from . import dummy @@ -134,13 +135,11 @@ class TestPRequestCommand(unittest.TestCase): self.assertEqual(self._out, ['abc']) def test_command_method_post(self): - from pyramid.compat import NativeIO - command = self._makeOne( ['', '--method=POST', 'development.ini', '/'], [('Content-Type', 'text/html; charset=UTF-8')], ) - stdin = NativeIO() + stdin = StringIO() command.stdin = stdin command.run() self.assertEqual(self._environ['REQUEST_METHOD'], 'POST') @@ -150,13 +149,11 @@ class TestPRequestCommand(unittest.TestCase): self.assertEqual(self._out, ['abc']) def test_command_method_put(self): - from pyramid.compat import NativeIO - command = self._makeOne( ['', '--method=PUT', 'development.ini', '/'], [('Content-Type', 'text/html; charset=UTF-8')], ) - stdin = NativeIO() + stdin = StringIO() command.stdin = stdin command.run() self.assertEqual(self._environ['REQUEST_METHOD'], 'PUT') @@ -166,13 +163,11 @@ class TestPRequestCommand(unittest.TestCase): self.assertEqual(self._out, ['abc']) def test_command_method_patch(self): - from pyramid.compat import NativeIO - command = self._makeOne( ['', '--method=PATCH', 'development.ini', '/'], [('Content-Type', 'text/html; charset=UTF-8')], ) - stdin = NativeIO() + stdin = StringIO() command.stdin = stdin command.run() self.assertEqual(self._environ['REQUEST_METHOD'], 'PATCH') @@ -182,13 +177,11 @@ class TestPRequestCommand(unittest.TestCase): self.assertEqual(self._out, ['abc']) def test_command_method_propfind(self): - from pyramid.compat import NativeIO - command = self._makeOne( ['', '--method=PROPFIND', 'development.ini', '/'], [('Content-Type', 'text/html; charset=UTF-8')], ) - stdin = NativeIO() + stdin = StringIO() command.stdin = stdin command.run() self.assertEqual(self._environ['REQUEST_METHOD'], 'PROPFIND') @@ -196,13 +189,11 @@ class TestPRequestCommand(unittest.TestCase): self.assertEqual(self._out, ['abc']) def test_command_method_options(self): - from pyramid.compat import NativeIO - command = self._makeOne( ['', '--method=OPTIONS', 'development.ini', '/'], [('Content-Type', 'text/html; charset=UTF-8')], ) - stdin = NativeIO() + stdin = StringIO() command.stdin = stdin command.run() self.assertEqual(self._environ['REQUEST_METHOD'], 'OPTIONS') diff --git a/tests/test_scripts/test_pserve.py b/tests/test_scripts/test_pserve.py index b85f4ddb7..a573f2e5b 100644 --- a/tests/test_scripts/test_pserve.py +++ b/tests/test_scripts/test_pserve.py @@ -1,3 +1,4 @@ +from io import StringIO import os import unittest from . import dummy @@ -8,9 +9,7 @@ here = os.path.abspath(os.path.dirname(__file__)) class TestPServeCommand(unittest.TestCase): def setUp(self): - from pyramid.compat import NativeIO - - self.out_ = NativeIO() + self.out_ = StringIO() def out(self, msg): self.out_.write(msg) -- cgit v1.2.3 From a705f56c3ebf34f25ab567d85b7d5b421983aa4a Mon Sep 17 00:00:00 2001 From: Michael Merickel Date: Wed, 14 Nov 2018 20:35:39 -0600 Subject: rely on webob for request.path_info and request.scheme --- tests/test_scripts/dummy.py | 5 ++++- tests/test_scripts/test_pviews.py | 18 ++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) (limited to 'tests/test_scripts') diff --git a/tests/test_scripts/dummy.py b/tests/test_scripts/dummy.py index 8e340f645..bb3475d39 100644 --- a/tests/test_scripts/dummy.py +++ b/tests/test_scripts/dummy.py @@ -81,8 +81,11 @@ class DummyRoute(object): class DummyRequest: application_url = 'http://example.com:5432' script_name = '' + path_info = '/' - def __init__(self, environ): + def __init__(self, environ=None): + if environ is None: + environ = {} self.environ = environ self.matchdict = {} diff --git a/tests/test_scripts/test_pviews.py b/tests/test_scripts/test_pviews.py index 0b26a9cf3..c8d29113f 100644 --- a/tests/test_scripts/test_pviews.py +++ b/tests/test_scripts/test_pviews.py @@ -53,7 +53,8 @@ class TestPViewsCommand(unittest.TestCase): class View1(object): pass - request = dummy.DummyRequest({'PATH_INFO': '/a'}) + request = dummy.DummyRequest() + request.path_info = '/a' root = DefaultRootFactory(request) root_iface = providedBy(root) registry.registerAdapter( @@ -78,7 +79,8 @@ class TestPViewsCommand(unittest.TestCase): def view1(): # pragma: no cover pass - request = dummy.DummyRequest({'PATH_INFO': '/a'}) + request = dummy.DummyRequest() + request.path_info = '/a' root = DefaultRootFactory(request) root_iface = providedBy(root) registry.registerAdapter( @@ -105,7 +107,8 @@ class TestPViewsCommand(unittest.TestCase): class View1(object): pass - request = dummy.DummyRequest({'PATH_INFO': '/a'}) + request = dummy.DummyRequest() + request.path_info = '/a' root = DefaultRootFactory(request) root_iface = providedBy(root) view = View1() @@ -267,7 +270,8 @@ class TestPViewsCommand(unittest.TestCase): dummy.DummyRoute('b', '/a', factory=factory, matchdict={}), ] mapper = dummy.DummyMapper(*routes) - request = dummy.DummyRequest({'PATH_INFO': '/a'}) + request = dummy.DummyRequest() + request.path_info = '/a' result = command._find_multi_routes(mapper, request) self.assertEqual( result, @@ -288,7 +292,8 @@ class TestPViewsCommand(unittest.TestCase): dummy.DummyRoute('b', '/a', factory=factory, matchdict={}), ] mapper = dummy.DummyMapper(*routes) - request = dummy.DummyRequest({'PATH_INFO': '/a'}) + request = dummy.DummyRequest() + request.path_info = '/a' result = command._find_multi_routes(mapper, request) self.assertEqual(result, [{'match': {}, 'route': routes[1]}]) @@ -303,7 +308,8 @@ class TestPViewsCommand(unittest.TestCase): dummy.DummyRoute('b', '/a', factory=factory), ] mapper = dummy.DummyMapper(*routes) - request = dummy.DummyRequest({'PATH_INFO': '/a'}) + request = dummy.DummyRequest() + request.path_info = '/a' result = command._find_multi_routes(mapper, request) self.assertEqual(result, []) -- cgit v1.2.3