Skip to content

Commit

Permalink
[WIP] Enable Mocks globally, and fixing tests broken by this
Browse files Browse the repository at this point in the history
  • Loading branch information
cptanalatriste committed Dec 5, 2024
1 parent 57e5fdc commit 3f469a8
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 154 deletions.
2 changes: 1 addition & 1 deletion data_safe_haven/infrastructure/programs/sre/firewall.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ def __init__(
# send via the firewall.
#
# See https://learn.microsoft.com/en-us/azure/virtual-network/virtual-networks-udr-overview
network.Route(
self.route = network.Route(
f"{self._name}_route_via_firewall",
address_prefix="0.0.0.0/0",
next_hop_ip_address=private_ip_address,
Expand Down
19 changes: 19 additions & 0 deletions tests/infrastructure/programs/sre/conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
import pulumi
import pulumi.runtime
from pulumi_azure_native import managedidentity, network, resources
from pytest import fixture

from data_safe_haven.infrastructure.common import SREIpRanges

# Mock configuration.


class DataSafeHavenMocks(pulumi.runtime.Mocks):
def new_resource(self, args: pulumi.runtime.MockResourceArgs):
resources = [args.name + "_id", args.inputs]
return resources

def call(self, _: pulumi.runtime.MockCallArgs):
return {}


pulumi.runtime.set_mocks(
DataSafeHavenMocks(),
preview=False,
)


#
# Constants
Expand Down
76 changes: 58 additions & 18 deletions tests/infrastructure/programs/sre/test_application_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def test_props_resource_group_id(
self, application_gateway_props: SREApplicationGatewayProps
):
application_gateway_props.resource_group_id.apply(
partial(assert_equal, pulumi.UNKNOWN),
partial(assert_equal, "resource_group_id"),
run_with_unknowns=True,
)

Expand Down Expand Up @@ -112,7 +112,7 @@ def test_props_user_assigned_identities(
self, application_gateway_props: SREApplicationGatewayProps
):
application_gateway_props.user_assigned_identities.apply(
partial(assert_equal, pulumi.UNKNOWN),
partial(assert_equal, {"identity_key_vault_reader_id": {}}),
run_with_unknowns=True,
)

Expand Down Expand Up @@ -282,7 +282,7 @@ def test_application_gateway_frontend_ip_configurations(
"name": "appGatewayFrontendIP",
"private_ip_allocation_method": "Dynamic",
"provisioning_state": None,
"public_ip_address": {"id": None},
"public_ip_address": {"id": "ag-name_public_ip_id"},
"type": None,
}
],
Expand Down Expand Up @@ -356,8 +356,12 @@ def test_application_gateway_http_listeners(
[
{
"etag": None,
"frontend_ip_configuration": {"id": None},
"frontend_port": {"id": None},
"frontend_ip_configuration": {
"id": "resource_group_id/providers/Microsoft.Network/applicationGateways/stack-example-ag-entrypoint/frontendIPConfigurations/appGatewayFrontendIP"
},
"frontend_port": {
"id": "resource_group_id/providers/Microsoft.Network/applicationGateways/stack-example-ag-entrypoint/frontendPorts/appGatewayFrontendHttp"
},
"host_name": "sre.example.com",
"name": "GuacamoleHttpListener",
"protocol": "Http",
Expand All @@ -366,13 +370,19 @@ def test_application_gateway_http_listeners(
},
{
"etag": None,
"frontend_ip_configuration": {"id": None},
"frontend_port": {"id": None},
"frontend_ip_configuration": {
"id": "resource_group_id/providers/Microsoft.Network/applicationGateways/stack-example-ag-entrypoint/frontendIPConfigurations/appGatewayFrontendIP"
},
"frontend_port": {
"id": "resource_group_id/providers/Microsoft.Network/applicationGateways/stack-example-ag-entrypoint/frontendPorts/appGatewayFrontendHttps"
},
"host_name": "sre.example.com",
"name": "GuacamoleHttpsListener",
"protocol": "Https",
"provisioning_state": None,
"ssl_certificate": {"id": None},
"ssl_certificate": {
"id": "resource_group_id/providers/Microsoft.Network/applicationGateways/stack-example-ag-entrypoint/sslCertificates/letsencryptcertificate"
},
"type": None,
},
],
Expand All @@ -387,7 +397,17 @@ def test_application_gateway_identity(
application_gateway_component.application_gateway.identity.apply(
partial(
assert_equal_json,
{"principal_id": None, "tenant_id": None, "type": "UserAssigned"},
{
"principal_id": None,
"tenant_id": None,
"type": "UserAssigned",
"user_assigned_identities": {
"identity_key_vault_reader_id": {
"client_id": None,
"principal_id": None,
}
},
},
),
run_with_unknowns=True,
)
Expand Down Expand Up @@ -489,8 +509,14 @@ def test_application_gateway_redirect_configurations(
"include_query_string": True,
"name": "GuacamoleHttpToHttpsRedirection",
"redirect_type": "Permanent",
"request_routing_rules": [{"id": None}],
"target_listener": {"id": None},
"request_routing_rules": [
{
"id": "resource_group_id/providers/Microsoft.Network/applicationGateways/stack-example-ag-entrypoint/requestRoutingRules/HttpToHttpsRedirection"
}
],
"target_listener": {
"id": "resource_group_id/providers/Microsoft.Network/applicationGateways/stack-example-ag-entrypoint/httpListeners/GuacamoleHttpsListener"
},
"type": None,
}
],
Expand All @@ -508,24 +534,38 @@ def test_application_gateway_request_routing_rules(
[
{
"etag": None,
"http_listener": {"id": None},
"http_listener": {
"id": "resource_group_id/providers/Microsoft.Network/applicationGateways/stack-example-ag-entrypoint/httpListeners/GuacamoleHttpListener"
},
"name": "GuacamoleHttpRouting",
"priority": 200,
"provisioning_state": None,
"redirect_configuration": {"id": None},
"rewrite_rule_set": {"id": None},
"redirect_configuration": {
"id": "resource_group_id/providers/Microsoft.Network/applicationGateways/stack-example-ag-entrypoint/redirectConfigurations/GuacamoleHttpToHttpsRedirection"
},
"rewrite_rule_set": {
"id": "resource_group_id/providers/Microsoft.Network/applicationGateways/stack-example-ag-entrypoint/rewriteRuleSets/ResponseHeaders"
},
"rule_type": "Basic",
"type": None,
},
{
"backend_address_pool": {"id": None},
"backend_http_settings": {"id": None},
"backend_address_pool": {
"id": "resource_group_id/providers/Microsoft.Network/applicationGateways/stack-example-ag-entrypoint/backendAddressPools/appGatewayBackendGuacamole"
},
"backend_http_settings": {
"id": "resource_group_id/providers/Microsoft.Network/applicationGateways/stack-example-ag-entrypoint/backendHttpSettingsCollection/appGatewayBackendHttpSettings"
},
"etag": None,
"http_listener": {"id": None},
"http_listener": {
"id": "resource_group_id/providers/Microsoft.Network/applicationGateways/stack-example-ag-entrypoint/httpListeners/GuacamoleHttpsListener"
},
"name": "GuacamoleHttpsRouting",
"priority": 100,
"provisioning_state": None,
"rewrite_rule_set": {"id": None},
"rewrite_rule_set": {
"id": "resource_group_id/providers/Microsoft.Network/applicationGateways/stack-example-ag-entrypoint/rewriteRuleSets/ResponseHeaders"
},
"rule_type": "Basic",
"type": None,
},
Expand Down
Loading

0 comments on commit 3f469a8

Please sign in to comment.