summaryrefslogtreecommitdiffhomepage
path: root/test/unit/http.py
diff options
context:
space:
mode:
authorAndrei Zeliankou <zelenkov@nginx.com>2020-09-16 21:31:15 +0100
committerAndrei Zeliankou <zelenkov@nginx.com>2020-09-16 21:31:15 +0100
commitd5e915934066c77a59d211efafca10c117b73d05 (patch)
treef894a3c09bd8aa43e87276eed377eb09f97e46fe /test/unit/http.py
parent77ecb6ab49257dd662aa9c461fed3dc1d74e5092 (diff)
downloadunit-d5e915934066c77a59d211efafca10c117b73d05.tar.gz
unit-d5e915934066c77a59d211efafca10c117b73d05.tar.bz2
Tests: migrated to the pytest.
Diffstat (limited to 'test/unit/http.py')
-rw-r--r--test/unit/http.py32
1 files changed, 17 insertions, 15 deletions
diff --git a/test/unit/http.py b/test/unit/http.py
index de3bb2a4..54d32c06 100644
--- a/test/unit/http.py
+++ b/test/unit/http.py
@@ -2,12 +2,14 @@ import binascii
import io
import json
import os
+import pytest
import re
import select
import socket
import time
from unit.main import TestUnit
+from conftest import option
class TestHTTP(TestUnit):
@@ -56,7 +58,7 @@ class TestHTTP(TestUnit):
sock.connect(connect_args)
except ConnectionRefusedError:
sock.close()
- self.fail('Client can\'t connect to the server.')
+ pytest.fail('Client can\'t connect to the server.')
else:
sock = kwargs['sock']
@@ -128,7 +130,7 @@ class TestHTTP(TestUnit):
return (resp, sock)
def log_out(self, log, encoding):
- if TestUnit.detailed:
+ if option.detailed:
print('>>>')
log = self.log_truncate(log)
try:
@@ -137,7 +139,7 @@ class TestHTTP(TestUnit):
print(log)
def log_in(self, log):
- if TestUnit.detailed:
+ if option.detailed:
print('<<<')
log = self.log_truncate(log)
try:
@@ -190,7 +192,7 @@ class TestHTTP(TestUnit):
# For all current cases if the "read_timeout" was changed
# than test do not expect to get a response from server.
if timeout == timeout_default:
- self.fail('Can\'t read response from server.')
+ pytest.fail('Can\'t read response from server.')
break
try:
@@ -243,28 +245,28 @@ class TestHTTP(TestUnit):
chunks = raw_body.split(crlf)
if len(chunks) < 3:
- self.fail('Invalid chunked body')
+ pytest.fail('Invalid chunked body')
if chunks.pop() != b'':
- self.fail('No CRLF at the end of the body')
+ pytest.fail('No CRLF at the end of the body')
try:
last_size = int(chunks[-2], 16)
except:
- self.fail('Invalid zero size chunk')
+ pytest.fail('Invalid zero size chunk')
if last_size != 0 or chunks[-1] != b'':
- self.fail('Incomplete body')
+ pytest.fail('Incomplete body')
body = b''
while len(chunks) >= 2:
try:
size = int(chunks.pop(0), 16)
except:
- self.fail('Invalid chunk size %s' % str(size))
+ pytest.fail('Invalid chunk size %s' % str(size))
if size == 0:
- self.assertEqual(len(chunks), 1, 'last zero size')
+ assert len(chunks) == 1, 'last zero size'
break
temp_body = crlf.join(chunks)
@@ -280,8 +282,8 @@ class TestHTTP(TestUnit):
def _parse_json(self, resp):
headers = resp['headers']
- self.assertIn('Content-Type', headers)
- self.assertEqual(headers['Content-Type'], 'application/json')
+ assert 'Content-Type' in headers
+ assert headers['Content-Type'] == 'application/json'
resp['body'] = json.loads(resp['body'])
@@ -305,7 +307,7 @@ class TestHTTP(TestUnit):
sock.close()
- self.assertTrue(ret, 'socket connected')
+ assert ret, 'socket connected'
def form_encode(self, fields):
is_multipart = False
@@ -345,7 +347,7 @@ class TestHTTP(TestUnit):
datatype = value['type']
if not isinstance(value['data'], io.IOBase):
- self.fail('multipart encoding of file requires a stream.')
+ pytest.fail('multipart encoding of file requires a stream.')
data = value['data'].read()
@@ -353,7 +355,7 @@ class TestHTTP(TestUnit):
data = value
else:
- self.fail('multipart requires a string or stream data')
+ pytest.fail('multipart requires a string or stream data')
body += (
"--%s\r\nContent-Disposition: form-data; name=\"%s\""