Skip to content

Commit 6465ff2

Browse files
mthakker123Prabhakar Kumar
authored andcommitted
Python tests for server endpoints in app.py
1 parent fbb9d6a commit 6465ff2

File tree

2 files changed

+60
-2
lines changed

2 files changed

+60
-2
lines changed

jupyter_matlab_proxy/app.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,13 @@ async def termination_integration_delete(req):
149149
# End termination with 0 exit code to indicate intentional termination
150150
await req.app.shutdown()
151151
await req.app.cleanup()
152-
sys.exit(0)
152+
153+
"""When testing with pytest, its not possible to catch sys.exit(0) using the construct
154+
'with pytest.raises()', there by causing the test : test_termination_integration_delete()
155+
to fail. Inorder to avoid this, adding the below if condition to check to skip sys.exit(0) when testing
156+
"""
157+
if os.environ.get("TEST", "False").lower() != "true":
158+
sys.exit(0)
153159

154160

155161
async def root_redirect(request):

tests/test_app.py

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ async def test_matlab_proxy_web_socket(test_server):
447447
assert text.type == aiohttp.WSMsgType.CLOSED
448448

449449

450-
async def test_set_licensing_info_put(test_server):
450+
async def test_set_licensing_info_put_nlm(test_server):
451451
"""Test to check endpoint : "/set_licensing_info"
452452
453453
Test which sends HTTP PUT request with NLM licensing information.
@@ -465,6 +465,44 @@ async def test_set_licensing_info_put(test_server):
465465
assert resp.status == 200
466466

467467

468+
async def test_set_licensing_info_put_invalid_license(test_server):
469+
"""Test to check endpoint : "/set_licensing_info"
470+
471+
Test which sends HTTP PUT request with INVALID licensing information type.
472+
Args:
473+
test_server (aiohttp_client): A aiohttp_client server to send HTTP GET request.
474+
"""
475+
476+
data = {
477+
"type": "INVALID_TYPE",
478+
"status": "starting",
479+
"version": "R2020b",
480+
"connectionString": "abc@nlm",
481+
}
482+
resp = await test_server.put("/set_licensing_info", data=json.dumps(data))
483+
assert resp.status == 400
484+
485+
486+
async def test_set_licensing_info_put_mhlm(test_server):
487+
"""Test to check endpoint : "/set_licensing_info"
488+
489+
Test which sends HTTP PUT request with MHLM licensing information.
490+
Args:
491+
test_server (aiohttp_client): A aiohttp_client server to send HTTP GET request.
492+
"""
493+
494+
data = {
495+
"type": "MHLM",
496+
"status": "starting",
497+
"version": "R2020b",
498+
"token": "abc@nlm",
499+
"emailaddress": "abc@nlm",
500+
"sourceId": "abc@nlm",
501+
}
502+
resp = await test_server.put("/set_licensing_info", data=json.dumps(data))
503+
assert resp.status == 200
504+
505+
468506
async def test_set_licensing_info_delete(test_server):
469507
"""Test to check endpoint : "/set_licensing_info"
470508
@@ -477,3 +515,17 @@ async def test_set_licensing_info_delete(test_server):
477515
resp = await test_server.delete("/set_licensing_info")
478516
resp_json = json.loads(await resp.text())
479517
assert resp.status == 200 and resp_json["licensing"] is None
518+
519+
520+
async def test_set_termination_integration_delete(test_server):
521+
"""Test to check endpoint : "/terminate_integration"
522+
523+
Test which sends HTTP DELETE request to terminate integration. Checks if integration is terminated
524+
successfully.
525+
Args:
526+
test_server (aiohttp_client): A aiohttp_client server to send HTTP GET request.
527+
"""
528+
529+
resp = await test_server.delete("/terminate_integration")
530+
resp_json = json.loads(await resp.text())
531+
assert resp.status == 200 and resp_json["loadUrl"] == "../"

0 commit comments

Comments
 (0)