OLD | NEW |
(Empty) | |
| 1 import unittest |
| 2 import random |
| 3 import time |
| 4 from functools import partial |
| 5 |
| 6 from boto.beanstalk.wrapper import Layer1Wrapper |
| 7 import boto.beanstalk.response as response |
| 8 |
| 9 |
| 10 class BasicSuite(unittest.TestCase): |
| 11 def setUp(self): |
| 12 self.random_id = str(random.randint(1, 1000000)) |
| 13 self.app_name = 'app-' + self.random_id |
| 14 self.app_version = 'version-' + self.random_id |
| 15 self.template = 'template-' + self.random_id |
| 16 self.environment = 'environment-' + self.random_id |
| 17 self.beanstalk = Layer1Wrapper() |
| 18 |
| 19 |
| 20 class MiscSuite(BasicSuite): |
| 21 def test_check_dns_availability(self): |
| 22 result = self.beanstalk.check_dns_availability('amazon') |
| 23 self.assertIsInstance(result, response.CheckDNSAvailabilityResponse, |
| 24 'incorrect response object returned') |
| 25 self.assertFalse(result.available) |
| 26 |
| 27 |
| 28 class TestApplicationObjects(BasicSuite): |
| 29 def create_application(self): |
| 30 # This method is used for any API calls that require an application |
| 31 # object. This also adds a cleanup step to automatically delete the |
| 32 # app when the test is finished. No assertions are performed |
| 33 # here. If you want to validate create_application, don't use this |
| 34 # method. |
| 35 self.beanstalk.create_application(application_name=self.app_name) |
| 36 self.addCleanup(partial(self.beanstalk.delete_application, |
| 37 application_name=self.app_name)) |
| 38 |
| 39 def test_create_delete_application_version(self): |
| 40 # This will create an app, create an app version, delete the app |
| 41 # version, and delete the app. For each API call we check that the |
| 42 # return type is what we expect and that a few attributes have the |
| 43 # correct values. |
| 44 app_result = self.beanstalk.create_application(application_name=self.app
_name) |
| 45 self.assertIsInstance(app_result, response.CreateApplicationResponse) |
| 46 self.assertEqual(app_result.application.application_name, self.app_name) |
| 47 |
| 48 version_result = self.beanstalk.create_application_version( |
| 49 application_name=self.app_name, version_label=self.app_version) |
| 50 self.assertIsInstance(version_result, response.CreateApplicationVersionR
esponse) |
| 51 self.assertEqual(version_result.application_version.version_label, |
| 52 self.app_version) |
| 53 result = self.beanstalk.delete_application_version( |
| 54 application_name=self.app_name, version_label=self.app_version) |
| 55 self.assertIsInstance(result, response.DeleteApplicationVersionResponse) |
| 56 result = self.beanstalk.delete_application( |
| 57 application_name=self.app_name |
| 58 ) |
| 59 self.assertIsInstance(result, response.DeleteApplicationResponse) |
| 60 |
| 61 def test_create_configuration_template(self): |
| 62 self.create_application() |
| 63 result = self.beanstalk.create_configuration_template( |
| 64 application_name=self.app_name, template_name=self.template, |
| 65 solution_stack_name='32bit Amazon Linux running Tomcat 6') |
| 66 self.assertIsInstance( |
| 67 result, response.CreateConfigurationTemplateResponse) |
| 68 self.assertEqual(result.solution_stack_name, |
| 69 '32bit Amazon Linux running Tomcat 6') |
| 70 |
| 71 def test_create_storage_location(self): |
| 72 result = self.beanstalk.create_storage_location() |
| 73 self.assertIsInstance(result, response.CreateStorageLocationResponse) |
| 74 |
| 75 def test_update_application(self): |
| 76 self.create_application() |
| 77 result = self.beanstalk.update_application(application_name=self.app_nam
e) |
| 78 self.assertIsInstance(result, response.UpdateApplicationResponse) |
| 79 |
| 80 def test_update_application_version(self): |
| 81 self.create_application() |
| 82 self.beanstalk.create_application_version( |
| 83 application_name=self.app_name, version_label=self.app_version) |
| 84 result = self.beanstalk.update_application_version( |
| 85 application_name=self.app_name, version_label=self.app_version) |
| 86 self.assertIsInstance( |
| 87 result, response.UpdateApplicationVersionResponse) |
| 88 |
| 89 |
| 90 class GetSuite(BasicSuite): |
| 91 def test_describe_applications(self): |
| 92 result = self.beanstalk.describe_applications() |
| 93 self.assertIsInstance(result, response.DescribeApplicationsResponse) |
| 94 |
| 95 def test_describe_application_versions(self): |
| 96 result = self.beanstalk.describe_application_versions() |
| 97 self.assertIsInstance(result, |
| 98 response.DescribeApplicationVersionsResponse) |
| 99 |
| 100 |
| 101 def test_describe_configuration_options(self): |
| 102 result = self.beanstalk.describe_configuration_options() |
| 103 self.assertIsInstance(result, |
| 104 response.DescribeConfigurationOptionsResponse) |
| 105 |
| 106 def test_12_describe_environments(self): |
| 107 result = self.beanstalk.describe_environments() |
| 108 self.assertIsInstance( |
| 109 result, response.DescribeEnvironmentsResponse) |
| 110 |
| 111 def test_14_describe_events(self): |
| 112 result = self.beanstalk.describe_events() |
| 113 self.assertIsInstance(result, response.DescribeEventsResponse) |
| 114 |
| 115 def test_15_list_available_solution_stacks(self): |
| 116 result = self.beanstalk.list_available_solution_stacks() |
| 117 self.assertIsInstance( |
| 118 result, response.ListAvailableSolutionStacksResponse) |
| 119 self.assertIn('32bit Amazon Linux running Tomcat 6', |
| 120 result.solution_stacks) |
| 121 |
| 122 |
| 123 |
| 124 class TestsWithEnvironment(unittest.TestCase): |
| 125 @classmethod |
| 126 def setUpClass(cls): |
| 127 cls.random_id = str(random.randint(1, 1000000)) |
| 128 cls.app_name = 'app-' + cls.random_id |
| 129 cls.environment = 'environment-' + cls.random_id |
| 130 cls.template = 'template-' + cls.random_id |
| 131 |
| 132 cls.beanstalk = Layer1Wrapper() |
| 133 cls.beanstalk.create_application(application_name=cls.app_name) |
| 134 cls.beanstalk.create_configuration_template( |
| 135 application_name=cls.app_name, template_name=cls.template, |
| 136 solution_stack_name='32bit Amazon Linux running Tomcat 6') |
| 137 cls.app_version = 'version-' + cls.random_id |
| 138 cls.beanstalk.create_application_version( |
| 139 application_name=cls.app_name, version_label=cls.app_version) |
| 140 cls.beanstalk.create_environment(cls.app_name, cls.environment, |
| 141 template_name=cls.template) |
| 142 cls.wait_for_env(cls.environment) |
| 143 |
| 144 @classmethod |
| 145 def tearDownClass(cls): |
| 146 cls.beanstalk.delete_application(application_name=cls.app_name, |
| 147 terminate_env_by_force=True) |
| 148 cls.wait_for_env(cls.environment, 'Terminated') |
| 149 |
| 150 @classmethod |
| 151 def wait_for_env(cls, env_name, status='Ready'): |
| 152 while not cls.env_ready(env_name, status): |
| 153 time.sleep(15) |
| 154 |
| 155 @classmethod |
| 156 def env_ready(cls, env_name, desired_status): |
| 157 result = cls.beanstalk.describe_environments( |
| 158 application_name=cls.app_name, environment_names=env_name) |
| 159 status = result.environments[0].status |
| 160 return status == desired_status |
| 161 |
| 162 def test_describe_environment_resources(self): |
| 163 result = self.beanstalk.describe_environment_resources( |
| 164 environment_name=self.environment) |
| 165 self.assertIsInstance( |
| 166 result, response.DescribeEnvironmentResourcesResponse) |
| 167 |
| 168 def test_describe_configuration_settings(self): |
| 169 result = self.beanstalk.describe_configuration_settings( |
| 170 application_name=self.app_name, environment_name=self.environment) |
| 171 self.assertIsInstance( |
| 172 result, response.DescribeConfigurationSettingsResponse) |
| 173 |
| 174 def test_request_environment_info(self): |
| 175 result = self.beanstalk.request_environment_info( |
| 176 environment_name=self.environment, info_type='tail') |
| 177 self.assertIsInstance(result, response.RequestEnvironmentInfoResponse) |
| 178 self.wait_for_env(self.environment) |
| 179 result = self.beanstalk.retrieve_environment_info( |
| 180 environment_name=self.environment, info_type='tail') |
| 181 self.assertIsInstance(result, response.RetrieveEnvironmentInfoResponse) |
| 182 |
| 183 def test_rebuild_environment(self): |
| 184 result = self.beanstalk.rebuild_environment( |
| 185 environment_name=self.environment) |
| 186 self.assertIsInstance(result, response.RebuildEnvironmentResponse) |
| 187 self.wait_for_env(self.environment) |
| 188 |
| 189 def test_restart_app_server(self): |
| 190 result = self.beanstalk.restart_app_server( |
| 191 environment_name=self.environment) |
| 192 self.assertIsInstance(result, response.RestartAppServerResponse) |
| 193 self.wait_for_env(self.environment) |
| 194 |
| 195 def test_update_configuration_template(self): |
| 196 result = self.beanstalk.update_configuration_template( |
| 197 application_name=self.app_name, template_name=self.template) |
| 198 self.assertIsInstance( |
| 199 result, response.UpdateConfigurationTemplateResponse) |
| 200 |
| 201 def test_update_environment(self): |
| 202 result = self.beanstalk.update_environment( |
| 203 environment_name=self.environment) |
| 204 self.assertIsInstance(result, response.UpdateEnvironmentResponse) |
| 205 self.wait_for_env(self.environment) |
| 206 |
| 207 |
| 208 if __name__ == '__main__': |
| 209 unittest.main() |
OLD | NEW |