Techdebt: Replace sure with regular assertions in servicediscovery (#6612)
This commit is contained in:
parent
6297361d1e
commit
2f8019052d
@ -1,5 +1,4 @@
|
||||
import json
|
||||
import sure # noqa # pylint: disable=unused-import
|
||||
|
||||
import moto.server as server
|
||||
|
||||
@ -11,5 +10,5 @@ def test_servicediscovery_list():
|
||||
headers = {"X-Amz-Target": "Route53AutoNaming_v20170314.ListNamespaces"}
|
||||
|
||||
resp = test_client.get("/", headers=headers)
|
||||
resp.status_code.should.equal(200)
|
||||
json.loads(resp.data).should.equal({"Namespaces": []})
|
||||
assert resp.status_code == 200
|
||||
assert json.loads(resp.data) == {"Namespaces": []}
|
||||
|
@ -1,9 +1,10 @@
|
||||
"""Unit tests for servicediscovery-supported APIs."""
|
||||
import boto3
|
||||
import pytest
|
||||
import sure # noqa # pylint: disable=unused-import
|
||||
import re
|
||||
|
||||
import boto3
|
||||
from botocore.exceptions import ClientError
|
||||
import pytest
|
||||
|
||||
from moto import mock_servicediscovery
|
||||
from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID
|
||||
|
||||
@ -17,21 +18,22 @@ def test_create_http_namespace():
|
||||
client.create_http_namespace(Name="mynamespace")
|
||||
|
||||
resp = client.list_namespaces()
|
||||
resp.should.have.key("Namespaces").length_of(1)
|
||||
assert len(resp["Namespaces"]) == 1
|
||||
|
||||
namespace = resp["Namespaces"][0]
|
||||
namespace.should.have.key("Id").match("ns-[a-z0-9]{16}")
|
||||
namespace.should.have.key("Arn").match(
|
||||
f"arn:aws:servicediscovery:eu-west-1:{ACCOUNT_ID}:namespace/{namespace['Id']}"
|
||||
assert re.match("ns-[a-z0-9]{16}", namespace["Id"])
|
||||
assert re.match(
|
||||
f"arn:aws:servicediscovery:eu-west-1:{ACCOUNT_ID}:namespace/{namespace['Id']}",
|
||||
namespace["Arn"],
|
||||
)
|
||||
namespace.should.have.key("Name").equals("mynamespace")
|
||||
namespace.should.have.key("Type").equals("HTTP")
|
||||
namespace.should.have.key("CreateDate")
|
||||
assert namespace["Name"] == "mynamespace"
|
||||
assert namespace["Type"] == "HTTP"
|
||||
assert "CreateDate" in namespace
|
||||
|
||||
namespace.should.have.key("Properties")
|
||||
assert "Properties" in namespace
|
||||
props = namespace["Properties"]
|
||||
props.should.have.key("DnsProperties").equals({"SOA": {}})
|
||||
props.should.have.key("HttpProperties").equals({"HttpName": "mynamespace"})
|
||||
assert props["DnsProperties"] == {"SOA": {}}
|
||||
assert props["HttpProperties"] == {"HttpName": "mynamespace"}
|
||||
|
||||
|
||||
@mock_servicediscovery
|
||||
@ -42,24 +44,25 @@ def test_get_http_namespace_minimal():
|
||||
ns_id = client.list_namespaces()["Namespaces"][0]["Id"]
|
||||
|
||||
resp = client.get_namespace(Id=ns_id)
|
||||
resp.should.have.key("Namespace")
|
||||
assert "Namespace" in resp
|
||||
|
||||
namespace = resp["Namespace"]
|
||||
namespace.should.have.key("Id").match(ns_id)
|
||||
namespace.should.have.key("Arn").match(
|
||||
f"arn:aws:servicediscovery:eu-west-1:{ACCOUNT_ID}:namespace/{namespace['Id']}"
|
||||
assert re.match(ns_id, namespace["Id"])
|
||||
assert re.match(
|
||||
f"arn:aws:servicediscovery:eu-west-1:{ACCOUNT_ID}:namespace/{namespace['Id']}",
|
||||
namespace["Arn"],
|
||||
)
|
||||
namespace.should.have.key("Name").equals("mynamespace")
|
||||
namespace.should.have.key("Type").equals("HTTP")
|
||||
namespace.should.have.key("CreateDate")
|
||||
namespace.should.have.key("CreatorRequestId")
|
||||
assert namespace["Name"] == "mynamespace"
|
||||
assert namespace["Type"] == "HTTP"
|
||||
assert "CreateDate" in namespace
|
||||
assert "CreatorRequestId" in namespace
|
||||
|
||||
namespace.should.have.key("Properties")
|
||||
assert "Properties" in namespace
|
||||
props = namespace["Properties"]
|
||||
props.should.have.key("DnsProperties").equals({"SOA": {}})
|
||||
props.should.have.key("HttpProperties").equals({"HttpName": "mynamespace"})
|
||||
assert props["DnsProperties"] == {"SOA": {}}
|
||||
assert props["HttpProperties"] == {"HttpName": "mynamespace"}
|
||||
|
||||
namespace.shouldnt.have.key("Description")
|
||||
assert "Description" not in namespace
|
||||
|
||||
|
||||
@mock_servicediscovery
|
||||
@ -72,23 +75,24 @@ def test_get_http_namespace():
|
||||
ns_id = client.list_namespaces()["Namespaces"][0]["Id"]
|
||||
|
||||
resp = client.get_namespace(Id=ns_id)
|
||||
resp.should.have.key("Namespace")
|
||||
assert "Namespace" in resp
|
||||
|
||||
namespace = resp["Namespace"]
|
||||
namespace.should.have.key("Id").match(ns_id)
|
||||
namespace.should.have.key("Arn").match(
|
||||
f"arn:aws:servicediscovery:eu-west-1:{ACCOUNT_ID}:namespace/{namespace['Id']}"
|
||||
assert re.match(ns_id, namespace["Id"])
|
||||
assert re.match(
|
||||
f"arn:aws:servicediscovery:eu-west-1:{ACCOUNT_ID}:namespace/{namespace['Id']}",
|
||||
namespace["Arn"],
|
||||
)
|
||||
namespace.should.have.key("Name").equals("mynamespace")
|
||||
namespace.should.have.key("Type").equals("HTTP")
|
||||
namespace.should.have.key("CreateDate")
|
||||
namespace.should.have.key("CreatorRequestId").equals("crid")
|
||||
namespace.should.have.key("Description").equals("mu fancy namespace")
|
||||
assert namespace["Name"] == "mynamespace"
|
||||
assert namespace["Type"] == "HTTP"
|
||||
assert "CreateDate" in namespace
|
||||
assert namespace["CreatorRequestId"] == "crid"
|
||||
assert namespace["Description"] == "mu fancy namespace"
|
||||
|
||||
namespace.should.have.key("Properties")
|
||||
assert "Properties" in namespace
|
||||
props = namespace["Properties"]
|
||||
props.should.have.key("DnsProperties").equals({"SOA": {}})
|
||||
props.should.have.key("HttpProperties").equals({"HttpName": "mynamespace"})
|
||||
assert props["DnsProperties"] == {"SOA": {}}
|
||||
assert props["HttpProperties"] == {"HttpName": "mynamespace"}
|
||||
|
||||
|
||||
@mock_servicediscovery
|
||||
@ -98,15 +102,17 @@ def test_delete_namespace():
|
||||
ns_id = client.list_namespaces()["Namespaces"][0]["Id"]
|
||||
|
||||
resp = client.delete_namespace(Id=ns_id)
|
||||
resp.should.have.key("OperationId")
|
||||
assert "OperationId" in resp
|
||||
|
||||
# Calling delete again while this is in progress results in an error:
|
||||
# Another operation of type DeleteNamespace and id dlmpkcn33aovnztwdpsdplgtheuhgcap-k6x64euq is in progress
|
||||
# list_operations is empty after successfull deletion - old operations from this namespace should be deleted
|
||||
# Another operation of type DeleteNamespace and id
|
||||
# dlmpkcn33aovnztwdpsdplgtheuhgcap-k6x64euq is in progress
|
||||
# list_operations is empty after successfull deletion - old operations
|
||||
# from this namespace should be deleted
|
||||
# list_namespaces is also empty (obvs)
|
||||
|
||||
client.list_namespaces()["Namespaces"].should.equal([])
|
||||
client.list_operations()["Operations"].should.equal([])
|
||||
assert client.list_namespaces()["Namespaces"] == []
|
||||
assert client.list_operations()["Operations"] == []
|
||||
|
||||
|
||||
@mock_servicediscovery
|
||||
@ -115,8 +121,8 @@ def test_delete_unknown_namespace():
|
||||
with pytest.raises(ClientError) as exc:
|
||||
client.delete_namespace(Id="unknown")
|
||||
err = exc.value.response["Error"]
|
||||
err["Code"].should.equal("NamespaceNotFound")
|
||||
err["Message"].should.equal("unknown")
|
||||
assert err["Code"] == "NamespaceNotFound"
|
||||
assert err["Message"] == "unknown"
|
||||
|
||||
|
||||
@mock_servicediscovery
|
||||
@ -125,8 +131,8 @@ def test_get_unknown_namespace():
|
||||
with pytest.raises(ClientError) as exc:
|
||||
client.get_namespace(Id="unknown")
|
||||
err = exc.value.response["Error"]
|
||||
err["Code"].should.equal("NamespaceNotFound")
|
||||
err["Message"].should.equal("unknown")
|
||||
assert err["Code"] == "NamespaceNotFound"
|
||||
assert err["Message"] == "unknown"
|
||||
|
||||
|
||||
@mock_servicediscovery
|
||||
@ -137,18 +143,18 @@ def test_create_private_dns_namespace_minimal():
|
||||
ns_id = client.list_namespaces()["Namespaces"][0]["Id"]
|
||||
|
||||
resp = client.get_namespace(Id=ns_id)
|
||||
resp.should.have.key("Namespace")
|
||||
assert "Namespace" in resp
|
||||
|
||||
namespace = resp["Namespace"]
|
||||
namespace.should.have.key("Id").match(ns_id)
|
||||
namespace.should.have.key("Name").equals("dns_ns")
|
||||
namespace.should.have.key("Type").equals("DNS_PRIVATE")
|
||||
assert re.match(ns_id, namespace["Id"])
|
||||
assert namespace["Name"] == "dns_ns"
|
||||
assert namespace["Type"] == "DNS_PRIVATE"
|
||||
|
||||
namespace.should.have.key("Properties")
|
||||
assert "Properties" in namespace
|
||||
props = namespace["Properties"]
|
||||
props.should.have.key("DnsProperties")
|
||||
props["DnsProperties"].should.have.key("HostedZoneId")
|
||||
props["DnsProperties"].shouldnt.have.key("SOA")
|
||||
assert "DnsProperties" in props
|
||||
assert "HostedZoneId" in props["DnsProperties"]
|
||||
assert "SOA" not in props["DnsProperties"]
|
||||
|
||||
|
||||
@mock_servicediscovery
|
||||
@ -164,19 +170,19 @@ def test_create_private_dns_namespace():
|
||||
ns_id = client.list_namespaces()["Namespaces"][0]["Id"]
|
||||
|
||||
resp = client.get_namespace(Id=ns_id)
|
||||
resp.should.have.key("Namespace")
|
||||
assert "Namespace" in resp
|
||||
|
||||
namespace = resp["Namespace"]
|
||||
namespace.should.have.key("Id").match(ns_id)
|
||||
namespace.should.have.key("Name").equals("dns_ns")
|
||||
namespace.should.have.key("Type").equals("DNS_PRIVATE")
|
||||
namespace.should.have.key("Description").equals("my private dns")
|
||||
assert re.match(ns_id, namespace["Id"])
|
||||
assert namespace["Name"] == "dns_ns"
|
||||
assert namespace["Type"] == "DNS_PRIVATE"
|
||||
assert namespace["Description"] == "my private dns"
|
||||
|
||||
namespace.should.have.key("Properties")
|
||||
assert "Properties" in namespace
|
||||
props = namespace["Properties"]
|
||||
props.should.have.key("DnsProperties")
|
||||
props["DnsProperties"].should.have.key("HostedZoneId")
|
||||
props["DnsProperties"].should.have.key("SOA").equals({"TTL": 123})
|
||||
assert "DnsProperties" in props
|
||||
assert "HostedZoneId" in props["DnsProperties"]
|
||||
assert props["DnsProperties"]["SOA"] == {"TTL": 123}
|
||||
|
||||
|
||||
@mock_servicediscovery
|
||||
@ -187,7 +193,7 @@ def test_create_private_dns_namespace_with_duplicate_vpc():
|
||||
with pytest.raises(ClientError) as exc:
|
||||
client.create_private_dns_namespace(Name="sth else", Vpc="vpc_id")
|
||||
err = exc.value.response["Error"]
|
||||
err["Code"].should.equal("ConflictingDomainExists")
|
||||
assert err["Code"] == "ConflictingDomainExists"
|
||||
|
||||
|
||||
@mock_servicediscovery
|
||||
@ -198,12 +204,12 @@ def test_create_public_dns_namespace_minimal():
|
||||
ns_id = client.list_namespaces()["Namespaces"][0]["Id"]
|
||||
|
||||
resp = client.get_namespace(Id=ns_id)
|
||||
resp.should.have.key("Namespace")
|
||||
assert "Namespace" in resp
|
||||
|
||||
namespace = resp["Namespace"]
|
||||
namespace.should.have.key("Id").match(ns_id)
|
||||
namespace.should.have.key("Name").equals("public_dns_ns")
|
||||
namespace.should.have.key("Type").equals("DNS_PUBLIC")
|
||||
assert re.match(ns_id, namespace["Id"])
|
||||
assert namespace["Name"] == "public_dns_ns"
|
||||
assert namespace["Type"] == "DNS_PUBLIC"
|
||||
|
||||
|
||||
@mock_servicediscovery
|
||||
@ -219,15 +225,15 @@ def test_create_public_dns_namespace():
|
||||
ns_id = client.list_namespaces()["Namespaces"][0]["Id"]
|
||||
|
||||
resp = client.get_namespace(Id=ns_id)
|
||||
resp.should.have.key("Namespace")
|
||||
assert "Namespace" in resp
|
||||
|
||||
namespace = resp["Namespace"]
|
||||
namespace.should.have.key("Id").match(ns_id)
|
||||
namespace.should.have.key("Name").equals("public_dns_ns")
|
||||
namespace.should.have.key("Type").equals("DNS_PUBLIC")
|
||||
namespace.should.have.key("Description").equals("my public dns")
|
||||
namespace.should.have.key("CreatorRequestId").equals("cri")
|
||||
assert re.match(ns_id, namespace["Id"])
|
||||
assert namespace["Name"] == "public_dns_ns"
|
||||
assert namespace["Type"] == "DNS_PUBLIC"
|
||||
assert namespace["Description"] == "my public dns"
|
||||
assert namespace["CreatorRequestId"] == "cri"
|
||||
|
||||
namespace.should.have.key("Properties").should.have.key("DnsProperties")
|
||||
assert "DnsProperties" in namespace["Properties"]
|
||||
dns_props = namespace["Properties"]["DnsProperties"]
|
||||
dns_props.should.equal({"HostedZoneId": "hzi", "SOA": {"TTL": 124}})
|
||||
assert dns_props == {"HostedZoneId": "hzi", "SOA": {"TTL": 124}}
|
||||
|
@ -1,9 +1,10 @@
|
||||
"""Unit tests for servicediscovery-supported APIs."""
|
||||
import boto3
|
||||
import pytest
|
||||
import sure # noqa # pylint: disable=unused-import
|
||||
import re
|
||||
|
||||
import boto3
|
||||
from botocore.exceptions import ClientError
|
||||
import pytest
|
||||
|
||||
from moto import mock_servicediscovery
|
||||
|
||||
# See our Development Tips on writing tests for hints on how to write good tests:
|
||||
@ -15,7 +16,7 @@ def test_list_operations_initial():
|
||||
client = boto3.client("servicediscovery", region_name="eu-west-1")
|
||||
resp = client.list_operations()
|
||||
|
||||
resp.should.have.key("Operations").equals([])
|
||||
assert resp["Operations"] == []
|
||||
|
||||
|
||||
@mock_servicediscovery
|
||||
@ -23,12 +24,12 @@ def test_list_operations():
|
||||
client = boto3.client("servicediscovery", region_name="eu-west-2")
|
||||
|
||||
resp = client.create_http_namespace(Name="n/a")
|
||||
resp.should.have.key("OperationId")
|
||||
assert "OperationId" in resp
|
||||
op_id = resp["OperationId"]
|
||||
|
||||
resp = client.list_operations()
|
||||
resp.should.have.key("Operations").length_of(1)
|
||||
resp["Operations"].should.equal([{"Id": op_id, "Status": "SUCCESS"}])
|
||||
assert len(resp["Operations"]) == 1
|
||||
assert resp["Operations"] == [{"Id": op_id, "Status": "SUCCESS"}]
|
||||
|
||||
|
||||
@mock_servicediscovery
|
||||
@ -36,26 +37,26 @@ def test_get_create_http_namespace_operation():
|
||||
client = boto3.client("servicediscovery", region_name="eu-west-1")
|
||||
resp = client.create_http_namespace(Name="mynamespace")
|
||||
|
||||
resp["OperationId"].should.match("[a-z0-9]{32}-[a-z0-9]{8}")
|
||||
assert re.match("[a-z0-9]{32}-[a-z0-9]{8}", resp["OperationId"])
|
||||
|
||||
operation_id = resp["OperationId"]
|
||||
|
||||
resp = client.get_operation(OperationId=operation_id)
|
||||
|
||||
resp.should.have.key("Operation")
|
||||
assert "Operation" in resp
|
||||
operation = resp["Operation"]
|
||||
operation.should.have.key("Id").equals(operation_id)
|
||||
operation.should.have.key("Type").equals("CREATE_NAMESPACE")
|
||||
operation.should.have.key("Status").equals("SUCCESS")
|
||||
operation.should.have.key("CreateDate")
|
||||
operation.should.have.key("UpdateDate")
|
||||
operation.should.have.key("Targets")
|
||||
assert operation["Id"] == operation_id
|
||||
assert operation["Type"] == "CREATE_NAMESPACE"
|
||||
assert operation["Status"] == "SUCCESS"
|
||||
assert "CreateDate" in operation
|
||||
assert "UpdateDate" in operation
|
||||
assert "Targets" in operation
|
||||
|
||||
targets = operation["Targets"]
|
||||
targets.should.have.key("NAMESPACE")
|
||||
assert "NAMESPACE" in targets
|
||||
|
||||
namespaces = client.list_namespaces()["Namespaces"]
|
||||
[ns["Id"] for ns in namespaces].should.contain(targets["NAMESPACE"])
|
||||
assert targets["NAMESPACE"] in [ns["Id"] for ns in namespaces]
|
||||
|
||||
|
||||
@mock_servicediscovery
|
||||
@ -63,20 +64,20 @@ def test_get_private_dns_namespace_operation():
|
||||
client = boto3.client("servicediscovery", region_name="eu-west-1")
|
||||
resp = client.create_private_dns_namespace(Name="dns_ns", Vpc="vpc_id")
|
||||
|
||||
resp["OperationId"].should.match("[a-z0-9]{32}-[a-z0-9]{8}")
|
||||
assert re.match("[a-z0-9]{32}-[a-z0-9]{8}", resp["OperationId"])
|
||||
|
||||
operation_id = resp["OperationId"]
|
||||
|
||||
resp = client.get_operation(OperationId=operation_id)
|
||||
|
||||
resp.should.have.key("Operation")
|
||||
assert "Operation" in resp
|
||||
operation = resp["Operation"]
|
||||
operation.should.have.key("Id").equals(operation_id)
|
||||
operation.should.have.key("Type").equals("CREATE_NAMESPACE")
|
||||
operation.should.have.key("Status").equals("SUCCESS")
|
||||
operation.should.have.key("CreateDate")
|
||||
operation.should.have.key("UpdateDate")
|
||||
operation.should.have.key("Targets")
|
||||
assert operation["Id"] == operation_id
|
||||
assert operation["Type"] == "CREATE_NAMESPACE"
|
||||
assert operation["Status"] == "SUCCESS"
|
||||
assert "CreateDate" in operation
|
||||
assert "UpdateDate" in operation
|
||||
assert "Targets" in operation
|
||||
|
||||
|
||||
@mock_servicediscovery
|
||||
@ -84,20 +85,20 @@ def test_get_public_dns_namespace_operation():
|
||||
client = boto3.client("servicediscovery", region_name="eu-west-1")
|
||||
resp = client.create_public_dns_namespace(Name="dns_ns")
|
||||
|
||||
resp["OperationId"].should.match("[a-z0-9]{32}-[a-z0-9]{8}")
|
||||
assert re.match("[a-z0-9]{32}-[a-z0-9]{8}", resp["OperationId"])
|
||||
|
||||
operation_id = resp["OperationId"]
|
||||
|
||||
resp = client.get_operation(OperationId=operation_id)
|
||||
|
||||
resp.should.have.key("Operation")
|
||||
assert "Operation" in resp
|
||||
operation = resp["Operation"]
|
||||
operation.should.have.key("Id").equals(operation_id)
|
||||
operation.should.have.key("Type").equals("CREATE_NAMESPACE")
|
||||
operation.should.have.key("Status").equals("SUCCESS")
|
||||
operation.should.have.key("CreateDate")
|
||||
operation.should.have.key("UpdateDate")
|
||||
operation.should.have.key("Targets")
|
||||
assert operation["Id"] == operation_id
|
||||
assert operation["Type"] == "CREATE_NAMESPACE"
|
||||
assert operation["Status"] == "SUCCESS"
|
||||
assert "CreateDate" in operation
|
||||
assert "UpdateDate" in operation
|
||||
assert "Targets" in operation
|
||||
|
||||
|
||||
@mock_servicediscovery
|
||||
@ -109,20 +110,20 @@ def test_get_update_service_operation():
|
||||
|
||||
resp = client.update_service(Id=service_id, Service={"Description": "updated desc"})
|
||||
|
||||
resp["OperationId"].should.match("[a-z0-9]{32}-[a-z0-9]{8}")
|
||||
assert re.match("[a-z0-9]{32}-[a-z0-9]{8}", resp["OperationId"])
|
||||
|
||||
operation_id = resp["OperationId"]
|
||||
|
||||
resp = client.get_operation(OperationId=operation_id)
|
||||
|
||||
resp.should.have.key("Operation")
|
||||
assert "Operation" in resp
|
||||
operation = resp["Operation"]
|
||||
operation.should.have.key("Id").equals(operation_id)
|
||||
operation.should.have.key("Type").equals("UPDATE_SERVICE")
|
||||
operation.should.have.key("Status").equals("SUCCESS")
|
||||
operation.should.have.key("CreateDate")
|
||||
operation.should.have.key("UpdateDate")
|
||||
operation.should.have.key("Targets")
|
||||
assert operation["Id"] == operation_id
|
||||
assert operation["Type"] == "UPDATE_SERVICE"
|
||||
assert operation["Status"] == "SUCCESS"
|
||||
assert "CreateDate" in operation
|
||||
assert "UpdateDate" in operation
|
||||
assert "Targets" in operation
|
||||
|
||||
|
||||
@mock_servicediscovery
|
||||
@ -132,4 +133,4 @@ def test_get_unknown_operation():
|
||||
with pytest.raises(ClientError) as exc:
|
||||
client.get_operation(OperationId="unknown")
|
||||
err = exc.value.response["Error"]
|
||||
err["Code"].should.equal("OperationNotFound")
|
||||
assert err["Code"] == "OperationNotFound"
|
||||
|
@ -1,9 +1,8 @@
|
||||
"""Unit tests for servicediscovery-supported APIs."""
|
||||
import boto3
|
||||
import pytest
|
||||
import sure # noqa # pylint: disable=unused-import
|
||||
|
||||
from botocore.exceptions import ClientError
|
||||
import pytest
|
||||
|
||||
from moto import mock_servicediscovery
|
||||
|
||||
# See our Development Tips on writing tests for hints on how to write good tests:
|
||||
@ -20,12 +19,12 @@ def test_create_service_minimal():
|
||||
|
||||
resp = client.create_service(Name="my service", NamespaceId=namespace_id)
|
||||
|
||||
resp.should.have.key("Service")
|
||||
resp["Service"].should.have.key("Id")
|
||||
resp["Service"].should.have.key("Arn")
|
||||
resp["Service"].should.have.key("Name").equals("my service")
|
||||
resp["Service"].should.have.key("NamespaceId").equals(namespace_id)
|
||||
resp["Service"].should.have.key("CreateDate")
|
||||
assert "Service" in resp
|
||||
assert "Id" in resp["Service"]
|
||||
assert "Arn" in resp["Service"]
|
||||
assert resp["Service"]["Name"] == "my service"
|
||||
assert resp["Service"]["NamespaceId"] == namespace_id
|
||||
assert "CreateDate" in resp["Service"]
|
||||
|
||||
|
||||
@mock_servicediscovery
|
||||
@ -50,27 +49,24 @@ def test_create_service():
|
||||
Type="HTTP",
|
||||
)
|
||||
|
||||
resp.should.have.key("Service")
|
||||
resp["Service"].should.have.key("Id")
|
||||
resp["Service"].should.have.key("Arn")
|
||||
resp["Service"].should.have.key("Name").equals("my service")
|
||||
resp["Service"].shouldnt.have.key("NamespaceId")
|
||||
resp["Service"].should.have.key("Description").equals("my service")
|
||||
resp["Service"].should.have.key("DnsConfig").equals(
|
||||
{
|
||||
"NamespaceId": namespace_id,
|
||||
"RoutingPolicy": "WEIGHTED",
|
||||
"DnsRecords": [{"Type": "SRV", "TTL": 0}],
|
||||
}
|
||||
)
|
||||
resp["Service"].should.have.key("HealthCheckConfig").equals(
|
||||
{"Type": "TCP", "ResourcePath": "/sth"}
|
||||
)
|
||||
resp["Service"].should.have.key("HealthCheckCustomConfig").equals(
|
||||
{"FailureThreshold": 125}
|
||||
)
|
||||
resp["Service"].should.have.key("Type").equals("HTTP")
|
||||
resp["Service"].should.have.key("CreatorRequestId").equals("crid")
|
||||
assert "Service" in resp
|
||||
assert "Id" in resp["Service"]
|
||||
assert "Arn" in resp["Service"]
|
||||
assert resp["Service"]["Name"] == "my service"
|
||||
assert "NamespaceId" not in resp["Service"]
|
||||
assert resp["Service"]["Description"] == "my service"
|
||||
assert resp["Service"]["DnsConfig"] == {
|
||||
"NamespaceId": namespace_id,
|
||||
"RoutingPolicy": "WEIGHTED",
|
||||
"DnsRecords": [{"Type": "SRV", "TTL": 0}],
|
||||
}
|
||||
assert resp["Service"]["HealthCheckConfig"] == {
|
||||
"Type": "TCP",
|
||||
"ResourcePath": "/sth",
|
||||
}
|
||||
assert resp["Service"]["HealthCheckCustomConfig"] == {"FailureThreshold": 125}
|
||||
assert resp["Service"]["Type"] == "HTTP"
|
||||
assert resp["Service"]["CreatorRequestId"] == "crid"
|
||||
|
||||
|
||||
@mock_servicediscovery
|
||||
@ -88,11 +84,11 @@ def test_get_service():
|
||||
|
||||
resp = client.get_service(Id=service_id)
|
||||
|
||||
resp.should.have.key("Service")
|
||||
resp["Service"].should.have.key("Id")
|
||||
resp["Service"].should.have.key("Arn")
|
||||
resp["Service"].should.have.key("Name").equals("my service")
|
||||
resp["Service"].should.have.key("NamespaceId").equals(namespace_id)
|
||||
assert "Service" in resp
|
||||
assert "Id" in resp["Service"]
|
||||
assert "Arn" in resp["Service"]
|
||||
assert resp["Service"]["Name"] == "my service"
|
||||
assert resp["Service"]["NamespaceId"] == namespace_id
|
||||
|
||||
|
||||
@mock_servicediscovery
|
||||
@ -102,8 +98,8 @@ def test_get_unknown_service():
|
||||
with pytest.raises(ClientError) as exc:
|
||||
client.get_service(Id="unknown")
|
||||
err = exc.value.response["Error"]
|
||||
err["Code"].should.equal("ServiceNotFound")
|
||||
err["Message"].should.equal("unknown")
|
||||
assert err["Code"] == "ServiceNotFound"
|
||||
assert err["Message"] == "unknown"
|
||||
|
||||
|
||||
@mock_servicediscovery
|
||||
@ -123,8 +119,8 @@ def test_delete_service():
|
||||
with pytest.raises(ClientError) as exc:
|
||||
client.get_service(Id=service_id)
|
||||
err = exc.value.response["Error"]
|
||||
err["Code"].should.equal("ServiceNotFound")
|
||||
err["Message"].should.equal(service_id)
|
||||
assert err["Code"] == "ServiceNotFound"
|
||||
assert err["Message"] == service_id
|
||||
|
||||
|
||||
@mock_servicediscovery
|
||||
@ -151,19 +147,21 @@ def test_update_service_description():
|
||||
|
||||
resp = client.get_service(Id=service_id)
|
||||
|
||||
resp.should.have.key("Service")
|
||||
resp["Service"].should.have.key("Id").equals(service_id)
|
||||
resp["Service"].should.have.key("Arn")
|
||||
resp["Service"].should.have.key("Name").equals("my service")
|
||||
resp["Service"].should.have.key("NamespaceId").equals(namespace_id)
|
||||
resp["Service"].should.have.key("Description").equals("updated desc")
|
||||
assert "Service" in resp
|
||||
assert resp["Service"]["Id"] == service_id
|
||||
assert "Arn" in resp["Service"]
|
||||
assert resp["Service"]["Name"] == "my service"
|
||||
assert resp["Service"]["NamespaceId"] == namespace_id
|
||||
assert resp["Service"]["Description"] == "updated desc"
|
||||
# From the docs:
|
||||
# If you omit any existing DnsRecords or HealthCheckConfig configurations from an UpdateService request,
|
||||
# If you omit any existing DnsRecords or HealthCheckConfig
|
||||
# configurations from an UpdateService request,
|
||||
# the configurations are deleted from the service.
|
||||
resp["Service"].shouldnt.have.key("DnsConfig")
|
||||
resp["Service"].should.have.key("HealthCheckConfig").equals(
|
||||
{"Type": "TCP", "ResourcePath": "/sth"}
|
||||
)
|
||||
assert "DnsConfig" not in resp["Service"]
|
||||
assert resp["Service"]["HealthCheckConfig"] == {
|
||||
"Type": "TCP",
|
||||
"ResourcePath": "/sth",
|
||||
}
|
||||
|
||||
|
||||
@mock_servicediscovery
|
||||
@ -194,15 +192,16 @@ def test_update_service_others():
|
||||
|
||||
resp = client.get_service(Id=service_id)
|
||||
|
||||
resp.should.have.key("Service")
|
||||
resp["Service"].should.have.key("Id").equals(service_id)
|
||||
resp["Service"].should.have.key("Arn")
|
||||
resp["Service"].should.have.key("Name").equals("my service")
|
||||
resp["Service"].should.have.key("NamespaceId").equals(namespace_id)
|
||||
resp["Service"].should.have.key("Description").equals("first desc")
|
||||
resp["Service"].should.have.key("DnsConfig").equals(
|
||||
assert "Service" in resp
|
||||
assert resp["Service"]["Id"] == service_id
|
||||
assert "Arn" in resp["Service"]
|
||||
assert resp["Service"]["Name"] == "my service"
|
||||
assert resp["Service"]["NamespaceId"] == namespace_id
|
||||
assert resp["Service"]["Description"] == "first desc"
|
||||
assert resp["Service"]["DnsConfig"] == (
|
||||
{"RoutingPolicy": "WEIGHTED", "DnsRecords": [{"Type": "SRV", "TTL": 12}]}
|
||||
)
|
||||
resp["Service"].should.have.key("HealthCheckConfig").equals(
|
||||
{"Type": "TCP", "ResourcePath": "/sth"}
|
||||
)
|
||||
assert resp["Service"]["HealthCheckConfig"] == {
|
||||
"Type": "TCP",
|
||||
"ResourcePath": "/sth",
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
"""Unit tests for servicediscovery-supported APIs."""
|
||||
import boto3
|
||||
|
||||
import sure # noqa # pylint: disable=unused-import
|
||||
from moto import mock_servicediscovery
|
||||
|
||||
# See our Development Tips on writing tests for hints on how to write good tests:
|
||||
@ -18,9 +17,9 @@ def test_create_http_namespace_with_tags():
|
||||
ns_arn = client.list_namespaces()["Namespaces"][0]["Arn"]
|
||||
|
||||
resp = client.list_tags_for_resource(ResourceARN=ns_arn)
|
||||
resp.should.have.key("Tags")
|
||||
assert "Tags" in resp
|
||||
|
||||
resp["Tags"].should.equal([{"Key": "key1", "Value": "val1"}])
|
||||
assert resp["Tags"] == [{"Key": "key1", "Value": "val1"}]
|
||||
|
||||
|
||||
@mock_servicediscovery
|
||||
@ -33,9 +32,9 @@ def test_create_public_dns_namespace_with_tags():
|
||||
ns_arn = client.list_namespaces()["Namespaces"][0]["Arn"]
|
||||
|
||||
resp = client.list_tags_for_resource(ResourceARN=ns_arn)
|
||||
resp.should.have.key("Tags")
|
||||
assert "Tags" in resp
|
||||
|
||||
resp["Tags"].should.equal([{"Key": "key1", "Value": "val1"}])
|
||||
assert resp["Tags"] == [{"Key": "key1", "Value": "val1"}]
|
||||
|
||||
|
||||
@mock_servicediscovery
|
||||
@ -48,9 +47,9 @@ def test_create_private_dns_namespace_with_tags():
|
||||
ns_arn = client.list_namespaces()["Namespaces"][0]["Arn"]
|
||||
|
||||
resp = client.list_tags_for_resource(ResourceARN=ns_arn)
|
||||
resp.should.have.key("Tags")
|
||||
assert "Tags" in resp
|
||||
|
||||
resp["Tags"].should.equal([{"Key": "key1", "Value": "val1"}])
|
||||
assert resp["Tags"] == [{"Key": "key1", "Value": "val1"}]
|
||||
|
||||
|
||||
@mock_servicediscovery
|
||||
@ -61,9 +60,9 @@ def test_create_service_with_tags():
|
||||
ns_arn = client.list_services()["Services"][0]["Arn"]
|
||||
|
||||
resp = client.list_tags_for_resource(ResourceARN=ns_arn)
|
||||
resp.should.have.key("Tags")
|
||||
assert "Tags" in resp
|
||||
|
||||
resp["Tags"].should.equal([{"Key": "key1", "Value": "val1"}])
|
||||
assert resp["Tags"] == [{"Key": "key1", "Value": "val1"}]
|
||||
|
||||
|
||||
@mock_servicediscovery
|
||||
@ -77,11 +76,12 @@ def test_tag_resource():
|
||||
client.tag_resource(ResourceARN=ns_arn, Tags=[{"Key": "key2", "Value": "val2"}])
|
||||
|
||||
resp = client.list_tags_for_resource(ResourceARN=ns_arn)
|
||||
resp.should.have.key("Tags")
|
||||
assert "Tags" in resp
|
||||
|
||||
resp["Tags"].should.equal(
|
||||
[{"Key": "key1", "Value": "val1"}, {"Key": "key2", "Value": "val2"}]
|
||||
)
|
||||
assert resp["Tags"] == [
|
||||
{"Key": "key1", "Value": "val1"},
|
||||
{"Key": "key2", "Value": "val2"},
|
||||
]
|
||||
|
||||
|
||||
@mock_servicediscovery
|
||||
@ -98,6 +98,6 @@ def test_untag_resource():
|
||||
client.untag_resource(ResourceARN=ns_arn, TagKeys=["key1"])
|
||||
|
||||
resp = client.list_tags_for_resource(ResourceARN=ns_arn)
|
||||
resp.should.have.key("Tags")
|
||||
assert "Tags" in resp
|
||||
|
||||
resp["Tags"].should.equal([{"Key": "key2", "Value": "val2"}])
|
||||
assert resp["Tags"] == [{"Key": "key2", "Value": "val2"}]
|
||||
|
Loading…
Reference in New Issue
Block a user