Skip to content

Commit

Permalink
no more FuturesSession
Browse files Browse the repository at this point in the history
  • Loading branch information
daisieh committed Oct 2, 2024
1 parent b10161c commit 453172a
Showing 1 changed file with 40 additions and 37 deletions.
77 changes: 40 additions & 37 deletions tests/test_uniform_federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ def services(requests_mock):

@pytest.fixture()
def two_servers(requests_mock):
requests_mock.post(f"{VAULT_URL}/v1/auth/approle/role/federation/secret-id", json={"data": {"secret_id": "gsfsf"}}, status_code=200)
requests_mock.post(f"{VAULT_URL}/v1/auth/approle/login", json={"auth": {"client_token": "gsfsf"}}, status_code=200)
with open(os.path.abspath("tests/test_data/two_servers.json")) as f:
servers = {"servers": json.load(f)}
requests_mock.get(f"{VAULT_URL}/v1/federation/servers", json={"data": servers}, status_code=200)
requests_mock.post(f"{VAULT_URL}/v1/auth/approle/role/federation/secret-id", json={"data": {"secret_id": "gsfsf"}}, status_code=200)
requests_mock.post(f"{VAULT_URL}/v1/auth/approle/login", json={"auth": {"client_token": "gsfsf"}}, status_code=200)


@pytest.fixture()
Expand All @@ -69,7 +69,8 @@ def get_federation_response(request_type, headers="Headers"):
endpoint_payload="",
endpoint_path=TestParams["path"],
request_dict=TestParams[headers],
endpoint_service=TestParams["service"])
endpoint_service=TestParams["service"],
unsafe=True)



Expand Down Expand Up @@ -325,23 +326,25 @@ def test_timeout_noFed_post(mock_requests, client, two_servers):

# Test the async request function --------------------------------------------------------------------

@patch('federation.FuturesSession.post', side_effect=mocked_async_requests_get)
@patch('federation.requests.post', side_effect=mocked_async_requests_get)
def test_valid_asyncRequests_two_servers_get(mock_requests, client, two_servers):
with client:
print(f"{VAULT_URL}/v1/federation/servers")
FR = get_federation_response("POST", "Federate")
resp = FR.async_requests(request='GET',
endpoint_path=TestParams["path"],
endpoint_payload="",
header=TestParams["Headers"],
endpoint_service=TestParams["service"])
print(resp)
resp = [r["response"] for r in resp.values()]
Success = list(filter(lambda x: x == 200, map(lambda a: a.status_code, resp)))

assert len(resp) == 2
assert Success == [200, 200]


