diff options
| author | Michael Merickel <michael@merickel.org> | 2018-10-15 01:55:54 -0500 |
|---|---|---|
| committer | Michael Merickel <michael@merickel.org> | 2018-10-15 09:24:07 -0500 |
| commit | 0c29cf2df41600d3906d521c72991c7686018b71 (patch) | |
| tree | ff907f90ec9467e12874c9b2c961549d0e7caf74 /tests/test_scripts/test_prequest.py | |
| parent | 851c368e3c158e264358de10446f5b5de240e534 (diff) | |
| download | pyramid-0c29cf2df41600d3906d521c72991c7686018b71.tar.gz pyramid-0c29cf2df41600d3906d521c72991c7686018b71.tar.bz2 pyramid-0c29cf2df41600d3906d521c72991c7686018b71.zip | |
format source using black
Diffstat (limited to 'tests/test_scripts/test_prequest.py')
| -rw-r--r-- | tests/test_scripts/test_prequest.py | 134 |
1 files changed, 89 insertions, 45 deletions
diff --git a/tests/test_scripts/test_prequest.py b/tests/test_scripts/test_prequest.py index f7e656995..1521172bc 100644 --- a/tests/test_scripts/test_prequest.py +++ b/tests/test_scripts/test_prequest.py @@ -1,9 +1,11 @@ import unittest from . import dummy + class TestPRequestCommand(unittest.TestCase): def _getTargetClass(self): from pyramid.scripts.prequest import PRequestCommand + return PRequestCommand def _makeOne(self, argv, headers=None): @@ -14,6 +16,7 @@ class TestPRequestCommand(unittest.TestCase): self._path_info = environ['PATH_INFO'] start_request('200 OK', headers or []) return [b'abc'] + self.loader = dummy.DummyLoader(app=helloworld) self._out = [] cmd._get_config_loader = self.loader @@ -26,11 +29,15 @@ class TestPRequestCommand(unittest.TestCase): def test_command_not_enough_args(self): command = self._makeOne([]) command.run() - self.assertEqual(self._out, ['You must provide at least two arguments']) + self.assertEqual( + self._out, ['You must provide at least two arguments'] + ) def test_command_two_args(self): - command = self._makeOne(['', 'development.ini', '/'], - [('Content-Type', 'text/html; charset=UTF-8')]) + command = self._makeOne( + ['', 'development.ini', '/'], + [('Content-Type', 'text/html; charset=UTF-8')], + ) command.run() self.assertEqual(self._path_info, '/') self.assertEqual(self.loader.uri.path, 'development.ini') @@ -40,26 +47,31 @@ class TestPRequestCommand(unittest.TestCase): self.assertEqual(self._out, ['abc']) def test_command_path_doesnt_start_with_slash(self): - command = self._makeOne(['', 'development.ini', 'abc'], - [('Content-Type', 'text/html; charset=UTF-8')]) + command = self._makeOne( + ['', 'development.ini', 'abc'], + [('Content-Type', 'text/html; charset=UTF-8')], + ) command.run() self.assertEqual(self._path_info, '/abc') self.assertEqual(self.loader.uri.path, 'development.ini') self.assertEqual(self._out, ['abc']) def test_command_has_bad_config_header(self): - command = self._makeOne( - ['', '--header=name','development.ini', '/']) + command = self._makeOne(['', '--header=name', 'development.ini', '/']) command.run() self.assertEqual( self._out[0], - ("Bad --header=name option, value must be in the form " - "'name:value'")) + ( + "Bad --header=name option, value must be in the form " + "'name:value'" + ), + ) def test_command_has_good_header_var(self): command = self._makeOne( - ['', '--header=name:value','development.ini', '/'], - [('Content-Type', 'text/html; charset=UTF-8')]) + ['', '--header=name:value', 'development.ini', '/'], + [('Content-Type', 'text/html; charset=UTF-8')], + ) command.run() self.assertEqual(self._environ['HTTP_NAME'], 'value') self.assertEqual(self._path_info, '/') @@ -67,20 +79,28 @@ class TestPRequestCommand(unittest.TestCase): def test_command_w_basic_auth(self): command = self._makeOne( - ['', '--login=user:password', - '--header=name:value','development.ini', '/'], - [('Content-Type', 'text/html; charset=UTF-8')]) + [ + '', + '--login=user:password', + '--header=name:value', + 'development.ini', + '/', + ], + [('Content-Type', 'text/html; charset=UTF-8')], + ) command.run() self.assertEqual(self._environ['HTTP_NAME'], 'value') - self.assertEqual(self._environ['HTTP_AUTHORIZATION'], - 'Basic dXNlcjpwYXNzd29yZA==') + self.assertEqual( + self._environ['HTTP_AUTHORIZATION'], 'Basic dXNlcjpwYXNzd29yZA==' + ) self.assertEqual(self._path_info, '/') self.assertEqual(self._out, ['abc']) def test_command_has_content_type_header_var(self): command = self._makeOne( - ['', '--header=content-type:app/foo','development.ini', '/'], - [('Content-Type', 'text/html; charset=UTF-8')]) + ['', '--header=content-type:app/foo', 'development.ini', '/'], + [('Content-Type', 'text/html; charset=UTF-8')], + ) command.run() self.assertEqual(self._environ['CONTENT_TYPE'], 'app/foo') self.assertEqual(self._path_info, '/') @@ -88,13 +108,15 @@ class TestPRequestCommand(unittest.TestCase): def test_command_has_multiple_header_vars(self): command = self._makeOne( - ['', - '--header=name:value', - '--header=name2:value2', - 'development.ini', - '/'], - [('Content-Type', 'text/html; charset=UTF-8')] - ) + [ + '', + '--header=name:value', + '--header=name2:value2', + 'development.ini', + '/', + ], + [('Content-Type', 'text/html; charset=UTF-8')], + ) command.run() self.assertEqual(self._environ['HTTP_NAME'], 'value') self.assertEqual(self._environ['HTTP_NAME2'], 'value2') @@ -102,8 +124,10 @@ class TestPRequestCommand(unittest.TestCase): self.assertEqual(self._out, ['abc']) def test_command_method_get(self): - command = self._makeOne(['', '--method=GET', 'development.ini', '/'], - [('Content-Type', 'text/html; charset=UTF-8')]) + command = self._makeOne( + ['', '--method=GET', 'development.ini', '/'], + [('Content-Type', 'text/html; charset=UTF-8')], + ) command.run() self.assertEqual(self._environ['REQUEST_METHOD'], 'GET') self.assertEqual(self._path_info, '/') @@ -111,8 +135,11 @@ class TestPRequestCommand(unittest.TestCase): 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')]) + + command = self._makeOne( + ['', '--method=POST', 'development.ini', '/'], + [('Content-Type', 'text/html; charset=UTF-8')], + ) stdin = NativeIO() command.stdin = stdin command.run() @@ -124,8 +151,11 @@ class TestPRequestCommand(unittest.TestCase): 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')]) + + command = self._makeOne( + ['', '--method=PUT', 'development.ini', '/'], + [('Content-Type', 'text/html; charset=UTF-8')], + ) stdin = NativeIO() command.stdin = stdin command.run() @@ -137,8 +167,11 @@ class TestPRequestCommand(unittest.TestCase): 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')]) + + command = self._makeOne( + ['', '--method=PATCH', 'development.ini', '/'], + [('Content-Type', 'text/html; charset=UTF-8')], + ) stdin = NativeIO() command.stdin = stdin command.run() @@ -150,9 +183,11 @@ class TestPRequestCommand(unittest.TestCase): 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')]) + + command = self._makeOne( + ['', '--method=PROPFIND', 'development.ini', '/'], + [('Content-Type', 'text/html; charset=UTF-8')], + ) stdin = NativeIO() command.stdin = stdin command.run() @@ -162,9 +197,11 @@ class TestPRequestCommand(unittest.TestCase): 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')]) + + command = self._makeOne( + ['', '--method=OPTIONS', 'development.ini', '/'], + [('Content-Type', 'text/html; charset=UTF-8')], + ) stdin = NativeIO() command.stdin = stdin command.run() @@ -173,8 +210,10 @@ class TestPRequestCommand(unittest.TestCase): self.assertEqual(self._out, ['abc']) def test_command_with_query_string(self): - command = self._makeOne(['', 'development.ini', '/abc?a=1&b=2&c'], - [('Content-Type', 'text/html; charset=UTF-8')]) + command = self._makeOne( + ['', 'development.ini', '/abc?a=1&b=2&c'], + [('Content-Type', 'text/html; charset=UTF-8')], + ) command.run() self.assertEqual(self._environ['QUERY_STRING'], 'a=1&b=2&c') self.assertEqual(self._path_info, '/abc') @@ -183,16 +222,20 @@ class TestPRequestCommand(unittest.TestCase): def test_command_display_headers(self): command = self._makeOne( ['', '--display-headers', 'development.ini', '/'], - [('Content-Type', 'text/html; charset=UTF-8')]) + [('Content-Type', 'text/html; charset=UTF-8')], + ) command.run() self.assertEqual(self._path_info, '/') self.assertEqual( self._out, - ['200 OK', 'Content-Type: text/html; charset=UTF-8', 'abc']) + ['200 OK', 'Content-Type: text/html; charset=UTF-8', 'abc'], + ) def test_command_response_has_no_charset(self): - command = self._makeOne(['', '--method=GET', 'development.ini', '/'], - headers=[('Content-Type', 'image/jpeg')]) + command = self._makeOne( + ['', '--method=GET', 'development.ini', '/'], + headers=[('Content-Type', 'image/jpeg')], + ) command.run() self.assertEqual(self._path_info, '/') @@ -207,6 +250,7 @@ class TestPRequestCommand(unittest.TestCase): class Test_main(unittest.TestCase): def _callFUT(self, argv): from pyramid.scripts.prequest import main + return main(argv, True) def test_it(self): |
