| OLD | NEW |
| 1 try: | 1 try: |
| 2 import unittest2 as unittest | 2 import unittest2 as unittest |
| 3 except ImportError: | 3 except ImportError: |
| 4 import unittest | 4 import unittest |
| 5 import httplib | 5 import httplib |
| 6 | 6 |
| 7 import mock |
| 7 from mock import Mock | 8 from mock import Mock |
| 8 | 9 |
| 9 | 10 |
| 10 class AWSMockServiceTestCase(unittest.TestCase): | 11 class AWSMockServiceTestCase(unittest.TestCase): |
| 11 """Base class for mocking aws services.""" | 12 """Base class for mocking aws services.""" |
| 12 # This param is used by the unittest module to display a full | 13 # This param is used by the unittest module to display a full |
| 13 # diff when assert*Equal methods produce an error message. | 14 # diff when assert*Equal methods produce an error message. |
| 14 maxDiff = None | 15 maxDiff = None |
| 15 connection_class = None | 16 connection_class = None |
| 16 | 17 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 self.assertIn(param, request_params) | 71 self.assertIn(param, request_params) |
| 71 del request_params[param] | 72 del request_params[param] |
| 72 self.assertDictEqual(request_params, params) | 73 self.assertDictEqual(request_params, params) |
| 73 | 74 |
| 74 def set_http_response(self, status_code, reason='', header=[], body=None): | 75 def set_http_response(self, status_code, reason='', header=[], body=None): |
| 75 http_response = self.create_response(status_code, reason, header, body) | 76 http_response = self.create_response(status_code, reason, header, body) |
| 76 self.https_connection.getresponse.return_value = http_response | 77 self.https_connection.getresponse.return_value = http_response |
| 77 | 78 |
| 78 def default_body(self): | 79 def default_body(self): |
| 79 return '' | 80 return '' |
| 81 |
| 82 |
| 83 class MockServiceWithConfigTestCase(AWSMockServiceTestCase): |
| 84 def setUp(self): |
| 85 super(MockServiceWithConfigTestCase, self).setUp() |
| 86 self.environ = {} |
| 87 self.config = {} |
| 88 self.config_patch = mock.patch('boto.provider.config.get', |
| 89 self.get_config) |
| 90 self.has_config_patch = mock.patch('boto.provider.config.has_option', |
| 91 self.has_config) |
| 92 self.environ_patch = mock.patch('os.environ', self.environ) |
| 93 self.config_patch.start() |
| 94 self.has_config_patch.start() |
| 95 self.environ_patch.start() |
| 96 |
| 97 def tearDown(self): |
| 98 self.config_patch.stop() |
| 99 self.has_config_patch.stop() |
| 100 self.environ_patch.stop() |
| 101 |
| 102 def has_config(self, section_name, key): |
| 103 try: |
| 104 self.config[section_name][key] |
| 105 return True |
| 106 except KeyError: |
| 107 return False |
| 108 |
| 109 def get_config(self, section_name, key, default=None): |
| 110 try: |
| 111 return self.config[section_name][key] |
| 112 except KeyError: |
| 113 return None |
| OLD | NEW |