Skip to content

Commit f9ff747

Browse files
committed
more unit tests
1 parent f6c2cb9 commit f9ff747

File tree

1 file changed

+74
-2
lines changed

1 file changed

+74
-2
lines changed

test/src/test_users.py

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -807,8 +807,80 @@ def test_get_mas_application_availability_error(user_utils, requests_mock):
807807

808808

809809
def test_await_mas_application_availability(user_utils, requests_mock):
810-
pass
811-
# TODO
810+
application_id = "manage"
811+
812+
# returns all possible permutations of the endpoint, until finally returning the
813+
# response that should cause the retry logic to exit
814+
return_values = [
815+
{
816+
"id": application_id,
817+
},
818+
{
819+
"available": False,
820+
},
821+
{
822+
"available": True,
823+
},
824+
{
825+
"ready": False,
826+
},
827+
{
828+
"ready": True,
829+
},
830+
{
831+
"available": False,
832+
"ready": False,
833+
},
834+
{
835+
"available": True,
836+
"ready": False,
837+
},
838+
{
839+
"available": False,
840+
"ready": True,
841+
},
842+
{
843+
"available": True,
844+
"ready": True,
845+
},
846+
]
847+
attempt = 0
848+
849+
def json_callback(request, context):
850+
nonlocal attempt
851+
nonlocal return_values
852+
ret = return_values[attempt]
853+
attempt = attempt + 1
854+
return ret
855+
856+
get = requests_mock.get(
857+
f"{MAS_API_URL}/workspaces/{MAS_WORKSPACE_ID}/applications/{application_id}",
858+
request_headers={"x-access-token": TOKEN},
859+
json=json_callback,
860+
status_code=200
861+
)
862+
863+
user_utils.await_mas_application_availability(application_id, timeout_secs=5, retry_interval_secs=0)
864+
assert get.call_count == len(return_values)
865+
866+
867+
def test_await_mas_application_availability_timeout(user_utils, requests_mock):
868+
application_id = "manage"
869+
870+
get = requests_mock.get(
871+
f"{MAS_API_URL}/workspaces/{MAS_WORKSPACE_ID}/applications/{application_id}",
872+
request_headers={"x-access-token": TOKEN},
873+
json={
874+
"available": False,
875+
"ready": False,
876+
},
877+
status_code=200
878+
)
879+
880+
with pytest.raises(Exception) as excinfo:
881+
user_utils.await_mas_application_availability(application_id, timeout_secs=1, retry_interval_secs=0.1)
882+
assert get.call_count > 1
883+
assert str(excinfo.value) == f"{application_id} did not become ready and available in time, aborting"
812884

813885

814886
def test_parse_initial_users_from_aws_secret_json(user_utils):

0 commit comments

Comments
 (0)