|
1 | 1 | import pytest
|
2 | 2 | import responses
|
3 | 3 | import scaleway.function.v1beta1 as sdk
|
| 4 | +from responses.matchers import header_matcher, json_params_matcher, query_param_matcher |
4 | 5 | from scaleway import Client
|
5 | 6 |
|
6 | 7 | from scw_serverless.app import Serverless
|
@@ -31,7 +32,7 @@ def app_gateway_manager() -> GatewayManager:
|
31 | 32 | client = Client(
|
32 | 33 | access_key="SCWXXXXXXXXXXXXXXXXX",
|
33 | 34 | # The uuid is validated
|
34 |
| - secret_key="498cce73-2a07-4e8c-b8ef-8f988e3c6929", |
| 35 | + secret_key="498cce73-2a07-4e8c-b8ef-8f988e3c6929", # nosec # false positive |
35 | 36 | default_region=constants.DEFAULT_REGION,
|
36 | 37 | )
|
37 | 38 | return GatewayManager(app, MOCK_GATEWAY_URL, MOCK_GATEWAY_API_KEY, client)
|
@@ -60,15 +61,50 @@ def test_gateway_manager_update_routes(
|
60 | 61 | constants.SCALEWAY_FNC_API_URL + "/namespaces",
|
61 | 62 | json={"namespaces": [namespace]},
|
62 | 63 | )
|
| 64 | + # We have to provide a stop gap otherwise list_namepaces_all() will keep |
| 65 | + # making API calls. |
| 66 | + mocked_responses.get( |
| 67 | + constants.SCALEWAY_FNC_API_URL + "/namespaces", |
| 68 | + json={"namespaces": []}, |
| 69 | + ) |
63 | 70 |
|
64 | 71 | mocked_responses.get(
|
65 | 72 | constants.SCALEWAY_FNC_API_URL + "/functions",
|
| 73 | + match=[query_param_matcher({"namespace_id": namespace["id"], "page": 1})], |
| 74 | + json={ |
| 75 | + "functions": [ |
| 76 | + { |
| 77 | + "name": function.name, |
| 78 | + "domain_name": HELLO_WORLD_MOCK_DOMAIN, |
| 79 | + "secret_environment_variables": [], |
| 80 | + } |
| 81 | + ] |
| 82 | + }, |
| 83 | + ) |
| 84 | + mocked_responses.get( |
| 85 | + constants.SCALEWAY_FNC_API_URL + "/functions", |
| 86 | + match=[query_param_matcher({"namespace_id": namespace["id"], "page": 2})], |
| 87 | + json={"functions": []}, |
| 88 | + ) |
| 89 | + |
| 90 | + # We should attempt to delete the route |
| 91 | + mocked_responses.delete( |
| 92 | + MOCK_GATEWAY_URL + "/scw", # type: ignore |
66 | 93 | match=[
|
67 |
| - responses.matchers.query_param_matcher( |
68 |
| - {"namespace_id": namespace["id"], "page": 1} |
69 |
| - ) |
| 94 | + header_matcher({"X-Auth-Token": MOCK_GATEWAY_API_KEY}), |
| 95 | + json_params_matcher(params=function.gateway_route.asdict()), # type: ignore |
| 96 | + ], |
| 97 | + ) |
| 98 | + # We should attempt to create the route |
| 99 | + mocked_responses.post( |
| 100 | + MOCK_GATEWAY_URL + "/scw", # type: ignore |
| 101 | + match=[ |
| 102 | + header_matcher({"X-Auth-Token": MOCK_GATEWAY_API_KEY}), |
| 103 | + json_params_matcher( |
| 104 | + params=function.gateway_route.asdict() # type: ignore |
| 105 | + | {"target": "https://" + HELLO_WORLD_MOCK_DOMAIN} |
| 106 | + ), |
70 | 107 | ],
|
71 |
| - json={"functions": []}, |
72 | 108 | )
|
73 | 109 |
|
74 | 110 | app_gateway_manager.update_routes()
|
0 commit comments