aboutsummaryrefslogtreecommitdiffstats
path: root/tests/dcaegen2/bbs-testcases/resources/simulator/httpServerLib.py
diff options
context:
space:
mode:
authorStavros Kanarakis <stavros.kanarakis@nokia.com>2019-03-27 19:11:43 +0200
committerStavros Kanarakis <stavros.kanarakis@nokia.com>2019-04-05 09:25:54 +0300
commit40c1ddcef93d169922cdb2b95a817e2ff50a25ce (patch)
treeec9851ef03e7f9f25279fc081f2b317e10389630 /tests/dcaegen2/bbs-testcases/resources/simulator/httpServerLib.py
parent7aa8cd32c8458cd9a148ca8dad4c26635cab6d8b (diff)
CSIT tests for bbs-event-processor
Change-Id: Iaf4d5f47754489b111a0af90bf3cdf819d4e62f7 Issue-ID: DCAEGEN2-1355 Signed-off-by: Stavros Kanarakis <stavros.kanarakis@nokia.com>
Diffstat (limited to 'tests/dcaegen2/bbs-testcases/resources/simulator/httpServerLib.py')
-rw-r--r--tests/dcaegen2/bbs-testcases/resources/simulator/httpServerLib.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/dcaegen2/bbs-testcases/resources/simulator/httpServerLib.py b/tests/dcaegen2/bbs-testcases/resources/simulator/httpServerLib.py
new file mode 100644
index 00000000..d963169d
--- /dev/null
+++ b/tests/dcaegen2/bbs-testcases/resources/simulator/httpServerLib.py
@@ -0,0 +1,37 @@
+import _thread
+import ssl
+from http.server import HTTPServer
+
+
+def header_200_and_json(self):
+ self.send_response(200)
+ self.send_header('Content-Type', 'application/json')
+ self.end_headers()
+
+def header_404_and_json(self):
+ self.send_response(404)
+ self.send_header('Content-Type', 'application/json')
+ self.end_headers()
+
+def start_http_endpoint(port, handler_class):
+ _thread.start_new_thread(init_http_endpoints, (port, handler_class))
+
+
+def start_https_endpoint(port, handler_class, keyfile, certfile, ca_certs):
+ _thread.start_new_thread(init_https_endpoints, (port, handler_class, keyfile, certfile, ca_certs))
+
+
+def init_http_endpoints(port, handler_class, server_class=HTTPServer):
+ server = server_class(('', port), handler_class)
+ sa = server.socket.getsockname()
+ print("Serving HTTP on", sa[0], "port", sa[1], "for", handler_class, "...")
+ server.serve_forever()
+
+
+def init_https_endpoints(port, handler_class, keyfile, certfile, ca_certs, server_class=HTTPServer):
+ server = server_class(('', port), handler_class)
+ server.socket = ssl.wrap_socket(server.socket, keyfile=keyfile, certfile=certfile,
+ ca_certs=ca_certs, server_side=True)
+ sa = server.socket.getsockname()
+ print("Serving HTTPS on", sa[0], "port", sa[1], "for", handler_class, "...")
+ server.serve_forever()