remove cgi

This commit is contained in:
stubbfel
2015-03-31 22:06:24 +02:00
parent 63f3957e0d
commit 705876d6d5
17 changed files with 78 additions and 198 deletions

View File

@@ -1,10 +0,0 @@
#!/usr/bin/env python3
__author__ = 'dev'
response_file_path = "cgi-bin/test.html"
response_file = open(response_file_path, "r")
response_file_content = response_file.read()
response_file.close()
print("\n")
print(response_file_content)

View File

@@ -1,9 +0,0 @@
#!/usr/bin/env python3
print("""
<html>
<Title>Hello in HTML</Title>
<body>
<p>Hello There!</p>
<p><b>Hi There!</b></p>
</body>
</html> """)

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="ISO8859-1" ?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

View File

@@ -1,15 +0,0 @@
#!/usr/bin/env python3
__author__ = 'dev'
import cgi
from fake_services.service.webservice.fake_http_request_handler import RESPONSE_PATH_PARAMETER_KEY_NAME
response_file_path = cgi.FieldStorage()[RESPONSE_PATH_PARAMETER_KEY_NAME].value
response_file = open(response_file_path, "r")
response_file_content = response_file.read()
response_file.close()
print("\n")
print(response_file_content)

View File

@@ -1,15 +0,0 @@
#!/usr/bin/env python3
__author__ = 'dev'
import cgi
from fake_services.service.webservice.fake_http_request_handler import RESPONSE_PATH_PARAMETER_KEY_NAME
response_file_path = cgi.FieldStorage()[RESPONSE_PATH_PARAMETER_KEY_NAME].value
response_file = open(response_file_path, "r")
response_file_content = response_file.read()
response_file.close()
print("\n")
print(response_file_content)

View File

@@ -1,9 +0,0 @@
{
"":
{
"host_pattern": "10.0.0.1",
"path_pattern": "index.php",
"protocol_pattern": "http",
"response_content_path": "cgi-bin/test.html"
}
}

View File

@@ -1,7 +1,6 @@
__author__ = 'dev'
import os
import stat
import unittest
import urllib.request
import urllib.parse
@@ -48,48 +47,18 @@ class TestFakeSever(unittest.TestCase):
except:
pass
def test_moved_request(self):
server = FakeWebServerManager(server_port=SERVER_PORT, request_handle_script_path=CGI_TEST_SCRIPT_PATH, requests_config=DEFAULT_CONFIG)
server.start_server()
content = urllib.request.urlopen(TEST_URL).read().decode('utf-8')
content2 = urllib.request.urlopen(TEST_URL_EXPAND).read().decode('utf-8')
server.stop_server()
self.assertNotEqual("", content)
self.assertEqual(content, content2)
self.assertFalse(content.startswith("#"))
def test_not_found_script(self):
self.assertRaises(FileNotFoundError, FakeWebServerManager, SERVER_PORT, None, CGI_WRONG_SCRIPT_PATH)
FakeWebServerManager(server_port=SERVER_PORT)
def test_set_executable(self):
st = os.stat(CGI_FILE_SCRIPT_PATH)
if os.access(CGI_FILE_SCRIPT_PATH, os.X_OK):
os.chmod(CGI_FILE_SCRIPT_PATH, st.st_mode ^ stat.S_IEXEC)
self.assertFalse(os.access(CGI_FILE_SCRIPT_PATH, os.X_OK))
FakeWebServerManager(server_port=SERVER_PORT, request_handle_script_path=CGI_FILE_SCRIPT_PATH, requests_config=DEFAULT_CONFIG)
self.assertTrue(os.access(CGI_FILE_SCRIPT_PATH, os.X_OK))
def test_file_request(self):
server = FakeWebServerManager(server_port=SERVER_PORT, request_handle_script_path=CGI_FILE_SCRIPT_PATH, requests_config=DEFAULT_CONFIG)
server = FakeWebServerManager(server_port=SERVER_PORT, requests_config=DEFAULT_CONFIG)
server.start_server()
content = urllib.request.urlopen(TEST_URL).read().decode('utf-8')
content2 = urllib.request.urlopen(TEST_URL_EXPAND).read().decode('utf-8')
server.stop_server()
self.assertNotEqual("", content)
self.assertEqual(content, content2)
self.assertFalse(content.startswith("#"))
def test_file_var_bin_request(self):
server = FakeWebServerManager(server_port=SERVER_PORT, request_handle_script_path=CGI_FILE_SCRIPT_PATH, requests_config=DEFAULT_CONFIG)
server.start_server()
content = urllib.request.urlopen(TEST_URL_EXPAND).read().decode('utf-8')
server.stop_server()
self.assertNotEqual("", content)
self.assertNotEqual(content, content2)
self.assertFalse(content.startswith("#"))
def test_file_var_bin_request_post(self):
server = FakeWebServerManager(server_port=SERVER_PORT, request_handle_script_path=CGI_FILE_SCRIPT_PATH, requests_config=DEFAULT_CONFIG)
server = FakeWebServerManager(server_port=SERVER_PORT, requests_config=DEFAULT_CONFIG)
server.start_server()
content = urllib.request.urlopen(TEST_URL_EXPAND).read().decode('utf-8')
data = urllib.parse.urlencode({'q': 'Status'})
@@ -100,57 +69,6 @@ class TestFakeSever(unittest.TestCase):
self.assertFalse(content.startswith("#"))
self.assertEqual(content, content2)
def test_config_request(self):
config = {
"/test_request":
[
{
"host_pattern": "10.0.0.1",
"response_content_path": "cgi-bin/test.html"
}
],
"/1/a/3/foo/bar.php":
[
{
"host_pattern": "^0.0.0.0$",
"response_content_path": "cgi-bin/testA.html"
},
{
"host_pattern": "0.0.0.0:8080",
"response_content_path": "cgi-bin/testB.html"
},
{
"response_content_path": "cgi-bin/testC.html"
}
]
}
server = FakeWebServerManager(server_port=SERVER_PORT, requests_config=config,
request_handle_script_path=CGI_VAR_BIN_SCRIPT_PATH)
server.start_server()
content = urllib.request.urlopen(TEST_URL_EXPAND).read().decode('utf-8')
server.stop_server()
self.assertNotEqual("", content)
self.assertFalse(content.startswith("#"))
def test_config_request_default_script(self):
path = os.path.abspath("cgi-bin/testA.html")
config = {
"/1/a/3/foo/bar.php":
[
{
"response_content_path": path
}
]
}
server = FakeWebServerManager(server_port=SERVER_PORT, requests_config=config)
server.start_server()
content = urllib.request.urlopen(TEST_URL_EXPAND).read().decode('utf-8')
server.stop_server()
self.assertNotEqual("", content)
self.assertFalse(content.startswith("#"))
if __name__ == '__main__':
unittest.main()