OLD | NEW |
(Empty) | |
| 1 # Copyright (c) 2010 Hunter Blanks http://artifex.org/~hblanks/ |
| 2 # All rights reserved. |
| 3 # |
| 4 # Permission is hereby granted, free of charge, to any person obtaining a |
| 5 # copy of this software and associated documentation files (the |
| 6 # "Software"), to deal in the Software without restriction, including |
| 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 |
| 9 # persons to whom the Software is furnished to do so, subject to the fol- |
| 10 # lowing conditions: |
| 11 # |
| 12 # The above copyright notice and this permission notice shall be included |
| 13 # in all copies or substantial portions of the Software. |
| 14 # |
| 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- |
| 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, |
| 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 |
| 21 # IN THE SOFTWARE. |
| 22 |
| 23 """ |
| 24 Initial, and very limited, unit tests for ELBConnection. |
| 25 """ |
| 26 |
| 27 import unittest |
| 28 from boto.ec2.elb import ELBConnection |
| 29 |
| 30 class ELBConnectionTest(unittest.TestCase): |
| 31 |
| 32 def tearDown(self): |
| 33 """ Deletes all load balancers after every test. """ |
| 34 for lb in ELBConnection().get_all_load_balancers(): |
| 35 lb.delete() |
| 36 |
| 37 def test_build_list_params(self): |
| 38 c = ELBConnection() |
| 39 params = {} |
| 40 c.build_list_params( |
| 41 params, ['thing1', 'thing2', 'thing3'], 'ThingName%d') |
| 42 expected_params = { |
| 43 'ThingName1': 'thing1', |
| 44 'ThingName2': 'thing2', |
| 45 'ThingName3': 'thing3' |
| 46 } |
| 47 self.assertEqual(params, expected_params) |
| 48 |
| 49 # TODO: for these next tests, consider sleeping until our load |
| 50 # balancer comes up, then testing for connectivity to |
| 51 # balancer.dns_name, along the lines of the existing EC2 unit tests. |
| 52 |
| 53 def test_create_load_balancer(self): |
| 54 c = ELBConnection() |
| 55 name = 'elb-boto-unit-test' |
| 56 availability_zones = ['us-east-1a'] |
| 57 listeners = [(80, 8000, 'HTTP')] |
| 58 balancer = c.create_load_balancer(name, availability_zones, listeners) |
| 59 self.assertEqual(balancer.name, name) |
| 60 self.assertEqual(balancer.availability_zones, availability_zones) |
| 61 self.assertEqual(balancer.listeners, listeners) |
| 62 |
| 63 balancers = c.get_all_load_balancers() |
| 64 self.assertEqual([lb.name for lb in balancers], [name]) |
| 65 |
| 66 def test_create_load_balancer_listeners(self): |
| 67 c = ELBConnection() |
| 68 name = 'elb-boto-unit-test' |
| 69 availability_zones = ['us-east-1a'] |
| 70 listeners = [(80, 8000, 'HTTP')] |
| 71 balancer = c.create_load_balancer(name, availability_zones, listeners) |
| 72 |
| 73 more_listeners = [(443, 8001, 'HTTP')] |
| 74 c.create_load_balancer_listeners(name, more_listeners) |
| 75 balancers = c.get_all_load_balancers() |
| 76 self.assertEqual([lb.name for lb in balancers], [name]) |
| 77 self.assertEqual( |
| 78 sorted(l.get_tuple() for l in balancers[0].listeners), |
| 79 sorted(listeners + more_listeners) |
| 80 ) |
| 81 |
| 82 def test_delete_load_balancer_listeners(self): |
| 83 c = ELBConnection() |
| 84 name = 'elb-boto-unit-test' |
| 85 availability_zones = ['us-east-1a'] |
| 86 listeners = [(80, 8000, 'HTTP'), (443, 8001, 'HTTP')] |
| 87 balancer = c.create_load_balancer(name, availability_zones, listeners) |
| 88 |
| 89 balancers = c.get_all_load_balancers() |
| 90 self.assertEqual([lb.name for lb in balancers], [name]) |
| 91 self.assertEqual( |
| 92 [l.get_tuple() for l in balancers[0].listeners], listeners) |
| 93 |
| 94 c.delete_load_balancer_listeners(name, [443]) |
| 95 balancers = c.get_all_load_balancers() |
| 96 self.assertEqual([lb.name for lb in balancers], [name]) |
| 97 self.assertEqual( |
| 98 [l.get_tuple() for l in balancers[0].listeners], |
| 99 listeners[:1] |
| 100 ) |
| 101 |
| 102 |
| 103 if __name__ == '__main__': |
| 104 unittest.main() |
OLD | NEW |