async def test_webgear_rtc_routes_validity(): """ Test WebGear_RTC Routes """ # add various tweaks for testing only options = { "enable_infinite_frames": False, "enable_live_broadcast": True, } # initialize WebGear_RTC app web = WebGear_RTC(source=return_testvideo_path(), logging=True) try: # modify route web.routes.clear() # test async with TestClient(web()) as client: pass except Exception as e: if isinstance(e, (RuntimeError, MediaStreamError)): pytest.xfail(str(e)) else: pytest.fail(str(e)) finally: # close web.shutdown()
def test_webgear_rtc_options(options): """ Test for various WebGear_RTC API internal options """ try: web = WebGear_RTC(source=return_testvideo_path(), logging=True, **options) client = TestClient(web(), raise_server_exceptions=True) response = client.get("/") assert response.status_code == 200 (offer_pc, data) = get_RTCPeer_payload() response_rtc_answer = client.post( "/offer", data=data, headers={"Content-Type": "application/json"}, ) params = response_rtc_answer.json() answer = RTCSessionDescription(sdp=params["sdp"], type=params["type"]) run(offer_pc.setRemoteDescription(answer)) response_rtc_offer = client.get( "/offer", data=data, headers={"Content-Type": "application/json"}, ) assert response_rtc_offer.status_code == 200 run(offer_pc.close()) web.shutdown() except Exception as e: if isinstance(e, AssertionError): logger.exception(str(e)) elif isinstance(e, requests.exceptions.Timeout): logger.exceptions(str(e)) else: pytest.fail(str(e))
def test_webgear_rtc_custom_server_generator(server, result): """ Test for WebGear_RTC API's custom source """ web = WebGear_RTC(logging=True) web.config["server"] = server client = TestClient(web(), raise_server_exceptions=True) web.shutdown()
async def test_webgear_rtc_custom_server_generator(server, result): """ Test for WebGear_RTC API's custom source """ web = WebGear_RTC(logging=True) web.config["server"] = server async with TestClient(web()) as client: pass web.shutdown()
def test_webgear_rtc_routes_validity(): # add various tweaks for testing only options = { "enable_infinite_frames": False, "enable_live_broadcast": True, } # initialize WebGear_RTC app web = WebGear_RTC(source=return_testvideo_path(), logging=True) # modify route web.routes.clear() # test client = TestClient(web(), raise_server_exceptions=True) web.shutdown()
async def test_webgear_rtc_custom_middleware(middleware, result): """ Test for WebGear_RTC API's custom middleware """ try: web = WebGear_RTC(source=return_testvideo_path(), logging=True) web.middleware = middleware async with TestClient(web()) as client: response = await client.get("/") assert response.status_code == 200 web.shutdown() except Exception as e: if result and not isinstance(e, MediaStreamError): pytest.fail(str(e))
async def test_webgear_rtc_routes(): """ Test for WebGear_RTC API's custom routes """ try: # add various performance tweaks as usual options = { "frame_size_reduction": 40, } # initialize WebGear_RTC app web = WebGear_RTC(source=return_testvideo_path(), logging=True, **options) # modify route to point our rendered webpage web.routes.append(Route("/hello", endpoint=hello_webpage)) # test async with TestClient(web()) as client: response = await client.get("/") assert response.status_code == 200 response_hello = await client.get("/hello") assert response_hello.status_code == 200 (offer_pc, data) = await get_RTCPeer_payload() response_rtc_answer = await client.post( "/offer", data=data, headers={"Content-Type": "application/json"}, ) params = response_rtc_answer.json() answer = RTCSessionDescription(sdp=params["sdp"], type=params["type"]) await offer_pc.setRemoteDescription(answer) response_rtc_offer = await client.get( "/offer", data=data, headers={"Content-Type": "application/json"}, ) assert response_rtc_offer.status_code == 200 # shutdown await offer_pc.close() web.shutdown() except Exception as e: if not isinstance(e, MediaStreamError): pytest.fail(str(e))
async def test_webgear_rtc_options(options): """ Test for various WebGear_RTC API internal options """ web = None try: web = WebGear_RTC(source=return_testvideo_path(), logging=True, **options) async with TestClient(web()) as client: response = await client.get("/") assert response.status_code == 200 if (not "enable_live_broadcast" in options or options["enable_live_broadcast"] == False): (offer_pc, data) = await get_RTCPeer_payload() response_rtc_answer = await client.post( "/offer", data=data, headers={"Content-Type": "application/json"}, ) params = response_rtc_answer.json() answer = RTCSessionDescription(sdp=params["sdp"], type=params["type"]) await offer_pc.setRemoteDescription(answer) response_rtc_offer = await client.get( "/offer", data=data, headers={"Content-Type": "application/json"}, ) assert response_rtc_offer.status_code == 200 await offer_pc.close() web.shutdown() except Exception as e: if isinstance(e, (AssertionError, MediaStreamError)): logger.exception(str(e)) elif isinstance(e, requests.exceptions.Timeout): logger.exceptions(str(e)) else: pytest.fail(str(e))
async def test_webgear_rtc_class(source, stabilize, colorspace, time_delay): """ Test for various WebGear_RTC API parameters """ try: web = WebGear_RTC( source=source, stabilize=stabilize, colorspace=colorspace, time_delay=time_delay, logging=True, ) async with TestClient(web()) as client: response = await client.get("/") assert response.status_code == 200 response_404 = await client.get("/test") assert response_404.status_code == 404 (offer_pc, data) = await get_RTCPeer_payload() response_rtc_answer = await client.post( "/offer", data=data, headers={"Content-Type": "application/json"}, ) params = response_rtc_answer.json() answer = RTCSessionDescription(sdp=params["sdp"], type=params["type"]) await offer_pc.setRemoteDescription(answer) response_rtc_offer = await client.get( "/offer", data=data, headers={"Content-Type": "application/json"}, ) assert response_rtc_offer.status_code == 200 await offer_pc.close() web.shutdown() except Exception as e: if not isinstance(e, MediaStreamError): pytest.fail(str(e))
async def test_webgear_rtc_custom_stream_class(stream_class, result): """ Test for WebGear_RTC API's custom source """ # assign your Custom Streaming Class with adequate source (for e.g. foo.mp4) # to `custom_stream` attribute in options parameter options = {"custom_stream": stream_class} try: web = WebGear_RTC(logging=True, **options) async with TestClient(web()) as client: response = await client.get("/") assert response.status_code == 200 response_404 = await client.get("/test") assert response_404.status_code == 404 (offer_pc, data) = await get_RTCPeer_payload() response_rtc_answer = await client.post( "/offer", data=data, headers={"Content-Type": "application/json"}, ) params = response_rtc_answer.json() answer = RTCSessionDescription(sdp=params["sdp"], type=params["type"]) await offer_pc.setRemoteDescription(answer) response_rtc_offer = await client.get( "/offer", data=data, headers={"Content-Type": "application/json"}, ) assert response_rtc_offer.status_code == 200 await offer_pc.close() web.shutdown() except Exception as e: if result and not isinstance(e, (ValueError, MediaStreamError)): pytest.fail(str(e)) else: pytest.xfail(str(e))
def test_webgear_rtc_class(source, stabilize, colorspace, time_delay): """ Test for various WebGear_RTC API parameters """ try: web = WebGear_RTC( source=source, stabilize=stabilize, colorspace=colorspace, time_delay=time_delay, logging=True, ) client = TestClient(web(), raise_server_exceptions=True) response = client.get("/") assert response.status_code == 200 response_404 = client.get("/test") assert response_404.status_code == 404 (offer_pc, data) = get_RTCPeer_payload() response_rtc_answer = client.post( "/offer", data=data, headers={"Content-Type": "application/json"}, ) params = response_rtc_answer.json() answer = RTCSessionDescription(sdp=params["sdp"], type=params["type"]) run(offer_pc.setRemoteDescription(answer)) response_rtc_offer = client.get( "/offer", data=data, headers={"Content-Type": "application/json"}, ) assert response_rtc_offer.status_code == 200 run(offer_pc.close()) web.shutdown() except Exception as e: pytest.fail(str(e))
async def test_webpage_reload(options): """ Test for testing WebGear_RTC API against Webpage reload disruptions """ web = WebGear_RTC(source=return_testvideo_path(), logging=True, **options) try: # run webgear_rtc async with TestClient(web()) as client: response = await client.get("/") assert response.status_code == 200 # create offer and receive (offer_pc, data) = await get_RTCPeer_payload() response_rtc_answer = await client.post( "/offer", data=data, headers={"Content-Type": "application/json"}, ) params = response_rtc_answer.json() answer = RTCSessionDescription(sdp=params["sdp"], type=params["type"]) await offer_pc.setRemoteDescription(answer) response_rtc_offer = await client.get( "/offer", data=data, headers={"Content-Type": "application/json"}, ) assert response_rtc_offer.status_code == 200 # simulate webpage reload response_rtc_reload = await client.post( "/close_connection", data="0", ) # close offer await offer_pc.close() offer_pc = None data = None # verify response logger.debug(response_rtc_reload.text) assert response_rtc_reload.text == "OK", "Test Failed!" # recreate offer and continue receive (offer_pc, data) = await get_RTCPeer_payload() response_rtc_answer = await client.post( "/offer", data=data, headers={"Content-Type": "application/json"}, ) params = response_rtc_answer.json() answer = RTCSessionDescription(sdp=params["sdp"], type=params["type"]) await offer_pc.setRemoteDescription(answer) response_rtc_offer = await client.get( "/offer", data=data, headers={"Content-Type": "application/json"}, ) assert response_rtc_offer.status_code == 200 # shutdown await offer_pc.close() except Exception as e: if "enable_live_broadcast" in options and isinstance( e, (AssertionError, MediaStreamError)): pytest.xfail("Test Passed") else: pytest.fail(str(e)) finally: web.shutdown()