test_boto_s3_bucket.py 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  1. # -*- coding: utf-8 -*-
  2. # Import Python libs
  3. from __future__ import absolute_import, print_function, unicode_literals
  4. import random
  5. import string
  6. import logging
  7. from copy import deepcopy
  8. # Import Salt Testing libs
  9. from tests.support.mixins import LoaderModuleMockMixin
  10. from tests.support.unit import skipIf, TestCase
  11. from tests.support.mock import (
  12. MagicMock,
  13. patch
  14. )
  15. # Import Salt libs
  16. import salt.loader
  17. import salt.modules.boto_s3_bucket as boto_s3_bucket
  18. from salt.utils.versions import LooseVersion
  19. # Import 3rd-party libs
  20. from salt.ext import six
  21. from salt.ext.six.moves import range # pylint: disable=import-error,redefined-builtin
  22. # pylint: disable=import-error,no-name-in-module,unused-import
  23. try:
  24. import boto
  25. import boto3
  26. from botocore.exceptions import ClientError
  27. HAS_BOTO = True
  28. except ImportError:
  29. HAS_BOTO = False
  30. # pylint: enable=import-error,no-name-in-module,unused-import
  31. # the boto_s3_bucket module relies on the connect_to_region() method
  32. # which was added in boto 2.8.0
  33. # https://github.com/boto/boto/commit/33ac26b416fbb48a60602542b4ce15dcc7029f12
  34. required_boto3_version = '1.2.1'
  35. log = logging.getLogger(__name__)
  36. def _has_required_boto():
  37. '''
  38. Returns True/False boolean depending on if Boto is installed and correct
  39. version.
  40. '''
  41. if not HAS_BOTO:
  42. return False
  43. elif LooseVersion(boto3.__version__) < LooseVersion(required_boto3_version):
  44. return False
  45. else:
  46. return True
  47. if _has_required_boto():
  48. region = 'us-east-1'
  49. access_key = 'GKTADJGHEIQSXMKKRBJ08H'
  50. secret_key = 'askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs'
  51. conn_parameters = {'region': region, 'key': access_key, 'keyid': secret_key, 'profile': {}}
  52. error_message = 'An error occurred (101) when calling the {0} operation: Test-defined error'
  53. e404_error = ClientError({
  54. 'Error': {
  55. 'Code': '404',
  56. 'Message': "Test-defined error"
  57. }
  58. }, 'msg')
  59. not_found_error = ClientError({
  60. 'Error': {
  61. 'Code': 'NoSuchBucket',
  62. 'Message': "Test-defined error"
  63. }
  64. }, 'msg')
  65. error_content = {
  66. 'Error': {
  67. 'Code': 101,
  68. 'Message': "Test-defined error"
  69. }
  70. }
  71. create_ret = {
  72. 'Location': 'nowhere',
  73. }
  74. list_ret = {
  75. 'Buckets': [{
  76. 'Name': 'mybucket',
  77. 'CreationDate': None
  78. }],
  79. 'Owner': {
  80. 'DisplayName': 'testuser',
  81. 'ID': '12341234123'
  82. },
  83. 'ResponseMetadata': {'Key': 'Value'}
  84. }
  85. config_ret = {
  86. 'get_bucket_acl': {
  87. 'Grants': [{
  88. 'Grantee': {
  89. 'DisplayName': 'testowner',
  90. 'ID': 'sdfghjklqwertyuiopzxcvbnm'
  91. },
  92. 'Permission': 'FULL_CONTROL'
  93. }, {
  94. 'Grantee': {
  95. 'URI': 'http://acs.amazonaws.com/groups/global/AllUsers'
  96. },
  97. 'Permission': 'READ'
  98. }],
  99. 'Owner': {
  100. 'DisplayName': 'testowner',
  101. 'ID': 'sdfghjklqwertyuiopzxcvbnm'
  102. }
  103. },
  104. 'get_bucket_cors': {
  105. 'CORSRules': [{
  106. 'AllowedMethods': ["GET"],
  107. 'AllowedOrigins': ["*"],
  108. }]
  109. },
  110. 'get_bucket_lifecycle_configuration': {
  111. 'Rules': [{
  112. 'Expiration': {
  113. 'Days': 1
  114. },
  115. 'Prefix': 'prefix',
  116. 'Status': 'Enabled',
  117. 'ID': 'asdfghjklpoiuytrewq'
  118. }]
  119. },
  120. 'get_bucket_location': {
  121. 'LocationConstraint': 'EU'
  122. },
  123. 'get_bucket_logging': {
  124. 'LoggingEnabled': {
  125. 'TargetBucket': 'my-bucket',
  126. 'TargetPrefix': 'prefix'
  127. }
  128. },
  129. 'get_bucket_notification_configuration': {
  130. 'LambdaFunctionConfigurations': [{
  131. 'LambdaFunctionArn': 'arn:aws:lambda:us-east-1:111111222222:function:my-function',
  132. 'Id': 'zxcvbnmlkjhgfdsa',
  133. 'Events': ["s3:ObjectCreated:*"],
  134. 'Filter': {
  135. 'Key': {
  136. 'FilterRules': [{
  137. 'Name': 'prefix',
  138. 'Value': 'string'
  139. }]
  140. }
  141. }
  142. }]
  143. },
  144. 'get_bucket_policy': {
  145. 'Policy':
  146. '{"Version":"2012-10-17","Statement":[{"Sid":"","Effect":"Allow","Principal":{"AWS":"arn:aws:iam::111111222222:root"},"Action":"s3:PutObject","Resource":"arn:aws:s3:::my-bucket/*"}]}'
  147. },
  148. 'get_bucket_replication': {
  149. 'ReplicationConfiguration': {
  150. 'Role': 'arn:aws:iam::11111222222:my-role',
  151. 'Rules': [{
  152. 'ID': "r1",
  153. 'Prefix': "prefix",
  154. 'Status': "Enabled",
  155. 'Destination': {
  156. 'Bucket': "arn:aws:s3:::my-bucket"
  157. }
  158. }]
  159. }
  160. },
  161. 'get_bucket_request_payment': {'Payer': 'Requester'},
  162. 'get_bucket_tagging': {
  163. 'TagSet': [{
  164. 'Key': 'c',
  165. 'Value': 'd'
  166. }, {
  167. 'Key': 'a',
  168. 'Value': 'b',
  169. }]
  170. },
  171. 'get_bucket_versioning': {
  172. 'Status': 'Enabled'
  173. },
  174. 'get_bucket_website': {
  175. 'ErrorDocument': {
  176. 'Key': 'error.html'
  177. },
  178. 'IndexDocument': {
  179. 'Suffix': 'index.html'
  180. }
  181. }
  182. }
  183. @skipIf(HAS_BOTO is False, 'The boto module must be installed.')
  184. @skipIf(_has_required_boto() is False, 'The boto3 module must be greater than'
  185. ' or equal to version {0}'
  186. .format(required_boto3_version))
  187. class BotoS3BucketTestCaseBase(TestCase, LoaderModuleMockMixin):
  188. conn = None
  189. def setup_loader_modules(self):
  190. self.opts = opts = salt.config.DEFAULT_MINION_OPTS
  191. utils = salt.loader.utils(
  192. opts,
  193. whitelist=['boto3', 'args', 'systemd', 'path', 'platform'],
  194. context={})
  195. return {boto_s3_bucket: {'__utils__': utils}}
  196. def setUp(self):
  197. super(BotoS3BucketTestCaseBase, self).setUp()
  198. boto_s3_bucket.__init__(self.opts)
  199. del self.opts
  200. # Set up MagicMock to replace the boto3 session
  201. # connections keep getting cached from prior tests, can't find the
  202. # correct context object to clear it. So randomize the cache key, to prevent any
  203. # cache hits
  204. conn_parameters['key'] = ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(50))
  205. self.patcher = patch('boto3.session.Session')
  206. self.addCleanup(self.patcher.stop)
  207. self.addCleanup(delattr, self, 'patcher')
  208. mock_session = self.patcher.start()
  209. session_instance = mock_session.return_value
  210. self.conn = MagicMock()
  211. self.addCleanup(delattr, self, 'conn')
  212. session_instance.client.return_value = self.conn
  213. class BotoS3BucketTestCaseMixin(object):
  214. pass
  215. class BotoS3BucketTestCase(BotoS3BucketTestCaseBase, BotoS3BucketTestCaseMixin):
  216. '''
  217. TestCase for salt.modules.boto_s3_bucket module
  218. '''
  219. def test_that_when_checking_if_a_bucket_exists_and_a_bucket_exists_the_bucket_exists_method_returns_true(self):
  220. '''
  221. Tests checking s3 bucket existence when the s3 bucket already exists
  222. '''
  223. self.conn.head_bucket.return_value = None
  224. result = boto_s3_bucket.exists(Bucket='mybucket', **conn_parameters)
  225. self.assertTrue(result['exists'])
  226. def test_that_when_checking_if_a_bucket_exists_and_a_bucket_does_not_exist_the_bucket_exists_method_returns_false(self):
  227. '''
  228. Tests checking s3 bucket existence when the s3 bucket does not exist
  229. '''
  230. self.conn.head_bucket.side_effect = e404_error
  231. result = boto_s3_bucket.exists(Bucket='mybucket', **conn_parameters)
  232. self.assertFalse(result['exists'])
  233. def test_that_when_checking_if_a_bucket_exists_and_boto3_returns_an_error_the_bucket_exists_method_returns_error(self):
  234. '''
  235. Tests checking s3 bucket existence when boto returns an error
  236. '''
  237. self.conn.head_bucket.side_effect = ClientError(error_content, 'head_bucket')
  238. result = boto_s3_bucket.exists(Bucket='mybucket', **conn_parameters)
  239. self.assertEqual(result.get('error', {}).get('message'), error_message.format('head_bucket'))
  240. def test_that_when_creating_a_bucket_succeeds_the_create_bucket_method_returns_true(self):
  241. '''
  242. tests True bucket created.
  243. '''
  244. self.conn.create_bucket.return_value = create_ret
  245. result = boto_s3_bucket.create(Bucket='mybucket',
  246. LocationConstraint='nowhere',
  247. **conn_parameters)
  248. self.assertTrue(result['created'])
  249. def test_that_when_creating_a_bucket_fails_the_create_bucket_method_returns_error(self):
  250. '''
  251. tests False bucket not created.
  252. '''
  253. self.conn.create_bucket.side_effect = ClientError(error_content, 'create_bucket')
  254. result = boto_s3_bucket.create(Bucket='mybucket',
  255. LocationConstraint='nowhere',
  256. **conn_parameters)
  257. self.assertEqual(result.get('error', {}).get('message'), error_message.format('create_bucket'))
  258. def test_that_when_deleting_a_bucket_succeeds_the_delete_bucket_method_returns_true(self):
  259. '''
  260. tests True bucket deleted.
  261. '''
  262. result = boto_s3_bucket.delete(Bucket='mybucket',
  263. **conn_parameters)
  264. self.assertTrue(result['deleted'])
  265. def test_that_when_deleting_a_bucket_fails_the_delete_bucket_method_returns_false(self):
  266. '''
  267. tests False bucket not deleted.
  268. '''
  269. self.conn.delete_bucket.side_effect = ClientError(error_content, 'delete_bucket')
  270. result = boto_s3_bucket.delete(Bucket='mybucket',
  271. **conn_parameters)
  272. self.assertFalse(result['deleted'])
  273. def test_that_when_describing_bucket_it_returns_the_dict_of_properties_returns_true(self):
  274. '''
  275. Tests describing parameters if bucket exists
  276. '''
  277. for key, value in six.iteritems(config_ret):
  278. getattr(self.conn, key).return_value = deepcopy(value)
  279. result = boto_s3_bucket.describe(Bucket='mybucket', **conn_parameters)
  280. self.assertTrue(result['bucket'])
  281. def test_that_when_describing_bucket_it_returns_the_dict_of_properties_returns_false(self):
  282. '''
  283. Tests describing parameters if bucket does not exist
  284. '''
  285. self.conn.get_bucket_acl.side_effect = not_found_error
  286. result = boto_s3_bucket.describe(Bucket='mybucket', **conn_parameters)
  287. self.assertFalse(result['bucket'])
  288. def test_that_when_describing_bucket_on_client_error_it_returns_error(self):
  289. '''
  290. Tests describing parameters failure
  291. '''
  292. self.conn.get_bucket_acl.side_effect = ClientError(error_content, 'get_bucket_acl')
  293. result = boto_s3_bucket.describe(Bucket='mybucket', **conn_parameters)
  294. self.assertTrue('error' in result)
  295. def test_that_when_listing_buckets_succeeds_the_list_buckets_method_returns_true(self):
  296. '''
  297. tests True buckets listed.
  298. '''
  299. self.conn.list_buckets.return_value = deepcopy(list_ret)
  300. result = boto_s3_bucket.list(**conn_parameters)
  301. self.assertTrue(result['Buckets'])
  302. def test_that_when_listing_bucket_fails_the_list_bucket_method_returns_false(self):
  303. '''
  304. tests False no bucket listed.
  305. '''
  306. ret = deepcopy(list_ret)
  307. log.info(ret)
  308. ret['Buckets'] = list()
  309. self.conn.list_buckets.return_value = ret
  310. result = boto_s3_bucket.list(**conn_parameters)
  311. self.assertFalse(result['Buckets'])
  312. def test_that_when_listing_bucket_fails_the_list_bucket_method_returns_error(self):
  313. '''
  314. tests False bucket error.
  315. '''
  316. self.conn.list_buckets.side_effect = ClientError(error_content, 'list_buckets')
  317. result = boto_s3_bucket.list(**conn_parameters)
  318. self.assertEqual(result.get('error', {}).get('message'), error_message.format('list_buckets'))
  319. def test_that_when_putting_acl_succeeds_the_put_acl_method_returns_true(self):
  320. '''
  321. tests True bucket updated.
  322. '''
  323. result = boto_s3_bucket.put_acl(Bucket='mybucket',
  324. **conn_parameters)
  325. self.assertTrue(result['updated'])
  326. def test_that_when_putting_acl_fails_the_put_acl_method_returns_error(self):
  327. '''
  328. tests False bucket not updated.
  329. '''
  330. self.conn.put_bucket_acl.side_effect = ClientError(error_content,
  331. 'put_bucket_acl')
  332. result = boto_s3_bucket.put_acl(Bucket='mybucket',
  333. **conn_parameters)
  334. self.assertEqual(result.get('error', {}).get('message'),
  335. error_message.format('put_bucket_acl'))
  336. def test_that_when_putting_cors_succeeds_the_put_cors_method_returns_true(self):
  337. '''
  338. tests True bucket updated.
  339. '''
  340. result = boto_s3_bucket.put_cors(Bucket='mybucket', CORSRules='[]',
  341. **conn_parameters)
  342. self.assertTrue(result['updated'])
  343. def test_that_when_putting_cors_fails_the_put_cors_method_returns_error(self):
  344. '''
  345. tests False bucket not updated.
  346. '''
  347. self.conn.put_bucket_cors.side_effect = ClientError(error_content,
  348. 'put_bucket_cors')
  349. result = boto_s3_bucket.put_cors(Bucket='mybucket', CORSRules='[]',
  350. **conn_parameters)
  351. self.assertEqual(result.get('error', {}).get('message'),
  352. error_message.format('put_bucket_cors'))
  353. def test_that_when_putting_lifecycle_configuration_succeeds_the_put_lifecycle_configuration_method_returns_true(self):
  354. '''
  355. tests True bucket updated.
  356. '''
  357. result = boto_s3_bucket.put_lifecycle_configuration(Bucket='mybucket',
  358. Rules='[]',
  359. **conn_parameters)
  360. self.assertTrue(result['updated'])
  361. def test_that_when_putting_lifecycle_configuration_fails_the_put_lifecycle_configuration_method_returns_error(self):
  362. '''
  363. tests False bucket not updated.
  364. '''
  365. self.conn.put_bucket_lifecycle_configuration.side_effect = ClientError(error_content,
  366. 'put_bucket_lifecycle_configuration')
  367. result = boto_s3_bucket.put_lifecycle_configuration(Bucket='mybucket',
  368. Rules='[]',
  369. **conn_parameters)
  370. self.assertEqual(result.get('error', {}).get('message'),
  371. error_message.format('put_bucket_lifecycle_configuration'))
  372. def test_that_when_putting_logging_succeeds_the_put_logging_method_returns_true(self):
  373. '''
  374. tests True bucket updated.
  375. '''
  376. result = boto_s3_bucket.put_logging(Bucket='mybucket',
  377. TargetBucket='arn:::::',
  378. TargetPrefix='asdf',
  379. TargetGrants='[]',
  380. **conn_parameters)
  381. self.assertTrue(result['updated'])
  382. def test_that_when_putting_logging_fails_the_put_logging_method_returns_error(self):
  383. '''
  384. tests False bucket not updated.
  385. '''
  386. self.conn.put_bucket_logging.side_effect = ClientError(error_content,
  387. 'put_bucket_logging')
  388. result = boto_s3_bucket.put_logging(Bucket='mybucket',
  389. TargetBucket='arn:::::',
  390. TargetPrefix='asdf',
  391. TargetGrants='[]',
  392. **conn_parameters)
  393. self.assertEqual(result.get('error', {}).get('message'),
  394. error_message.format('put_bucket_logging'))
  395. def test_that_when_putting_notification_configuration_succeeds_the_put_notification_configuration_method_returns_true(self):
  396. '''
  397. tests True bucket updated.
  398. '''
  399. result = boto_s3_bucket.put_notification_configuration(Bucket='mybucket',
  400. **conn_parameters)
  401. self.assertTrue(result['updated'])
  402. def test_that_when_putting_notification_configuration_fails_the_put_notification_configuration_method_returns_error(self):
  403. '''
  404. tests False bucket not updated.
  405. '''
  406. self.conn.put_bucket_notification_configuration.side_effect = ClientError(error_content,
  407. 'put_bucket_notification_configuration')
  408. result = boto_s3_bucket.put_notification_configuration(Bucket='mybucket',
  409. **conn_parameters)
  410. self.assertEqual(result.get('error', {}).get('message'),
  411. error_message.format('put_bucket_notification_configuration'))
  412. def test_that_when_putting_policy_succeeds_the_put_policy_method_returns_true(self):
  413. '''
  414. tests True bucket updated.
  415. '''
  416. result = boto_s3_bucket.put_policy(Bucket='mybucket',
  417. Policy='{}',
  418. **conn_parameters)
  419. self.assertTrue(result['updated'])
  420. def test_that_when_putting_policy_fails_the_put_policy_method_returns_error(self):
  421. '''
  422. tests False bucket not updated.
  423. '''
  424. self.conn.put_bucket_policy.side_effect = ClientError(error_content,
  425. 'put_bucket_policy')
  426. result = boto_s3_bucket.put_policy(Bucket='mybucket',
  427. Policy='{}',
  428. **conn_parameters)
  429. self.assertEqual(result.get('error', {}).get('message'),
  430. error_message.format('put_bucket_policy'))
  431. def test_that_when_putting_replication_succeeds_the_put_replication_method_returns_true(self):
  432. '''
  433. tests True bucket updated.
  434. '''
  435. result = boto_s3_bucket.put_replication(Bucket='mybucket',
  436. Role='arn:aws:iam:::',
  437. Rules='[]',
  438. **conn_parameters)
  439. self.assertTrue(result['updated'])
  440. def test_that_when_putting_replication_fails_the_put_replication_method_returns_error(self):
  441. '''
  442. tests False bucket not updated.
  443. '''
  444. self.conn.put_bucket_replication.side_effect = ClientError(error_content,
  445. 'put_bucket_replication')
  446. result = boto_s3_bucket.put_replication(Bucket='mybucket',
  447. Role='arn:aws:iam:::',
  448. Rules='[]',
  449. **conn_parameters)
  450. self.assertEqual(result.get('error', {}).get('message'),
  451. error_message.format('put_bucket_replication'))
  452. def test_that_when_putting_request_payment_succeeds_the_put_request_payment_method_returns_true(self):
  453. '''
  454. tests True bucket updated.
  455. '''
  456. result = boto_s3_bucket.put_request_payment(Bucket='mybucket',
  457. Payer='Requester',
  458. **conn_parameters)
  459. self.assertTrue(result['updated'])
  460. def test_that_when_putting_request_payment_fails_the_put_request_payment_method_returns_error(self):
  461. '''
  462. tests False bucket not updated.
  463. '''
  464. self.conn.put_bucket_request_payment.side_effect = ClientError(error_content,
  465. 'put_bucket_request_payment')
  466. result = boto_s3_bucket.put_request_payment(Bucket='mybucket',
  467. Payer='Requester',
  468. **conn_parameters)
  469. self.assertEqual(result.get('error', {}).get('message'),
  470. error_message.format('put_bucket_request_payment'))
  471. def test_that_when_putting_tagging_succeeds_the_put_tagging_method_returns_true(self):
  472. '''
  473. tests True bucket updated.
  474. '''
  475. result = boto_s3_bucket.put_tagging(Bucket='mybucket',
  476. **conn_parameters)
  477. self.assertTrue(result['updated'])
  478. def test_that_when_putting_tagging_fails_the_put_tagging_method_returns_error(self):
  479. '''
  480. tests False bucket not updated.
  481. '''
  482. self.conn.put_bucket_tagging.side_effect = ClientError(error_content,
  483. 'put_bucket_tagging')
  484. result = boto_s3_bucket.put_tagging(Bucket='mybucket',
  485. **conn_parameters)
  486. self.assertEqual(result.get('error', {}).get('message'),
  487. error_message.format('put_bucket_tagging'))
  488. def test_that_when_putting_versioning_succeeds_the_put_versioning_method_returns_true(self):
  489. '''
  490. tests True bucket updated.
  491. '''
  492. result = boto_s3_bucket.put_versioning(Bucket='mybucket',
  493. Status='Enabled',
  494. **conn_parameters)
  495. self.assertTrue(result['updated'])
  496. def test_that_when_putting_versioning_fails_the_put_versioning_method_returns_error(self):
  497. '''
  498. tests False bucket not updated.
  499. '''
  500. self.conn.put_bucket_versioning.side_effect = ClientError(error_content,
  501. 'put_bucket_versioning')
  502. result = boto_s3_bucket.put_versioning(Bucket='mybucket',
  503. Status='Enabled',
  504. **conn_parameters)
  505. self.assertEqual(result.get('error', {}).get('message'),
  506. error_message.format('put_bucket_versioning'))
  507. def test_that_when_putting_website_succeeds_the_put_website_method_returns_true(self):
  508. '''
  509. tests True bucket updated.
  510. '''
  511. result = boto_s3_bucket.put_website(Bucket='mybucket',
  512. **conn_parameters)
  513. self.assertTrue(result['updated'])
  514. def test_that_when_putting_website_fails_the_put_website_method_returns_error(self):
  515. '''
  516. tests False bucket not updated.
  517. '''
  518. self.conn.put_bucket_website.side_effect = ClientError(error_content,
  519. 'put_bucket_website')
  520. result = boto_s3_bucket.put_website(Bucket='mybucket',
  521. **conn_parameters)
  522. self.assertEqual(result.get('error', {}).get('message'),
  523. error_message.format('put_bucket_website'))
  524. def test_that_when_deleting_cors_succeeds_the_delete_cors_method_returns_true(self):
  525. '''
  526. tests True bucket attribute deleted.
  527. '''
  528. result = boto_s3_bucket.delete_cors(Bucket='mybucket',
  529. **conn_parameters)
  530. self.assertTrue(result['deleted'])
  531. def test_that_when_deleting_cors_fails_the_delete_cors_method_returns_error(self):
  532. '''
  533. tests False bucket attribute not deleted.
  534. '''
  535. self.conn.delete_bucket_cors.side_effect = ClientError(error_content,
  536. 'delete_bucket_cors')
  537. result = boto_s3_bucket.delete_cors(Bucket='mybucket',
  538. **conn_parameters)
  539. self.assertEqual(result.get('error', {}).get('message'),
  540. error_message.format('delete_bucket_cors'))
  541. def test_that_when_deleting_lifecycle_configuration_succeeds_the_delete_lifecycle_configuration_method_returns_true(self):
  542. '''
  543. tests True bucket attribute deleted.
  544. '''
  545. result = boto_s3_bucket.delete_lifecycle_configuration(Bucket='mybucket',
  546. **conn_parameters)
  547. self.assertTrue(result['deleted'])
  548. def test_that_when_deleting_lifecycle_configuration_fails_the_delete_lifecycle_configuration_method_returns_error(self):
  549. '''
  550. tests False bucket attribute not deleted.
  551. '''
  552. self.conn.delete_bucket_lifecycle.side_effect = ClientError(error_content,
  553. 'delete_bucket_lifecycle_configuration')
  554. result = boto_s3_bucket.delete_lifecycle_configuration(Bucket='mybucket',
  555. **conn_parameters)
  556. self.assertEqual(result.get('error', {}).get('message'),
  557. error_message.format('delete_bucket_lifecycle_configuration'))
  558. def test_that_when_deleting_policy_succeeds_the_delete_policy_method_returns_true(self):
  559. '''
  560. tests True bucket attribute deleted.
  561. '''
  562. result = boto_s3_bucket.delete_policy(Bucket='mybucket',
  563. **conn_parameters)
  564. self.assertTrue(result['deleted'])
  565. def test_that_when_deleting_policy_fails_the_delete_policy_method_returns_error(self):
  566. '''
  567. tests False bucket attribute not deleted.
  568. '''
  569. self.conn.delete_bucket_policy.side_effect = ClientError(error_content,
  570. 'delete_bucket_policy')
  571. result = boto_s3_bucket.delete_policy(Bucket='mybucket',
  572. **conn_parameters)
  573. self.assertEqual(result.get('error', {}).get('message'),
  574. error_message.format('delete_bucket_policy'))
  575. def test_that_when_deleting_replication_succeeds_the_delete_replication_method_returns_true(self):
  576. '''
  577. tests True bucket attribute deleted.
  578. '''
  579. result = boto_s3_bucket.delete_replication(Bucket='mybucket',
  580. **conn_parameters)
  581. self.assertTrue(result['deleted'])
  582. def test_that_when_deleting_replication_fails_the_delete_replication_method_returns_error(self):
  583. '''
  584. tests False bucket attribute not deleted.
  585. '''
  586. self.conn.delete_bucket_replication.side_effect = ClientError(error_content,
  587. 'delete_bucket_replication')
  588. result = boto_s3_bucket.delete_replication(Bucket='mybucket',
  589. **conn_parameters)
  590. self.assertEqual(result.get('error', {}).get('message'),
  591. error_message.format('delete_bucket_replication'))
  592. def test_that_when_deleting_tagging_succeeds_the_delete_tagging_method_returns_true(self):
  593. '''
  594. tests True bucket attribute deleted.
  595. '''
  596. result = boto_s3_bucket.delete_tagging(Bucket='mybucket',
  597. **conn_parameters)
  598. self.assertTrue(result['deleted'])
  599. def test_that_when_deleting_tagging_fails_the_delete_tagging_method_returns_error(self):
  600. '''
  601. tests False bucket attribute not deleted.
  602. '''
  603. self.conn.delete_bucket_tagging.side_effect = ClientError(error_content,
  604. 'delete_bucket_tagging')
  605. result = boto_s3_bucket.delete_tagging(Bucket='mybucket',
  606. **conn_parameters)
  607. self.assertEqual(result.get('error', {}).get('message'),
  608. error_message.format('delete_bucket_tagging'))
  609. def test_that_when_deleting_website_succeeds_the_delete_website_method_returns_true(self):
  610. '''
  611. tests True bucket attribute deleted.
  612. '''
  613. result = boto_s3_bucket.delete_website(Bucket='mybucket',
  614. **conn_parameters)
  615. self.assertTrue(result['deleted'])
  616. def test_that_when_deleting_website_fails_the_delete_website_method_returns_error(self):
  617. '''
  618. tests False bucket attribute not deleted.
  619. '''
  620. self.conn.delete_bucket_website.side_effect = ClientError(error_content,
  621. 'delete_bucket_website')
  622. result = boto_s3_bucket.delete_website(Bucket='mybucket',
  623. **conn_parameters)
  624. self.assertEqual(result.get('error', {}).get('message'),
  625. error_message.format('delete_bucket_website'))