From 76a939cee68abe47e301ce0aa8848a5c139c317f Mon Sep 17 00:00:00 2001 From: earthmant Date: Thu, 3 Dec 2015 13:19:10 +0200 Subject: [PATCH] making requested fix used sequence_from_querystring and removed added functon vpn_connection_ids_from_query_string added tests --- moto/ec2/responses/vpn_connections.py | 4 +-- moto/ec2/utils.py | 8 ------ tests/test_ec2/test_vpn_connections.py | 40 ++++++++++++++++++++++++-- 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/moto/ec2/responses/vpn_connections.py b/moto/ec2/responses/vpn_connections.py index e01fd272e..7825e7ebb 100644 --- a/moto/ec2/responses/vpn_connections.py +++ b/moto/ec2/responses/vpn_connections.py @@ -1,6 +1,6 @@ from __future__ import unicode_literals from moto.core.responses import BaseResponse -from moto.ec2.utils import filters_from_querystring, vpn_connection_ids_from_query_string +from moto.ec2.utils import filters_from_querystring, sequence_from_querystring class VPNConnections(BaseResponse): @@ -20,7 +20,7 @@ class VPNConnections(BaseResponse): return template.render(vpn_connection=vpn_connection) def describe_vpn_connections(self): - vpn_connection_ids = vpn_connection_ids_from_query_string(self.querystring) + vpn_connection_ids = sequence_from_querystring('VpnConnectionId', self.querystring) filters = filters_from_querystring(self.querystring) vpn_connections = self.ec2_backend.get_all_vpn_connections( vpn_connection_ids=vpn_connection_ids, filters=filters) diff --git a/moto/ec2/utils.py b/moto/ec2/utils.py index 70adf2634..e0edde7d6 100644 --- a/moto/ec2/utils.py +++ b/moto/ec2/utils.py @@ -197,14 +197,6 @@ def vpc_ids_from_querystring(querystring_dict): return vpc_ids -def vpn_connection_ids_from_query_string(querystring_dict): - vpn_connection_ids = [] - for key, value in querystring_dict.items(): - if 'VpnConnectionId' in key: - vpn_connection_ids.append(value[0]) - return vpn_connection_ids - - def sequence_from_querystring(parameter, querystring_dict): parameter_values = [] for key, value in querystring_dict.items(): diff --git a/tests/test_ec2/test_vpn_connections.py b/tests/test_ec2/test_vpn_connections.py index 06b9fba5e..064ff0e88 100644 --- a/tests/test_ec2/test_vpn_connections.py +++ b/tests/test_ec2/test_vpn_connections.py @@ -1,10 +1,46 @@ from __future__ import unicode_literals import boto +from nose.tools import assert_raises, assert_in import sure # noqa +from boto.exception import EC2ResponseError from moto import mock_ec2 @mock_ec2 -def test_vpn_connections(): - pass +def test_create_vpn_connections(): + conn = boto.connect_vpc('the_key', 'the_secret') + vpn_connection = conn.create_vpn_connection('ipsec.1', 'vgw-0123abcd', 'cgw-0123abcd') + vpn_connection.should_not.be.none + vpn_connection.id.should.match(r'vpn-\w+') + vpn_connection.type.should.equal('ipsec.1') + +@mock_ec2 +def test_delete_vpn_connections(): + conn = boto.connect_vpc('the_key', 'the_secret') + vpn_connection = conn.create_vpn_connection('ipsec.1', 'vgw-0123abcd', 'cgw-0123abcd') + list_of_vpn_connections = conn.get_all_vpn_connections() + list_of_vpn_connections.should.have.length_of(1) + conn.delete_vpn_connection(vpn_connection.id) + list_of_vpn_connections = conn.get_all_vpn_connections() + list_of_vpn_connections.should.have.length_of(0) + +@mock_ec2 +def test_delete_vpn_connections_bad_id(): + conn = boto.connect_vpc('the_key', 'the_secret') + with assert_raises(EC2ResponseError) as message: + conn.delete_vpn_connection('vpn-0123abcd') + +@mock_ec2 +def test_describe_vpn_connections(): + conn = boto.connect_vpc('the_key', 'the_secret') + list_of_vpn_connections = conn.get_all_vpn_connections() + list_of_vpn_connections.should.have.length_of(0) + conn.create_vpn_connection('ipsec.1', 'vgw-0123abcd', 'cgw-0123abcd') + list_of_vpn_connections = conn.get_all_vpn_connections() + list_of_vpn_connections.should.have.length_of(1) + vpn = conn.create_vpn_connection('ipsec.1', 'vgw-1234abcd', 'cgw-1234abcd') + list_of_vpn_connections = conn.get_all_vpn_connections() + list_of_vpn_connections.should.have.length_of(2) + list_of_vpn_connections = conn.get_all_vpn_connections(vpn.id) + list_of_vpn_connections.should.have.length_of(1)