ue_pe_web/scripts/03_server/tests/test_server.py
2024-03-05 09:13:34 +01:00

47 lines
1.2 KiB
Python

######################################################################
# Copyright (c) Adrien Luxey-Bitri, Boris Baldassari
#
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
######################################################################
"""
Script to test the server.py module.
"""
import pytest
import requests
from threading import Thread
import _thread, signal, sys
from myserver.server import serve #, handle_client, reply
HTTP_PORT = 12345
@pytest.fixture
def start_server():
thread = Thread(target=serve, args=(HTTP_PORT, 'resources/www'))
#signal.signal( signal.SIGINT, lambda s, f : exit() )
# run the thread
thread.daemon = True
thread.start()
yield
# wait for the thread to finish
_thread.interrupt_main()
print('Waiting for the thread...')
thread.join()
return 0
def test_serve(start_server):
url = f"http://localhost:{HTTP_PORT}/"
print(f"Starting server on {url}.")
ret = start_server
print(f"Requesting url {url}.")
req = requests.get( url )
print(req)
assert 1 == 1