File: test_internetgateway.py

package info (click to toggle)
python-boto 2.49.0-4.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 9,888 kB
  • sloc: python: 86,396; makefile: 112
file content (152 lines) | stat: -rw-r--r-- 6,080 bytes parent folder | download | duplicates (13)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
from tests.unit import unittest
from tests.unit import AWSMockServiceTestCase

from boto.vpc import VPCConnection, InternetGateway


class TestDescribeInternetGateway(AWSMockServiceTestCase):

    connection_class = VPCConnection

    def default_body(self):
        return b"""
            <DescribeInternetGatewaysResponse xmlns="http://ec2.amazonaws.com/doc/2013-10-01/">
               <requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
               <internetGatewaySet>
                  <item>
                     <internetGatewayId>igw-eaad4883EXAMPLE</internetGatewayId>
                     <attachmentSet>
                        <item>
                           <vpcId>vpc-11ad4878</vpcId>
                           <state>available</state>
                        </item>
                     </attachmentSet>
                     <tagSet/>
                  </item>
               </internetGatewaySet>
            </DescribeInternetGatewaysResponse>
        """

    def test_describe_internet_gateway(self):
        self.set_http_response(status_code=200)
        api_response = self.service_connection.get_all_internet_gateways(
            'igw-eaad4883EXAMPLE', filters=[('attachment.state', ['available', 'pending'])])
        self.assert_request_parameters({
            'Action': 'DescribeInternetGateways',
            'InternetGatewayId.1': 'igw-eaad4883EXAMPLE',
            'Filter.1.Name': 'attachment.state',
            'Filter.1.Value.1': 'available',
            'Filter.1.Value.2': 'pending'},
            ignore_params_values=['AWSAccessKeyId', 'SignatureMethod',
                                  'SignatureVersion', 'Timestamp',
                                  'Version'])
        self.assertEquals(len(api_response), 1)
        self.assertIsInstance(api_response[0], InternetGateway)
        self.assertEqual(api_response[0].id, 'igw-eaad4883EXAMPLE')


class TestCreateInternetGateway(AWSMockServiceTestCase):

    connection_class = VPCConnection

    def default_body(self):
        return b"""
            <CreateInternetGatewayResponse xmlns="http://ec2.amazonaws.com/doc/2013-10-01/">
               <requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
               <internetGateway>
                  <internetGatewayId>igw-eaad4883</internetGatewayId>
                  <attachmentSet/>
                  <tagSet/>
               </internetGateway>
            </CreateInternetGatewayResponse>
        """

    def test_create_internet_gateway(self):
        self.set_http_response(status_code=200)
        api_response = self.service_connection.create_internet_gateway()
        self.assert_request_parameters({
            'Action': 'CreateInternetGateway'},
            ignore_params_values=['AWSAccessKeyId', 'SignatureMethod',
                                  'SignatureVersion', 'Timestamp',
                                  'Version'])
        self.assertIsInstance(api_response, InternetGateway)
        self.assertEqual(api_response.id, 'igw-eaad4883')


class TestDeleteInternetGateway(AWSMockServiceTestCase):

    connection_class = VPCConnection

    def default_body(self):
        return b"""
            <DeleteInternetGatewayResponse xmlns="http://ec2.amazonaws.com/doc/2013-10-01/">
               <requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
               <return>true</return>
            </DeleteInternetGatewayResponse>
        """

    def test_delete_internet_gateway(self):
        self.set_http_response(status_code=200)
        api_response = self.service_connection.delete_internet_gateway('igw-eaad4883')
        self.assert_request_parameters({
            'Action': 'DeleteInternetGateway',
            'InternetGatewayId': 'igw-eaad4883'},
            ignore_params_values=['AWSAccessKeyId', 'SignatureMethod',
                                  'SignatureVersion', 'Timestamp',
                                  'Version'])
        self.assertEquals(api_response, True)


class TestAttachInternetGateway(AWSMockServiceTestCase):

    connection_class = VPCConnection

    def default_body(self):
        return b"""
            <AttachInternetGatewayResponse xmlns="http://ec2.amazonaws.com/doc/2013-10-01/">
               <requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
               <return>true</return>
            </AttachInternetGatewayResponse>
        """

    def test_attach_internet_gateway(self):
        self.set_http_response(status_code=200)
        api_response = self.service_connection.attach_internet_gateway(
            'igw-eaad4883', 'vpc-11ad4878')
        self.assert_request_parameters({
            'Action': 'AttachInternetGateway',
            'InternetGatewayId': 'igw-eaad4883',
            'VpcId': 'vpc-11ad4878'},
            ignore_params_values=['AWSAccessKeyId', 'SignatureMethod',
                                  'SignatureVersion', 'Timestamp',
                                  'Version'])
        self.assertEquals(api_response, True)


class TestDetachInternetGateway(AWSMockServiceTestCase):

    connection_class = VPCConnection

    def default_body(self):
        return b"""
            <DetachInternetGatewayResponse xmlns="http://ec2.amazonaws.com/doc/2013-10-01/">
               <requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
               <return>true</return>
            </DetachInternetGatewayResponse>
        """

    def test_detach_internet_gateway(self):
        self.set_http_response(status_code=200)
        api_response = self.service_connection.detach_internet_gateway(
            'igw-eaad4883', 'vpc-11ad4878')
        self.assert_request_parameters({
            'Action': 'DetachInternetGateway',
            'InternetGatewayId': 'igw-eaad4883',
            'VpcId': 'vpc-11ad4878'},
            ignore_params_values=['AWSAccessKeyId', 'SignatureMethod',
                                  'SignatureVersion', 'Timestamp',
                                  'Version'])
        self.assertEquals(api_response, True)

if __name__ == '__main__':
    unittest.main()