@patch('federation.FuturesSession.post', side_effect=mocked_async_requests_post)
@patch('federation.requests.post', side_effect=mocked_async_requests_post)
def test_valid_asyncRequests_two_servers_post(mock_requests, client, two_servers):
with client:
FR = get_federation_response("POST")
Expand All @@ -357,7 +360,7 @@ def test_valid_asyncRequests_two_servers_post(mock_requests, client, two_servers
assert Success == [200, 200]


@patch('federation.FuturesSession.post', side_effect=exceptions.ConnectionError)
@patch('federation.requests.post', side_effect=exceptions.ConnectionError)
def test_invalid_asyncRequests_two_servers_get(mock_requests, client, two_servers):
with client:
FR = get_federation_response("POST")
Expand All @@ -374,7 +377,7 @@ def test_invalid_asyncRequests_two_servers_get(mock_requests, client, two_server
assert ConnErrs == [True, True]


@patch('federation.FuturesSession.post', side_effect=exceptions.ConnectionError)
@patch('federation.requests.post', side_effect=exceptions.ConnectionError)
def test_invalid_asyncRequests_two_servers_post(mock_requests, client, two_servers):
with client:
FR = get_federation_response("POST")
Expand All @@ -390,7 +393,7 @@ def test_invalid_asyncRequests_two_servers_post(mock_requests, client, two_serve
assert Success == [True, True]


@patch('federation.FuturesSession.post', side_effect=exceptions.Timeout)
@patch('federation.requests.post', side_effect=exceptions.Timeout)
def test_timeout_asyncRequests_two_servers_post(mock_requests, client, two_servers):
with client:
FR = get_federation_response("POST")
Expand All @@ -406,7 +409,7 @@ def test_timeout_asyncRequests_two_servers_post(mock_requests, client, two_serve
assert Success == [True, True]


@patch('federation.FuturesSession.post', side_effect=exceptions.Timeout)
@patch('federation.requests.post', side_effect=exceptions.Timeout)
def test_timeout_asyncRequests_two_servers_get(mock_requests, client, two_servers):
with client:
FR = get_federation_response("GET")
Expand All @@ -426,7 +429,7 @@ def test_timeout_asyncRequests_two_servers_get(mock_requests, client, two_server
# Test Federation with one server --------------------------------------------------------------------

@patch('federation.requests.Session.get', side_effect=mocked_service_get)
@patch('federation.FuturesSession.post', side_effect=mocked_async_requests_get)
@patch('federation.requests.post', side_effect=mocked_async_requests_get)
def test_valid_ServerRequest_one_server_get(mock_requests, mock_session, client, two_servers):
with client:
FR = get_federation_response("GET", "Federate")
Expand All @@ -438,7 +441,7 @@ def test_valid_ServerRequest_one_server_get(mock_requests, mock_session, client,


@patch('federation.requests.Session.get', side_effect=mocked_service_get)
@patch('federation.FuturesSession.post', side_effect=mocked_async_requests_get)
@patch('federation.requests.post', side_effect=mocked_async_requests_get)
def test_valid_federated_query_one_server_get(mock_requests, mock_session, client, two_servers):
with client:
with APP.app.test_request_context(
Expand All @@ -458,7 +461,7 @@ def test_valid_federated_query_one_server_get(mock_requests, mock_session, clien


@patch('federation.requests.Session.post', side_effect=mocked_service_post)
@patch('federation.FuturesSession.post', side_effect=mocked_async_requests_post)
@patch('federation.requests.post', side_effect=mocked_async_requests_post)
def test_valid_ServerRequest_one_server_post(mock_session, mock_requests, client, two_servers):
with client:
FR = get_federation_response("POST", "Federate")
Expand All @@ -471,7 +474,7 @@ def test_valid_ServerRequest_one_server_post(mock_session, mock_requests, client


@patch('federation.requests.Session.post', side_effect=mocked_service_post)
@patch('federation.FuturesSession.post', side_effect=mocked_async_requests_post)
@patch('federation.requests.post', side_effect=mocked_async_requests_post)
def test_valid_federated_query_one_server_post(mock_requests, mock_session, client, two_servers):
with client:
with APP.app.test_request_context(
Expand All @@ -493,7 +496,7 @@ def test_valid_federated_query_one_server_post(mock_requests, mock_session, clie
# Test Federation with one server, have "local" error -------------------------------------------------

@patch('federation.requests.Session.post', side_effect=mocked_service_post)
@patch('federation.FuturesSession.post', side_effect=mocked_async_local_ConnErr_requests_post)
@patch('federation.requests.post', side_effect=mocked_async_local_ConnErr_requests_post)
def test_valid_federated_local_ConnErr_one_server_post(mock_session, client, two_servers):
with client:
with APP.app.test_request_context(
Expand All @@ -513,7 +516,7 @@ def test_valid_federated_local_ConnErr_one_server_post(mock_session, client, two


@patch('federation.requests.Session.post', side_effect=mocked_service_post)
@patch('federation.FuturesSession.post', side_effect=mocked_async_local_timeout_requests_post)
@patch('federation.requests.post', side_effect=mocked_async_local_timeout_requests_post)
def test_valid_federated_local_TimeOut_one_server_post(mock_session, client, two_servers):
with client:
with APP.app.test_request_context(
Expand All @@ -535,7 +538,7 @@ def test_valid_federated_local_TimeOut_one_server_post(mock_session, client, two


@patch('federation.requests.Session.get', side_effect=mocked_service_get)
@patch('federation.FuturesSession.post', side_effect=mocked_async_local_timeout_requests_get)
@patch('federation.requests.post', side_effect=mocked_async_local_timeout_requests_get)
def test_valid_federated_local_TimeOut_one_server_get(mock_requests, mock_session, client, two_servers):
with client:
with APP.app.test_request_context(
Expand All @@ -555,7 +558,7 @@ def test_valid_federated_local_TimeOut_one_server_get(mock_requests, mock_sessio


@patch('federation.requests.Session.get', side_effect=mocked_service_get)
@patch('federation.FuturesSession.post', side_effect=mocked_async_local_ConnErr_requests_get)
@patch('federation.requests.post', side_effect=mocked_async_local_ConnErr_requests_get)
def test_valid_federated_local_ConnErr_one_server_get(mock_requests, mock_session, client, two_servers):
with client:
with APP.app.test_request_context(
Expand All @@ -578,7 +581,7 @@ def test_valid_federated_local_ConnErr_one_server_get(mock_requests, mock_sessio
# Test Federation with one server, have server error out --------------------------------------------------

@patch('federation.requests.Session.post', side_effect=mocked_service_post)
@patch('federation.FuturesSession.post', side_effect=mocked_async_p1_ConnErr_requests_post)
@patch('federation.requests.post', side_effect=mocked_async_p1_ConnErr_requests_post)
def test_ConnErr_federated_valid_local_one_server_post(mock_session, client, two_servers):
with client:
with APP.app.test_request_context(
Expand All @@ -597,7 +600,7 @@ def test_ConnErr_federated_valid_local_one_server_post(mock_session, client, two
assert server["results"] == PostResponse[loc]['results']

@patch('federation.requests.Session.post', side_effect=mocked_service_post)
@patch('federation.FuturesSession.post', side_effect=mocked_async_p1_timeout_requests_post)
@patch('federation.requests.post', side_effect=mocked_async_p1_timeout_requests_post)
def test_TimeOut_federated_valid_local_one_server_post(mock_session, client, two_servers):
with client:
with APP.app.test_request_context(
Expand All @@ -617,7 +620,7 @@ def test_TimeOut_federated_valid_local_one_server_post(mock_session, client, two


@patch('federation.requests.Session.get', side_effect=mocked_service_get)
@patch('federation.FuturesSession.post', side_effect=mocked_async_p1_ConnErr_requests_get)
@patch('federation.requests.post', side_effect=mocked_async_p1_ConnErr_requests_get)
def test_ConnErr_federated_valid_local_one_server_get(mock_requests, mock_session, client, two_servers):
with client:
with APP.app.test_request_context(
Expand All @@ -637,7 +640,7 @@ def test_ConnErr_federated_valid_local_one_server_get(mock_requests, mock_sessio


@patch('federation.requests.Session.get', side_effect=mocked_service_get)
@patch('federation.FuturesSession.post', side_effect=mocked_async_p1_ConnErr_requests_get)
@patch('federation.requests.post', side_effect=mocked_async_p1_ConnErr_requests_get)
def test_TimeOut_federated_valid_local_one_server_get(mock_requests, mock_session, client, two_servers):
with client:
with APP.app.test_request_context(
Expand All @@ -659,7 +662,7 @@ def test_TimeOut_federated_valid_local_one_server_get(mock_requests, mock_sessio


@patch('federation.requests.Session.get', side_effect=mocked_service_get)
@patch('federation.FuturesSession.post', side_effect=mocked_async_requests_get)
@patch('federation.requests.post', side_effect=mocked_async_requests_get)
def test_valid_ServerRequest_two_server_get(mock_requests, mock_session, client, three_servers):
with client:
FR = get_federation_response("GET", "Federate")
Expand All @@ -673,7 +676,7 @@ def test_valid_ServerRequest_two_server_get(mock_requests, mock_session, client,


@patch('federation.requests.Session.get', side_effect=mocked_service_get)
@patch('federation.FuturesSession.post', side_effect=mocked_async_requests_get)
@patch('federation.requests.post', side_effect=mocked_async_requests_get)
def test_valid_federated_query_two_server_get(mock_requests, mock_session, client, three_servers):
with client:
with APP.app.test_request_context(
Expand All @@ -693,7 +696,7 @@ def test_valid_federated_query_two_server_get(mock_requests, mock_session, clien


@patch('federation.requests.Session.post', side_effect=mocked_service_post)
@patch('federation.FuturesSession.post', side_effect=mocked_async_requests_post)
@patch('federation.requests.post', side_effect=mocked_async_requests_post)
def test_valid_ServerRequest_two_server_post(mock_session, mock_requests, client, three_servers):
with client:
FR = get_federation_response("POST", "Federate")
Expand All @@ -707,7 +710,7 @@ def test_valid_ServerRequest_two_server_post(mock_session, mock_requests, client


@patch('federation.requests.Session.post', side_effect=mocked_service_post)
@patch('federation.FuturesSession.post', side_effect=mocked_async_requests_post)
@patch('federation.requests.post', side_effect=mocked_async_requests_post)
def test_valid_federated_query_two_server_post(mock_requests, mock_session, client, three_servers):
with client:
with APP.app.test_request_context(
Expand All @@ -729,7 +732,7 @@ def test_valid_federated_query_two_server_post(mock_requests, mock_session, clie
# Test Federation with two nodes and local error -----------------------------------------------------

@patch('federation.requests.Session.post', side_effect=mocked_service_post)
@patch('federation.FuturesSession.post', side_effect=mocked_async_local_ConnErr_requests_post)
@patch('federation.requests.post', side_effect=mocked_async_local_ConnErr_requests_post)
def test_valid_federated_local_ConnErr_two_server_post(mock_session, client, three_servers):
with client:
with APP.app.test_request_context(
Expand All @@ -749,7 +752,7 @@ def test_valid_federated_local_ConnErr_two_server_post(mock_session, client, thr


@patch('federation.requests.Session.post', side_effect=mocked_service_post)
@patch('federation.FuturesSession.post', side_effect=mocked_async_local_timeout_requests_post)
@patch('federation.requests.post', side_effect=mocked_async_local_timeout_requests_post)
def test_valid_federated_local_TimeOut_two_server_post(mock_session, client, three_servers):
with client:
with APP.app.test_request_context(
Expand All @@ -769,7 +772,7 @@ def test_valid_federated_local_TimeOut_two_server_post(mock_session, client, thr


@patch('federation.requests.Session.get', side_effect=mocked_service_get)
@patch('federation.FuturesSession.post', side_effect=mocked_async_local_ConnErr_requests_get)
@patch('federation.requests.post', side_effect=mocked_async_local_ConnErr_requests_get)
def test_valid_federated_local_ConnErr_two_server_get(mock_requests, mock_session, client, three_servers):
with client:
with APP.app.test_request_context(
Expand All @@ -789,7 +792,7 @@ def test_valid_federated_local_ConnErr_two_server_get(mock_requests, mock_sessio


@patch('federation.requests.Session.get', side_effect=mocked_service_get)
@patch('federation.FuturesSession.post', side_effect=mocked_async_local_timeout_requests_get)
@patch('federation.requests.post', side_effect=mocked_async_local_timeout_requests_get)
def test_valid_federated_local_TimeOut_two_server_get(mock_requests, mock_session, client, three_servers):
with client:
with APP.app.test_request_context(
Expand All @@ -811,7 +814,7 @@ def test_valid_federated_local_TimeOut_two_server_get(mock_requests, mock_sessio
# Test Federation with two nodes (One timeout) and local Error -----------------------------------------------------

@patch('federation.requests.Session.post', side_effect=mocked_service_post)
@patch('federation.FuturesSession.post', side_effect=mocked_async_local_ConnErr_p1_Timeout_requests_post)
@patch('federation.requests.post', side_effect=mocked_async_local_ConnErr_p1_Timeout_requests_post)
def test_one_TimeOut_federated_local_ConnErr_two_server_post(mock_session, client, three_servers):
with client:
with APP.app.test_request_context(
Expand All @@ -831,7 +834,7 @@ def test_one_TimeOut_federated_local_ConnErr_two_server_post(mock_session, clien


@patch('federation.requests.Session.post', side_effect=mocked_service_post)
@patch('federation.FuturesSession.post', side_effect=mocked_async_local_TimeOUt_p1_Timeout_requests_post)
@patch('federation.requests.post', side_effect=mocked_async_local_TimeOUt_p1_Timeout_requests_post)
def test_one_TimeOut_federated_local_TimeOut_two_server_post(mock_session, client, three_servers):
with client:
with APP.app.test_request_context(
Expand All @@ -851,7 +854,7 @@ def test_one_TimeOut_federated_local_TimeOut_two_server_post(mock_session, clien


@patch('federation.requests.Session.get', side_effect=mocked_service_get)
@patch('federation.FuturesSession.post', side_effect=mocked_async_local_ConnErr_p1_Timeout_requests_get)
@patch('federation.requests.post', side_effect=mocked_async_local_ConnErr_p1_Timeout_requests_get)
def test_one_TimeOut_federated_local_ConnErr_two_server_get(mock_requests, mock_session, client, three_servers):
with client:
with APP.app.test_request_context(
Expand All @@ -871,7 +874,7 @@ def test_one_TimeOut_federated_local_ConnErr_two_server_get(mock_requests, mock_


@patch('federation.requests.Session.get', side_effect=mocked_service_get)
@patch('federation.FuturesSession.post', side_effect=mocked_async_local_TimeOut_p1_Timeout_requests_get)
@patch('federation.requests.post', side_effect=mocked_async_local_TimeOut_p1_Timeout_requests_get)
def test_one_TimeOut_federated_local_TimeOut_two_server_get(mock_requests, mock_session, client, three_servers):
with client:
with APP.app.test_request_context(
Expand All @@ -893,7 +896,7 @@ def test_one_TimeOut_federated_local_TimeOut_two_server_get(mock_requests, mock_
# Test Federation with two nodes (One timeout) and local valid -----------------------------------------------------

@patch('federation.requests.Session.post', side_effect=mocked_service_post)
@patch('federation.FuturesSession.post', side_effect=mocked_async_p1_timeout_requests_post)
@patch('federation.requests.post', side_effect=mocked_async_p1_timeout_requests_post)
def test_one_TimeOut_federated_valid_two_server_post(mock_session, client, three_servers):
with client:
with APP.app.test_request_context(
Expand All @@ -913,7 +916,7 @@ def test_one_TimeOut_federated_valid_two_server_post(mock_session, client, three


@patch('federation.requests.Session.post', side_effect=mocked_service_post)
@patch('federation.FuturesSession.post', side_effect=mocked_async_p1_timeout_requests_post)
@patch('federation.requests.post', side_effect=mocked_async_p1_timeout_requests_post)
def test_one_TimeOut_federated_local_valid_two_server_post(mock_session, client, three_servers):
with client:
with APP.app.test_request_context(
Expand All @@ -933,7 +936,7 @@ def test_one_TimeOut_federated_local_valid_two_server_post(mock_session, client,


@patch('federation.requests.Session.get', side_effect=mocked_service_get)
@patch('federation.FuturesSession.post', side_effect=mocked_async_p1_timeout_requests_get)
@patch('federation.requests.post', side_effect=mocked_async_p1_timeout_requests_get)
def test_one_TimeOut_federated_local_valid_two_server_get(mock_requests, mock_session, client, three_servers):
with client:
with APP.app.test_request_context(
Expand All @@ -953,7 +956,7 @@ def test_one_TimeOut_federated_local_valid_two_server_get(mock_requests, mock_se


@patch('federation.requests.Session.get', side_effect=mocked_service_get)
@patch('federation.FuturesSession.post', side_effect=mocked_async_requests_get)
@patch('federation.requests.post', side_effect=mocked_async_requests_get)
def test_invalid_backslash_endpoint_start(mock_requests, mock_session, client, two_servers):
with client:
with APP.app.test_request_context(
Expand Down

0 comments on commit 453172a

Please sign in to comment.