Skip to content

Commit

Permalink
Merge pull request #952 from lsst/tickets/DM-42698
Browse files Browse the repository at this point in the history
DM-42698: Support moto v5
  • Loading branch information
timj committed Jan 31, 2024
2 parents 1dd62dc + 11955df commit 97c358c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
16 changes: 10 additions & 6 deletions tests/test_butler.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,16 @@
import boto3
import botocore
from lsst.resources.s3utils import clean_test_environment_for_s3
from moto import mock_s3 # type: ignore[import]

try:
from moto import mock_aws # v5
except ImportError:
from moto import mock_s3 as mock_aws
except ImportError:
boto3 = None

def mock_s3(*args: Any, **kwargs: Any) -> Any: # type: ignore[no-untyped-def]
"""No-op decorator in case moto mock_s3 can not be imported."""
def mock_aws(*args: Any, **kwargs: Any) -> Any: # type: ignore[no-untyped-def]
"""No-op decorator in case moto mock_aws can not be imported."""
return None


Expand Down Expand Up @@ -2025,7 +2029,7 @@ class S3DatastoreButlerTestCase(FileDatastoreButlerTests, unittest.TestCase):
registryStr = "/gen3.sqlite3"
"""Expected format of the Registry string."""

mock_s3 = mock_s3()
mock_aws = mock_aws()
"""The mocked s3 interface from moto."""

def genRoot(self) -> str:
Expand All @@ -2045,7 +2049,7 @@ def setUp(self) -> None:

# Enable S3 mocking of tests.
self.enterContext(clean_test_environment_for_s3())
self.mock_s3.start()
self.mock_aws.start()

if self.useTempRoot:
self.root = self.genRoot()
Expand Down Expand Up @@ -2082,7 +2086,7 @@ def tearDown(self) -> None:
bucket.delete()

# Stop the S3 mock.
self.mock_s3.stop()
self.mock_aws.stop()

if self.reg_dir is not None and os.path.exists(self.reg_dir):
shutil.rmtree(self.reg_dir, ignore_errors=True)
Expand Down
8 changes: 6 additions & 2 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@
from lsst.daf.butler.remote_butler.server._dependencies import butler_factory_dependency
from lsst.daf.butler.tests.server_utils import add_auth_header_check_middleware
from lsst.resources.s3utils import clean_test_environment_for_s3, getS3Client
from moto import mock_s3

try:
from moto import mock_aws # v5
except ImportError:
from moto import mock_s3 as mock_aws
except ImportError:
TestClient = None
create_app = None
Expand Down Expand Up @@ -100,7 +104,7 @@ def setUpClass(cls):
# redirected to the mocked S3.
# Note that all files are stored in memory.
cls.enterClassContext(clean_test_environment_for_s3())
cls.enterClassContext(mock_s3())
cls.enterClassContext(mock_aws())
bucket_name = "anybucketname" # matches s3Datastore.yaml
getS3Client().create_bucket(Bucket=bucket_name)

Expand Down

0 comments on commit 97c358c

Please sign in to comment.