Skip to content

Commit 5cb8f4d

Browse files
committed
More patch changes
1 parent 2a172a6 commit 5cb8f4d

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

tests/test_minio_adapter.py

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2626
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2727
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28-
from unittest.mock import AsyncMock
2928
import urllib.parse
3029

3130
import pytest
@@ -48,14 +47,6 @@ def mock_downloader(**args):
4847
open("/tmp/foo/test.txt", "wb").write(b"\x01" * 10)
4948

5049

51-
@fixture
52-
def download_patch():
53-
import aioboto3.s3.inject
54-
55-
aioboto3.s3.inject.download_file = AsyncMock(side_effect=mock_downloader)
56-
return aioboto3.s3.inject.download_file
57-
58-
5950
@fixture
6051
def minio_adapter(moto_services, moto_patch_session) -> MinioAdapter:
6152
urlinfo = urllib.parse.urlparse(moto_services["s3"])
@@ -64,7 +55,7 @@ def minio_adapter(moto_services, moto_patch_session) -> MinioAdapter:
6455
)
6556

6657

67-
@fixture
58+
@fixture(scope="function")
6859
async def populate_bucket(request, minio_adapter):
6960
async with minio_adapter.minio.client(
7061
"s3", endpoint_url=minio_adapter.endpoint_host
@@ -173,16 +164,6 @@ async def test_download_short_filename_change(minio_adapter, populate_bucket):
173164
result.unlink() # it should exist, from above ...
174165

175166

176-
@pytest.mark.parametrize("populate_bucket", ["test.txt"], indirect=True)
177-
@pytest.mark.asyncio
178-
async def test_download_file_retry(download_patch, minio_adapter, populate_bucket):
179-
result = await minio_adapter.download_file("test.txt", local_dir="/tmp/foo")
180-
assert str(result).endswith("test.txt")
181-
assert result.exists()
182-
assert len(download_patch.call_args_list) == 3
183-
result.unlink()
184-
185-
186167
@pytest.mark.parametrize("populate_bucket", ["test2.txt"], indirect=True)
187168
@pytest.mark.asyncio
188169
async def test_download_repeat(minio_adapter, populate_bucket):
@@ -202,7 +183,21 @@ async def test_download_repeat(minio_adapter, populate_bucket):
202183
result.unlink() # it should exist, from above ...
203184

204185

186+
@pytest.mark.parametrize("populate_bucket", ["test.txt"], indirect=True)
205187
@pytest.mark.asyncio
206-
async def test_get_signed_url(minio_adapter, moto_services):
188+
async def test_get_signed_url(minio_adapter, moto_services, populate_bucket):
207189
result = await minio_adapter.get_signed_url("test.txt")
208190
assert result.startswith(moto_services["s3"])
191+
192+
193+
@pytest.mark.parametrize("populate_bucket", ["test.txt"], indirect=True)
194+
@pytest.mark.asyncio
195+
async def test_download_file_retry(minio_adapter, populate_bucket, mocker):
196+
download_patch = mocker.patch(
197+
"aioboto3.s3.inject.download_file", side_effect=mock_downloader
198+
)
199+
result = await minio_adapter.download_file("test.txt", local_dir="/tmp/foo")
200+
assert str(result).endswith("test.txt")
201+
assert result.exists()
202+
assert download_patch.call_count == 3
203+
result.unlink()

0 commit comments

Comments
 (0)