When using Amazon S3 cloud storage, it's helpful to mock the S3 service for testing. That way, test can run without actually needing to contact S3 and move data in and out of it.
Fortunately there is a very helpful S3 mocking library available for python called moto.
To use it:
from moto import mock_s3
# Mock s3 to create that bucket and path.
moto = mock_s3()
moto.start() # begin 'mock mode'
conn = boto.connect_s3() # mock connection
bucket = conn.create_bucket(s3bucket)
# Now mock the lockfile.
key = Key(bucket)
key.key = s3path
test_data = base_dir + '/data/client1.json'
key.set_contents_from_filename(test_data)
# Now check that (mocked) file is there.
result = main.lock_exists(s3bucket, s3path)
assert result == True
# End mock mode.
moto.stop()
No comments:
Post a Comment