diff --git a/moto/rds2/models.py b/moto/rds2/models.py
index ad2f9b3f1..846d070ab 100644
--- a/moto/rds2/models.py
+++ b/moto/rds2/models.py
@@ -339,6 +339,29 @@ class SubnetGroup(object):
""")
return template.render(subnet_group=self)
+ def to_json(self):
+ template = Template("""{
+ "DBSubnetGroup": {
+ "VpcId": "{{ subnet_group.vpc_id }}",
+ "SubnetGroupStatus": "{{ subnet_group.status }}",
+ "DBSubnetGroupDescription": "{{ subnet_group.description }}",
+ "DBSubnetGroupName": "{{ subnet_group.subnet_name }}",
+ "Subnets": {
+ "Subnet": [
+ {% for subnet in subnet_group.subnets %}{
+ "SubnetStatus": "Active",
+ "SubnetIdentifier": "{{ subnet.id }}",
+ "SubnetAvailabilityZone": {
+ "Name": "{{ subnet.availability_zone }}",
+ "ProvisionedIopsCapable": "false"
+ }
+ }{%- if not loop.last -%},{%- endif -%}{% endfor %}
+ ]
+ }
+ }
+ }""")
+ return template.render(subnet_group=self)
+
@classmethod
def create_from_cloudformation_json(cls, resource_name, cloudformation_json, region_name):
properties = cloudformation_json['Properties']
diff --git a/moto/rds2/responses.py b/moto/rds2/responses.py
index 918de9969..f013be0f4 100644
--- a/moto/rds2/responses.py
+++ b/moto/rds2/responses.py
@@ -139,7 +139,6 @@ class RDS2Response(BaseResponse):
template = self.response_template(AUTHORIZE_SECURITY_GROUP_TEMPLATE)
return template.render(security_group=security_group)
- # TODO: Update function to new method
def create_dbsubnet_group(self):
subnet_name = self._get_param('DBSubnetGroupName')
description = self._get_param('DBSubnetGroupDescription')
@@ -149,7 +148,6 @@ class RDS2Response(BaseResponse):
template = self.response_template(CREATE_SUBNET_GROUP_TEMPLATE)
return template.render(subnet_group=subnet_group)
- # TODO: Update function to new method
def describe_dbsubnet_groups(self):
subnet_name = self._get_param('DBSubnetGroupName')
subnet_groups = self.backend.describe_subnet_groups(subnet_name)
@@ -303,27 +301,28 @@ AUTHORIZE_SECURITY_GROUP_TEMPLATE = """
"""
-CREATE_SUBNET_GROUP_TEMPLATE = """
-
- {{ subnet_group.to_xml() }}
-
-
- 3a401b3f-bb9e-11d3-f4c6-37db295f7674
-
-"""
+CREATE_SUBNET_GROUP_TEMPLATE = """{
+ "CreateDBSubnetGroupResponse": {
+ "CreateDBSubnetGroupResult":
+ {{ subnet_group.to_json() }},
+ "ResponseMetadata": { "RequestId": "3a401b3f-bb9e-11d3-f4c6-37db295f7674" }
+ }
+}"""
+
+DESCRIBE_SUBNET_GROUPS_TEMPLATE = """{
+ "DescribeDBSubnetGroupsResponse": {
+ "DescribeDBSubnetGroupsResult": {
+ "DBSubnetGroups": [
+ {% for subnet_group in subnet_groups %}
+ {{ subnet_group.to_json() }}{%- if not loop.last -%},{%- endif -%}
+ {% endfor %}
+ ],
+ "Marker": null
+ },
+ "ResponseMetadata": { "RequestId": "b783db3b-b98c-11d3-fbc7-5c0aad74da7c" }
+ }
+}"""
-DESCRIBE_SUBNET_GROUPS_TEMPLATE = """
-
-
- {% for subnet_group in subnet_groups %}
- {{ subnet_group.to_xml() }}
- {% endfor %}
-
-
-
- b783db3b-b98c-11d3-fbc7-5c0aad74da7c
-
-"""
DELETE_SUBNET_GROUP_TEMPLATE = """
diff --git a/moto/rds2/urls.py b/moto/rds2/urls.py
index 3c8a129a8..d21084766 100644
--- a/moto/rds2/urls.py
+++ b/moto/rds2/urls.py
@@ -3,6 +3,7 @@ from .responses import RDS2Response
url_bases = [
"https?://rds.(.+).amazonaws.com",
+ "https?://rds.amazonaws.com",
]
url_paths = {
diff --git a/tests/test_rds2/test_rds2.py b/tests/test_rds2/test_rds2.py
index e2801c1c7..40e3d24b2 100644
--- a/tests/test_rds2/test_rds2.py
+++ b/tests/test_rds2/test_rds2.py
@@ -322,21 +322,31 @@ def test_delete_non_existant_database():
# list(subnet_group.subnet_ids).should.equal(subnet_ids)
#
#
-#@mock_ec2
-#@mock_rds2
-#def test_describe_database_subnet_group():
-# vpc_conn = boto.vpc.connect_to_region("us-west-2")
-# vpc = vpc_conn.create_vpc("10.0.0.0/16")
-# subnet = vpc_conn.create_subnet(vpc.id, "10.1.0.0/24")
-#
-# conn = boto.rds2.connect_to_region("us-west-2")
-# conn.create_db_subnet_group("db_subnet1", "my db subnet", [subnet.id])
-# conn.create_db_subnet_group("db_subnet2", "my db subnet", [subnet.id])
-#
-# list(conn.get_all_db_subnet_groups()).should.have.length_of(2)
-# list(conn.get_all_db_subnet_groups("db_subnet1")).should.have.length_of(1)
-#
-# conn.get_all_db_subnet_groups.when.called_with("not-a-subnet").should.throw(BotoServerError)
+@mock_ec2
+@mock_rds2
+def test_describe_database_subnet_group():
+ vpc_conn = boto.vpc.connect_to_region("us-west-2")
+ vpc = vpc_conn.create_vpc("10.0.0.0/16")
+ subnet = vpc_conn.create_subnet(vpc.id, "10.1.0.0/24")
+
+ conn = boto.rds2.connect_to_region("us-west-2")
+ conn.create_db_subnet_group("db_subnet1", "my db subnet", [subnet.id])
+ conn.create_db_subnet_group("db_subnet2", "my db subnet", [subnet.id])
+
+ resp = conn.describe_db_subnet_groups()
+ groups_resp = resp['DescribeDBSubnetGroupsResponse']
+
+ subnet_groups = groups_resp['DescribeDBSubnetGroupsResult']['DBSubnetGroups']
+ subnet_groups.should.have.length_of(2)
+
+ subnets = groups_resp['DescribeDBSubnetGroupsResult']['DBSubnetGroups'][0]['DBSubnetGroup']['Subnets']
+ subnets.should.have.length_of(1)
+
+ list(resp).should.have.length_of(1)
+ list(groups_resp).should.have.length_of(2)
+ list(conn.describe_db_subnet_groups("db_subnet1")).should.have.length_of(1)
+
+ conn.describe_db_subnet_groups.when.called_with("not-a-subnet").should.throw(BotoServerError)
#
#
#@mock_ec2