summaryrefslogtreecommitdiffhomepage
path: root/test/test_access_log.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/test_access_log.py
parent77ecb6ab49257dd662aa9c461fed3dc1d74e5092 (diff)
downloadunit-d5e915934066c77a59d211efafca10c117b73d05.tar.gz
unit-d5e915934066c77a59d211efafca10c117b73d05.tar.bz2
Tests: migrated to the pytest.
Diffstat (limited to 'test/test_access_log.py')
-rw-r--r--test/test_access_log.py160
1 files changed, 75 insertions, 85 deletions
diff --git a/test/test_access_log.py b/test/test_access_log.py
index 3ef8f7a0..010c56c2 100644
--- a/test/test_access_log.py
+++ b/test/test_access_log.py
@@ -1,5 +1,5 @@
+import pytest
import time
-import unittest
from unit.applications.lang.python import TestApplicationPython
@@ -10,11 +10,9 @@ class TestAccessLog(TestApplicationPython):
def load(self, script):
super().load(script)
- self.assertIn(
- 'success',
- self.conf('"' + self.testdir + '/access.log"', 'access_log'),
- 'access_log configure',
- )
+ assert 'success' in self.conf(
+ '"' + self.temp_dir + '/access.log"', 'access_log'
+ ), 'access_log configure'
def wait_for_record(self, pattern, name='access.log'):
return super().wait_for_record(pattern, name)
@@ -22,7 +20,7 @@ class TestAccessLog(TestApplicationPython):
def test_access_log_keepalive(self):
self.load('mirror')
- self.assertEqual(self.get()['status'], 200, 'init')
+ assert self.get()['status'] == 200, 'init'
(resp, sock) = self.post(
headers={
@@ -35,9 +33,9 @@ class TestAccessLog(TestApplicationPython):
read_timeout=1,
)
- self.assertIsNotNone(
- self.wait_for_record(r'"POST / HTTP/1.1" 200 5'), 'keepalive 1'
- )
+ assert (
+ self.wait_for_record(r'"POST / HTTP/1.1" 200 5') is not None
+ ), 'keepalive 1'
resp = self.post(
headers={
@@ -51,9 +49,9 @@ class TestAccessLog(TestApplicationPython):
self.stop()
- self.assertIsNotNone(
- self.wait_for_record(r'"POST / HTTP/1.1" 200 10'), 'keepalive 2'
- )
+ assert (
+ self.wait_for_record(r'"POST / HTTP/1.1" 200 10') is not None
+ ), 'keepalive 2'
def test_access_log_pipeline(self):
self.load('empty')
@@ -79,18 +77,18 @@ Connection: close
self.stop()
- self.assertIsNotNone(
- self.wait_for_record(r'"GET / HTTP/1.1" 200 0 "Referer-1" "-"'),
- 'pipeline 1',
- )
- self.assertIsNotNone(
- self.wait_for_record(r'"GET / HTTP/1.1" 200 0 "Referer-2" "-"'),
- 'pipeline 2',
- )
- self.assertIsNotNone(
- self.wait_for_record(r'"GET / HTTP/1.1" 200 0 "Referer-3" "-"'),
- 'pipeline 3',
- )
+ assert (
+ self.wait_for_record(r'"GET / HTTP/1.1" 200 0 "Referer-1" "-"')
+ is not None
+ ), 'pipeline 1'
+ assert (
+ self.wait_for_record(r'"GET / HTTP/1.1" 200 0 "Referer-2" "-"')
+ is not None
+ ), 'pipeline 2'
+ assert (
+ self.wait_for_record(r'"GET / HTTP/1.1" 200 0 "Referer-3" "-"')
+ is not None
+ ), 'pipeline 3'
def test_access_log_ipv6(self):
self.load('empty')
@@ -101,17 +99,17 @@ Connection: close
self.stop()
- self.assertIsNotNone(
+ assert (
self.wait_for_record(
r'::1 - - \[.+\] "GET / HTTP/1.1" 200 0 "-" "-"'
- ),
- 'ipv6',
- )
+ )
+ is not None
+ ), 'ipv6'
def test_access_log_unix(self):
self.load('empty')
- addr = self.testdir + '/sock'
+ addr = self.temp_dir + '/sock'
self.conf(
{"unix:" + addr: {"pass": "applications/empty"}}, 'listeners'
@@ -121,12 +119,12 @@ Connection: close
self.stop()
- self.assertIsNotNone(
+ assert (
self.wait_for_record(
r'unix: - - \[.+\] "GET / HTTP/1.1" 200 0 "-" "-"'
- ),
- 'unix',
- )
+ )
+ is not None
+ ), 'unix'
def test_access_log_referer(self):
self.load('empty')
@@ -141,12 +139,10 @@ Connection: close
self.stop()
- self.assertIsNotNone(
- self.wait_for_record(
- r'"GET / HTTP/1.1" 200 0 "referer-value" "-"'
- ),
- 'referer',
- )
+ assert (
+ self.wait_for_record(r'"GET / HTTP/1.1" 200 0 "referer-value" "-"')
+ is not None
+ ), 'referer'
def test_access_log_user_agent(self):
self.load('empty')
@@ -161,12 +157,12 @@ Connection: close
self.stop()
- self.assertIsNotNone(
+ assert (
self.wait_for_record(
r'"GET / HTTP/1.1" 200 0 "-" "user-agent-value"'
- ),
- 'user agent',
- )
+ )
+ is not None
+ ), 'user agent'
def test_access_log_http10(self):
self.load('empty')
@@ -175,14 +171,14 @@ Connection: close
self.stop()
- self.assertIsNotNone(
- self.wait_for_record(r'"GET / HTTP/1.0" 200 0 "-" "-"'), 'http 1.0'
- )
+ assert (
+ self.wait_for_record(r'"GET / HTTP/1.0" 200 0 "-" "-"') is not None
+ ), 'http 1.0'
def test_access_log_partial(self):
self.load('empty')
- self.assertEqual(self.post()['status'], 200, 'init')
+ assert self.post()['status'] == 200, 'init'
resp = self.http(b"""GE""", raw=True, read_timeout=1)
@@ -190,27 +186,27 @@ Connection: close
self.stop()
- self.assertIsNotNone(
- self.wait_for_record(r'"GE" 400 0 "-" "-"'), 'partial'
- )
+ assert (
+ self.wait_for_record(r'"GE" 400 0 "-" "-"') is not None
+ ), 'partial'
def test_access_log_partial_2(self):
self.load('empty')
- self.assertEqual(self.post()['status'], 200, 'init')
+ assert self.post()['status'] == 200, 'init'
self.http(b"""GET /\n""", raw=True)
self.stop()
- self.assertIsNotNone(
- self.wait_for_record(r'"GET /" 400 \d+ "-" "-"'), 'partial 2'
- )
+ assert (
+ self.wait_for_record(r'"GET /" 400 \d+ "-" "-"') is not None
+ ), 'partial 2'
def test_access_log_partial_3(self):
self.load('empty')
- self.assertEqual(self.post()['status'], 200, 'init')
+ assert self.post()['status'] == 200, 'init'
resp = self.http(b"""GET / HTTP/1.1""", raw=True, read_timeout=1)
@@ -218,14 +214,14 @@ Connection: close
self.stop()
- self.assertIsNotNone(
- self.wait_for_record(r'"GET /" 400 0 "-" "-"'), 'partial 3'
- )
+ assert (
+ self.wait_for_record(r'"GET /" 400 0 "-" "-"') is not None
+ ), 'partial 3'
def test_access_log_partial_4(self):
self.load('empty')
- self.assertEqual(self.post()['status'], 200, 'init')
+ assert self.post()['status'] == 200, 'init'
resp = self.http(b"""GET / HTTP/1.1\n""", raw=True, read_timeout=1)
@@ -233,25 +229,24 @@ Connection: close
self.stop()
- self.assertIsNotNone(
- self.wait_for_record(r'"GET / HTTP/1.1" 400 0 "-" "-"'),
- 'partial 4',
- )
+ assert (
+ self.wait_for_record(r'"GET / HTTP/1.1" 400 0 "-" "-"') is not None
+ ), 'partial 4'
- @unittest.skip('not yet')
+ @pytest.mark.skip('not yet')
def test_access_log_partial_5(self):
self.load('empty')
- self.assertEqual(self.post()['status'], 200, 'init')
+ assert self.post()['status'] == 200, 'init'
self.get(headers={'Connection': 'close'})
self.stop()
- self.assertIsNotNone(
- self.wait_for_record(r'"GET / HTTP/1.1" 400 \d+ "-" "-"'),
- 'partial 5',
- )
+ assert (
+ self.wait_for_record(r'"GET / HTTP/1.1" 400 \d+ "-" "-"')
+ is not None
+ ), 'partial 5'
def test_access_log_get_parameters(self):
self.load('empty')
@@ -260,12 +255,12 @@ Connection: close
self.stop()
- self.assertIsNotNone(
+ assert (
self.wait_for_record(
r'"GET /\?blah&var=val HTTP/1.1" 200 0 "-" "-"'
- ),
- 'get parameters',
- )
+ )
+ is not None
+ ), 'get parameters'
def test_access_log_delete(self):
self.load('empty')
@@ -276,25 +271,20 @@ Connection: close
self.stop()
- self.assertIsNone(
- self.search_in_log(r'/delete', 'access.log'), 'delete'
- )
+ assert self.search_in_log(r'/delete', 'access.log') is None, 'delete'
def test_access_log_change(self):
self.load('empty')
self.get()
- self.conf('"' + self.testdir + '/new.log"', 'access_log')
+ self.conf('"' + self.temp_dir + '/new.log"', 'access_log')
self.get()
self.stop()
- self.assertIsNotNone(
- self.wait_for_record(r'"GET / HTTP/1.1" 200 0 "-" "-"', 'new.log'),
- 'change',
- )
-
-if __name__ == '__main__':
- TestAccessLog.main()
+ assert (
+ self.wait_for_record(r'"GET / HTTP/1.1" 200 0 "-" "-"', 'new.log')
+ is not None
+ ), 'change'