diff options
author | Andrei Zeliankou <zelenkov@nginx.com> | 2020-09-16 21:31:15 +0100 |
---|---|---|
committer | Andrei Zeliankou <zelenkov@nginx.com> | 2020-09-16 21:31:15 +0100 |
commit | d5e915934066c77a59d211efafca10c117b73d05 (patch) | |
tree | f894a3c09bd8aa43e87276eed377eb09f97e46fe /test/test_http_header.py | |
parent | 77ecb6ab49257dd662aa9c461fed3dc1d74e5092 (diff) | |
download | unit-d5e915934066c77a59d211efafca10c117b73d05.tar.gz unit-d5e915934066c77a59d211efafca10c117b73d05.tar.bz2 |
Tests: migrated to the pytest.
Diffstat (limited to 'test/test_http_header.py')
-rw-r--r-- | test/test_http_header.py | 294 |
1 files changed, 120 insertions, 174 deletions
diff --git a/test/test_http_header.py b/test/test_http_header.py index ea4520c1..8c1e211b 100644 --- a/test/test_http_header.py +++ b/test/test_http_header.py @@ -1,4 +1,4 @@ -import unittest +import pytest from unit.applications.lang.python import TestApplicationPython @@ -17,12 +17,10 @@ class TestHTTPHeader(TestApplicationPython): } ) - self.assertEqual(resp['status'], 200, 'value leading sp status') - self.assertEqual( - resp['headers']['Custom-Header'], - ',', - 'value leading sp custom header', - ) + assert resp['status'] == 200, 'value leading sp status' + assert ( + resp['headers']['Custom-Header'] == ',' + ), 'value leading sp custom header' def test_http_header_value_leading_htab(self): self.load('custom_header') @@ -35,12 +33,10 @@ class TestHTTPHeader(TestApplicationPython): } ) - self.assertEqual(resp['status'], 200, 'value leading htab status') - self.assertEqual( - resp['headers']['Custom-Header'], - ',', - 'value leading htab custom header', - ) + assert resp['status'] == 200, 'value leading htab status' + assert ( + resp['headers']['Custom-Header'] == ',' + ), 'value leading htab custom header' def test_http_header_value_trailing_sp(self): self.load('custom_header') @@ -53,12 +49,10 @@ class TestHTTPHeader(TestApplicationPython): } ) - self.assertEqual(resp['status'], 200, 'value trailing sp status') - self.assertEqual( - resp['headers']['Custom-Header'], - ',', - 'value trailing sp custom header', - ) + assert resp['status'] == 200, 'value trailing sp status' + assert ( + resp['headers']['Custom-Header'] == ',' + ), 'value trailing sp custom header' def test_http_header_value_trailing_htab(self): self.load('custom_header') @@ -71,12 +65,10 @@ class TestHTTPHeader(TestApplicationPython): } ) - self.assertEqual(resp['status'], 200, 'value trailing htab status') - self.assertEqual( - resp['headers']['Custom-Header'], - ',', - 'value trailing htab custom header', - ) + assert resp['status'] == 200, 'value trailing htab status' + assert ( + resp['headers']['Custom-Header'] == ',' + ), 'value trailing htab custom header' def test_http_header_value_both_sp(self): self.load('custom_header') @@ -89,12 +81,10 @@ class TestHTTPHeader(TestApplicationPython): } ) - self.assertEqual(resp['status'], 200, 'value both sp status') - self.assertEqual( - resp['headers']['Custom-Header'], - ',', - 'value both sp custom header', - ) + assert resp['status'] == 200, 'value both sp status' + assert ( + resp['headers']['Custom-Header'] == ',' + ), 'value both sp custom header' def test_http_header_value_both_htab(self): self.load('custom_header') @@ -107,12 +97,10 @@ class TestHTTPHeader(TestApplicationPython): } ) - self.assertEqual(resp['status'], 200, 'value both htab status') - self.assertEqual( - resp['headers']['Custom-Header'], - ',', - 'value both htab custom header', - ) + assert resp['status'] == 200, 'value both htab status' + assert ( + resp['headers']['Custom-Header'] == ',' + ), 'value both htab custom header' def test_http_header_value_chars(self): self.load('custom_header') @@ -125,12 +113,11 @@ class TestHTTPHeader(TestApplicationPython): } ) - self.assertEqual(resp['status'], 200, 'value chars status') - self.assertEqual( - resp['headers']['Custom-Header'], - '(),/:;<=>?@[\]{}\t !#$%&\'*+-.^_`|~', - 'value chars custom header', - ) + assert resp['status'] == 200, 'value chars status' + assert ( + resp['headers']['Custom-Header'] + == '(),/:;<=>?@[\]{}\t !#$%&\'*+-.^_`|~' + ), 'value chars custom header' def test_http_header_value_chars_edge(self): self.load('custom_header') @@ -146,10 +133,8 @@ Connection: close encoding='latin1', ) - self.assertEqual(resp['status'], 200, 'value chars edge status') - self.assertEqual( - resp['headers']['Custom-Header'], '\xFF', 'value chars edge' - ) + assert resp['status'] == 200, 'value chars edge status' + assert resp['headers']['Custom-Header'] == '\xFF', 'value chars edge' def test_http_header_value_chars_below(self): self.load('custom_header') @@ -164,7 +149,7 @@ Connection: close raw=True, ) - self.assertEqual(resp['status'], 400, 'value chars below') + assert resp['status'] == 400, 'value chars below' def test_http_header_field_leading_sp(self): self.load('empty') @@ -177,7 +162,7 @@ Connection: close } ) - self.assertEqual(resp['status'], 400, 'field leading sp') + assert resp['status'] == 400, 'field leading sp' def test_http_header_field_leading_htab(self): self.load('empty') @@ -190,7 +175,7 @@ Connection: close } ) - self.assertEqual(resp['status'], 400, 'field leading htab') + assert resp['status'] == 400, 'field leading htab' def test_http_header_field_trailing_sp(self): self.load('empty') @@ -203,7 +188,7 @@ Connection: close } ) - self.assertEqual(resp['status'], 400, 'field trailing sp') + assert resp['status'] == 400, 'field trailing sp' def test_http_header_field_trailing_htab(self): self.load('empty') @@ -216,12 +201,12 @@ Connection: close } ) - self.assertEqual(resp['status'], 400, 'field trailing htab') + assert resp['status'] == 400, 'field trailing htab' def test_http_header_content_length_big(self): self.load('empty') - self.assertEqual( + assert ( self.post( headers={ 'Host': 'localhost', @@ -229,15 +214,14 @@ Connection: close 'Connection': 'close', }, body='X' * 1000, - )['status'], - 400, - 'Content-Length big', - ) + )['status'] + == 400 + ), 'Content-Length big' def test_http_header_content_length_negative(self): self.load('empty') - self.assertEqual( + assert ( self.post( headers={ 'Host': 'localhost', @@ -245,15 +229,14 @@ Connection: close 'Connection': 'close', }, body='X' * 1000, - )['status'], - 400, - 'Content-Length negative', - ) + )['status'] + == 400 + ), 'Content-Length negative' def test_http_header_content_length_text(self): self.load('empty') - self.assertEqual( + assert ( self.post( headers={ 'Host': 'localhost', @@ -261,15 +244,14 @@ Connection: close 'Connection': 'close', }, body='X' * 1000, - )['status'], - 400, - 'Content-Length text', - ) + )['status'] + == 400 + ), 'Content-Length text' def test_http_header_content_length_multiple_values(self): self.load('empty') - self.assertEqual( + assert ( self.post( headers={ 'Host': 'localhost', @@ -277,15 +259,14 @@ Connection: close 'Connection': 'close', }, body='X' * 1000, - )['status'], - 400, - 'Content-Length multiple value', - ) + )['status'] + == 400 + ), 'Content-Length multiple value' def test_http_header_content_length_multiple_fields(self): self.load('empty') - self.assertEqual( + assert ( self.post( headers={ 'Host': 'localhost', @@ -293,39 +274,35 @@ Connection: close 'Connection': 'close', }, body='X' * 1000, - )['status'], - 400, - 'Content-Length multiple fields', - ) + )['status'] + == 400 + ), 'Content-Length multiple fields' - @unittest.skip('not yet') + @pytest.mark.skip('not yet') def test_http_header_host_absent(self): self.load('host') resp = self.get(headers={'Connection': 'close'}) - self.assertEqual(resp['status'], 400, 'Host absent status') + assert resp['status'] == 400, 'Host absent status' def test_http_header_host_empty(self): self.load('host') resp = self.get(headers={'Host': '', 'Connection': 'close'}) - self.assertEqual(resp['status'], 200, 'Host empty status') - self.assertNotEqual( - resp['headers']['X-Server-Name'], '', 'Host empty SERVER_NAME' - ) + assert resp['status'] == 200, 'Host empty status' + assert resp['headers']['X-Server-Name'] != '', 'Host empty SERVER_NAME' def test_http_header_host_big(self): self.load('empty') - self.assertEqual( + assert ( self.get(headers={'Host': 'X' * 10000, 'Connection': 'close'})[ 'status' - ], - 431, - 'Host big', - ) + ] + == 431 + ), 'Host big' def test_http_header_host_port(self): self.load('host') @@ -334,17 +311,13 @@ Connection: close headers={'Host': 'exmaple.com:7080', 'Connection': 'close'} ) - self.assertEqual(resp['status'], 200, 'Host port status') - self.assertEqual( - resp['headers']['X-Server-Name'], - 'exmaple.com', - 'Host port SERVER_NAME', - ) - self.assertEqual( - resp['headers']['X-Http-Host'], - 'exmaple.com:7080', - 'Host port HTTP_HOST', - ) + assert resp['status'] == 200, 'Host port status' + assert ( + resp['headers']['X-Server-Name'] == 'exmaple.com' + ), 'Host port SERVER_NAME' + assert ( + resp['headers']['X-Http-Host'] == 'exmaple.com:7080' + ), 'Host port HTTP_HOST' def test_http_header_host_port_empty(self): self.load('host') @@ -353,63 +326,49 @@ Connection: close headers={'Host': 'exmaple.com:', 'Connection': 'close'} ) - self.assertEqual(resp['status'], 200, 'Host port empty status') - self.assertEqual( - resp['headers']['X-Server-Name'], - 'exmaple.com', - 'Host port empty SERVER_NAME', - ) - self.assertEqual( - resp['headers']['X-Http-Host'], - 'exmaple.com:', - 'Host port empty HTTP_HOST', - ) + assert resp['status'] == 200, 'Host port empty status' + assert ( + resp['headers']['X-Server-Name'] == 'exmaple.com' + ), 'Host port empty SERVER_NAME' + assert ( + resp['headers']['X-Http-Host'] == 'exmaple.com:' + ), 'Host port empty HTTP_HOST' def test_http_header_host_literal(self): self.load('host') resp = self.get(headers={'Host': '127.0.0.1', 'Connection': 'close'}) - self.assertEqual(resp['status'], 200, 'Host literal status') - self.assertEqual( - resp['headers']['X-Server-Name'], - '127.0.0.1', - 'Host literal SERVER_NAME', - ) + assert resp['status'] == 200, 'Host literal status' + assert ( + resp['headers']['X-Server-Name'] == '127.0.0.1' + ), 'Host literal SERVER_NAME' def test_http_header_host_literal_ipv6(self): self.load('host') resp = self.get(headers={'Host': '[::1]:7080', 'Connection': 'close'}) - self.assertEqual(resp['status'], 200, 'Host literal ipv6 status') - self.assertEqual( - resp['headers']['X-Server-Name'], - '[::1]', - 'Host literal ipv6 SERVER_NAME', - ) - self.assertEqual( - resp['headers']['X-Http-Host'], - '[::1]:7080', - 'Host literal ipv6 HTTP_HOST', - ) + assert resp['status'] == 200, 'Host literal ipv6 status' + assert ( + resp['headers']['X-Server-Name'] == '[::1]' + ), 'Host literal ipv6 SERVER_NAME' + assert ( + resp['headers']['X-Http-Host'] == '[::1]:7080' + ), 'Host literal ipv6 HTTP_HOST' def test_http_header_host_trailing_period(self): self.load('host') resp = self.get(headers={'Host': '127.0.0.1.', 'Connection': 'close'}) - self.assertEqual(resp['status'], 200, 'Host trailing period status') - self.assertEqual( - resp['headers']['X-Server-Name'], - '127.0.0.1', - 'Host trailing period SERVER_NAME', - ) - self.assertEqual( - resp['headers']['X-Http-Host'], - '127.0.0.1.', - 'Host trailing period HTTP_HOST', - ) + assert resp['status'] == 200, 'Host trailing period status' + assert ( + resp['headers']['X-Server-Name'] == '127.0.0.1' + ), 'Host trailing period SERVER_NAME' + assert ( + resp['headers']['X-Http-Host'] == '127.0.0.1.' + ), 'Host trailing period HTTP_HOST' def test_http_header_host_trailing_period_2(self): self.load('host') @@ -418,66 +377,53 @@ Connection: close headers={'Host': 'EXAMPLE.COM.', 'Connection': 'close'} ) - self.assertEqual(resp['status'], 200, 'Host trailing period 2 status') - self.assertEqual( - resp['headers']['X-Server-Name'], - 'example.com', - 'Host trailing period 2 SERVER_NAME', - ) - self.assertEqual( - resp['headers']['X-Http-Host'], - 'EXAMPLE.COM.', - 'Host trailing period 2 HTTP_HOST', - ) + assert resp['status'] == 200, 'Host trailing period 2 status' + assert ( + resp['headers']['X-Server-Name'] == 'example.com' + ), 'Host trailing period 2 SERVER_NAME' + assert ( + resp['headers']['X-Http-Host'] == 'EXAMPLE.COM.' + ), 'Host trailing period 2 HTTP_HOST' def test_http_header_host_case_insensitive(self): self.load('host') resp = self.get(headers={'Host': 'EXAMPLE.COM', 'Connection': 'close'}) - self.assertEqual(resp['status'], 200, 'Host case insensitive') - self.assertEqual( - resp['headers']['X-Server-Name'], - 'example.com', - 'Host case insensitive SERVER_NAME', - ) + assert resp['status'] == 200, 'Host case insensitive' + assert ( + resp['headers']['X-Server-Name'] == 'example.com' + ), 'Host case insensitive SERVER_NAME' def test_http_header_host_double_dot(self): self.load('empty') - self.assertEqual( + assert ( self.get(headers={'Host': '127.0.0..1', 'Connection': 'close'})[ 'status' - ], - 400, - 'Host double dot', - ) + ] + == 400 + ), 'Host double dot' def test_http_header_host_slash(self): self.load('empty') - self.assertEqual( + assert ( self.get(headers={'Host': '/localhost', 'Connection': 'close'})[ 'status' - ], - 400, - 'Host slash', - ) + ] + == 400 + ), 'Host slash' def test_http_header_host_multiple_fields(self): self.load('empty') - self.assertEqual( + assert ( self.get( headers={ 'Host': ['localhost', 'example.com'], 'Connection': 'close', } - )['status'], - 400, - 'Host multiple fields', - ) - - -if __name__ == '__main__': - TestHTTPHeader.main() + )['status'] + == 400 + ), 'Host multiple fields' |