1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
community.general/test/units/modules/cloud/amazon/test_s3.py
Sloane Hertel 1de91a9aa0 [cloud] Convert s3 module to use boto3 (#21529)
* replace boto with boto3 for the s3 module

make s3 pep8 and remove from legacy files

fix s3 unit tests

* fix indentation

* s3 module - if we can't create an MD5 sum return None and always upload file

* remove Location.DEFAULT which isn't used in boto3 and tidy up the docs

* pep8

* s3: remove default: null, empty aliases, and required: false from documentation

fix incorrectly documented defaults

* Porting s3 to boto3. Simplify some logic and remove unused imports

* Fix s3 module variables

* Fix a typo in s3 module and remove from pep8 legacy files

* s3: add pagination for listing objects.

Fix logic and use head_object instead of get_object for efficiency.

Fix typo in unit test.

* Fix pagination to maintain backwards compatibility.

Fix incorrect conditional.

Remove redundant variable assignment.

Fix s3 list_object pagination to return all pages

* Use the revised List Objects API as recommended.

* Wrap call to paginated_list in a try/except

Also remembered to allow marker/prefix/max_keys to modify what keys are listed

* Simplify argument
2017-08-11 09:34:33 -04:00

37 lines
1.3 KiB
Python

import pytest
import unittest
import ansible.modules.cloud.amazon.s3 as s3
from ansible.module_utils.six.moves.urllib.parse import urlparse
boto3 = pytest.importorskip("boto3")
class TestUrlparse(unittest.TestCase):
def test_urlparse(self):
actual = urlparse("http://test.com/here")
self.assertEqual("http", actual.scheme)
self.assertEqual("test.com", actual.netloc)
self.assertEqual("/here", actual.path)
def test_is_fakes3(self):
actual = s3.is_fakes3("fakes3://bla.blubb")
self.assertEqual(True, actual)
def test_is_walrus(self):
actual = s3.is_walrus("trulywalrus_but_invalid_url")
# I don't know if this makes sense, but this is the current behaviour...
self.assertEqual(True, actual)
actual = s3.is_walrus("http://notwalrus.amazonaws.com")
self.assertEqual(False, actual)
def test_get_s3_connection(self):
aws_connect_kwargs = dict(aws_access_key_id="access_key",
aws_secret_access_key="secret_key")
location = None
rgw = True
s3_url = "http://bla.blubb"
actual = s3.get_s3_connection(None, aws_connect_kwargs, location, rgw, s3_url)
self.assertEqual(bool("bla.blubb" in str(actual._endpoint)), True)