test_php_application.py (1848:4bd548074e2c) test_php_application.py (1850:839024ce4a6a)
1import os
2import re
3import shutil
1import os
2import re
3import shutil
4import signal
4import time
5import time
5from subprocess import call
6
7import pytest
8
9from unit.applications.lang.php import TestApplicationPHP
10from unit.option import option
11
12
13class TestPHPApplication(TestApplicationPHP):

--- 76 unchanged lines hidden (view full) ---

90 def test_php_application_query_string_empty(self):
91 self.load('query_string')
92
93 resp = self.get(url='/?')
94
95 assert resp['status'] == 200, 'query string empty status'
96 assert resp['headers']['Query-String'] == '', 'query string empty'
97
6
7import pytest
8
9from unit.applications.lang.php import TestApplicationPHP
10from unit.option import option
11
12
13class TestPHPApplication(TestApplicationPHP):

--- 76 unchanged lines hidden (view full) ---

90 def test_php_application_query_string_empty(self):
91 self.load('query_string')
92
93 resp = self.get(url='/?')
94
95 assert resp['status'] == 200, 'query string empty status'
96 assert resp['headers']['Query-String'] == '', 'query string empty'
97
98 def test_php_application_fastcgi_finish_request(self, temp_dir):
98 def test_php_application_fastcgi_finish_request(self, unit_pid):
99 self.load('fastcgi_finish_request')
100
101 assert self.get()['body'] == '0123'
102
99 self.load('fastcgi_finish_request')
100
101 assert self.get()['body'] == '0123'
102
103 with open(temp_dir + '/unit.pid', 'r') as f:
104 pid = f.read().rstrip()
103 os.kill(unit_pid, signal.SIGUSR1);
105
104
106 call(['kill', '-s', 'USR1', pid])
105 errs = self.findall(r'Error in fastcgi_finish_request')
107
106
108 with open(temp_dir + '/unit.log', 'r', errors='ignore') as f:
109 errs = re.findall(r'Error in fastcgi_finish_request', f.read())
107 assert len(errs) == 0, 'no error'
110
108
111 assert len(errs) == 0, 'no error'
112
113 def test_php_application_fastcgi_finish_request_2(self, temp_dir):
109 def test_php_application_fastcgi_finish_request_2(self, unit_pid):
114 self.load('fastcgi_finish_request')
115
116 resp = self.get(url='/?skip')
117 assert resp['status'] == 200
118 assert resp['body'] == ''
119
110 self.load('fastcgi_finish_request')
111
112 resp = self.get(url='/?skip')
113 assert resp['status'] == 200
114 assert resp['body'] == ''
115
120 with open(temp_dir + '/unit.pid', 'r') as f:
121 pid = f.read().rstrip()
116 os.kill(unit_pid, signal.SIGUSR1);
122
117
123 call(['kill', '-s', 'USR1', pid])
118 errs = self.findall(r'Error in fastcgi_finish_request')
124
119
125 with open(temp_dir + '/unit.log', 'r', errors='ignore') as f:
126 errs = re.findall(r'Error in fastcgi_finish_request', f.read())
120 assert len(errs) == 0, 'no error'
127
121
128 assert len(errs) == 0, 'no error'
129
130 def test_php_application_query_string_absent(self):
131 self.load('query_string')
132
133 resp = self.get()
134
135 assert resp['status'] == 200, 'query string absent status'
136 assert resp['headers']['Query-String'] == '', 'query string absent'
137

--- 395 unchanged lines hidden (view full) ---

533 {"user": {"disable_classes": "DateTime"}},
534 'applications/date_time/options',
535 )
536
537 assert not re.search(
538 r'012345', self.get()['body']
539 ), 'disable_classes before'
540
122 def test_php_application_query_string_absent(self):
123 self.load('query_string')
124
125 resp = self.get()
126
127 assert resp['status'] == 200, 'query string absent status'
128 assert resp['headers']['Query-String'] == '', 'query string absent'
129

--- 395 unchanged lines hidden (view full) ---

525 {"user": {"disable_classes": "DateTime"}},
526 'applications/date_time/options',
527 )
528
529 assert not re.search(
530 r'012345', self.get()['body']
531 ), 'disable_classes before'
532
541 def test_php_application_error_log(self, temp_dir):
533 def test_php_application_error_log(self):
542 self.load('error_log')
543
544 assert self.get()['status'] == 200, 'status'
545
546 time.sleep(1)
547
548 assert self.get()['status'] == 200, 'status 2'
549
550 pattern = r'\d{4}\/\d\d\/\d\d\s\d\d:.+\[notice\].+Error in application'
551
552 assert self.wait_for_record(pattern) is not None, 'errors print'
553
534 self.load('error_log')
535
536 assert self.get()['status'] == 200, 'status'
537
538 time.sleep(1)
539
540 assert self.get()['status'] == 200, 'status 2'
541
542 pattern = r'\d{4}\/\d\d\/\d\d\s\d\d:.+\[notice\].+Error in application'
543
544 assert self.wait_for_record(pattern) is not None, 'errors print'
545
554 with open(temp_dir + '/unit.log', 'r', errors='ignore') as f:
555 errs = re.findall(pattern, f.read())
546 errs = self.findall(pattern)
556
547
557 assert len(errs) == 2, 'error_log count'
548 assert len(errs) == 2, 'error_log count'
558
549
559 date = errs[0].split('[')[0]
560 date2 = errs[1].split('[')[0]
561 assert date != date2, 'date diff'
550 date = errs[0].split('[')[0]
551 date2 = errs[1].split('[')[0]
552 assert date != date2, 'date diff'
562
563 def test_php_application_script(self):
564 assert 'success' in self.conf(
565 {
566 "listeners": {"*:7080": {"pass": "applications/script"}},
567 "applications": {
568 "script": {
569 "type": "php",

--- 146 unchanged lines hidden ---
553
554 def test_php_application_script(self):
555 assert 'success' in self.conf(
556 {
557 "listeners": {"*:7080": {"pass": "applications/script"}},
558 "applications": {
559 "script": {
560 "type": "php",

--- 146 unchanged lines hidden ---