Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: third_party/boto/tests/unit/ec2/test_networkinterface.py

Issue 698893003: Update checked in version of gsutil to version 4.6 (Closed) Base URL: http://dart.googlecode.com/svn/third_party/gsutil/
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 Amazon.com, Inc. or its affiliates. All Rights Reserved 2 # Copyright (c) 2012 Amazon.com, Inc. or its affiliates. All Rights Reserved
3 # 3 #
4 # Permission is hereby granted, free of charge, to any person obtaining a 4 # Permission is hereby granted, free of charge, to any person obtaining a
5 # copy of this software and associated documentation files (the 5 # copy of this software and associated documentation files (the
6 # "Software"), to deal in the Software without restriction, including 6 # "Software"), to deal in the Software without restriction, including
7 # without limitation the rights to use, copy, modify, merge, publish, dis- 7 # without limitation the rights to use, copy, modify, merge, publish, dis-
8 # tribute, sublicense, and/or sell copies of the Software, and to permit 8 # tribute, sublicense, and/or sell copies of the Software, and to permit
9 # persons to whom the Software is furnished to do so, subject to the fol- 9 # persons to whom the Software is furnished to do so, subject to the fol-
10 # lowing conditions: 10 # lowing conditions:
11 # 11 #
12 # The above copyright notice and this permission notice shall be included 12 # The above copyright notice and this permission notice shall be included
13 # in all copies or substantial portions of the Software. 13 # in all copies or substantial portions of the Software.
14 # 14 #
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- 16 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
17 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 17 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
18 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 18 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 # IN THE SOFTWARE. 21 # IN THE SOFTWARE.
22 # 22 #
23 23
24 import mock
24 from tests.unit import unittest 25 from tests.unit import unittest
25 26
26 from boto.exception import BotoClientError 27 from boto.exception import BotoClientError
27 from boto.ec2.networkinterface import NetworkInterfaceCollection 28 from boto.ec2.networkinterface import NetworkInterfaceCollection
28 from boto.ec2.networkinterface import NetworkInterfaceSpecification 29 from boto.ec2.networkinterface import NetworkInterfaceSpecification
29 from boto.ec2.networkinterface import PrivateIPAddress 30 from boto.ec2.networkinterface import PrivateIPAddress
31 from boto.ec2.networkinterface import Attachment, NetworkInterface
32
33
34 class NetworkInterfaceTests(unittest.TestCase):
35 def setUp(self):
36
37 self.attachment = Attachment()
38 self.attachment.id = 'eni-attach-1'
39 self.attachment.instance_id = 10
40 self.attachment.status = "some status"
41 self.attachment.device_index = 100
42
43 self.eni_one = NetworkInterface()
44 self.eni_one.id = 'eni-1'
45 self.eni_one.status = "one_status"
46 self.eni_one.attachment = self.attachment
47
48 self.eni_two = NetworkInterface()
49 self.eni_two.connection = mock.Mock()
50 self.eni_two.id = 'eni-2'
51 self.eni_two.status = "two_status"
52 self.eni_two.attachment = None
53
54 def test_update_with_validate_true_raises_value_error(self):
55 self.eni_one.connection = mock.Mock()
56 self.eni_one.connection.get_all_network_interfaces.return_value = []
57 with self.assertRaisesRegexp(ValueError, "^eni-1 is not a valid ENI ID$" ):
58 self.eni_one.update(True)
59
60 def test_update_with_result_set_greater_than_0_updates_dict(self):
61 self.eni_two.connection.get_all_network_interfaces.return_value = [self. eni_one]
62 self.eni_two.update()
63
64 assert all([self.eni_two.status == "one_status",
65 self.eni_two.id == 'eni-1',
66 self.eni_two.attachment == self.attachment])
67
68 def test_update_returns_status(self):
69 self.eni_one.connection = mock.Mock()
70 self.eni_one.connection.get_all_network_interfaces.return_value = [self. eni_two]
71 retval = self.eni_one.update()
72 self.assertEqual(retval, "two_status")
73
74 def test_attach_calls_attach_eni(self):
75 self.eni_one.connection = mock.Mock()
76 self.eni_one.attach("instance_id", 11)
77 self.eni_one.connection.attach_network_interface.assert_called_with(
78 'eni-1',
79 "instance_id",
80 11,
81 dry_run=False
82 )
83
84 def test_detach_calls_detach_network_interface(self):
85 self.eni_one.connection = mock.Mock()
86 self.eni_one.detach()
87 self.eni_one.connection.detach_network_interface.assert_called_with(
88 'eni-attach-1',
89 False,
90 dry_run=False
91 )
92
93 def test_detach_with_no_attach_data(self):
94 self.eni_two.connection = mock.Mock()
95 self.eni_two.detach()
96 self.eni_two.connection.detach_network_interface.assert_called_with(
97 None, False, dry_run=False)
98
99 def test_detach_with_force_calls_detach_network_interface_with_force(self):
100 self.eni_one.connection = mock.Mock()
101 self.eni_one.detach(True)
102 self.eni_one.connection.detach_network_interface.assert_called_with(
103 'eni-attach-1', True, dry_run=False)
30 104
31 105
32 class TestNetworkInterfaceCollection(unittest.TestCase): 106 class TestNetworkInterfaceCollection(unittest.TestCase):
33 maxDiff = None 107 maxDiff = None
34 108
35 def setUp(self): 109 def setUp(self):
36 self.private_ip_address1 = PrivateIPAddress( 110 self.private_ip_address1 = PrivateIPAddress(
37 private_ip_address='10.0.0.10', primary=False) 111 private_ip_address='10.0.0.10', primary=False)
38 self.private_ip_address2 = PrivateIPAddress( 112 self.private_ip_address2 = PrivateIPAddress(
39 private_ip_address='10.0.0.11', primary=False) 113 private_ip_address='10.0.0.11', primary=False)
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 '10.0.1.11', 265 '10.0.1.11',
192 'LaunchSpecification.NetworkInterface.0.SecurityGroupId.0': 266 'LaunchSpecification.NetworkInterface.0.SecurityGroupId.0':
193 'group_id1', 267 'group_id1',
194 'LaunchSpecification.NetworkInterface.0.SecurityGroupId.1': 268 'LaunchSpecification.NetworkInterface.0.SecurityGroupId.1':
195 'group_id2', 269 'group_id2',
196 }) 270 })
197 271
198 272
199 if __name__ == '__main__': 273 if __name__ == '__main__':
200 unittest.main() 274 unittest.main()
OLDNEW
« no previous file with comments | « third_party/boto/tests/unit/ec2/test_instancetype.py ('k') | third_party/boto/tests/unit/ec2/test_snapshot.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698