Skip to content

Commit b640559

Browse files
committed
Allow --download to work with --use-mocks
1 parent 6585e17 commit b640559

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

firefly/cli.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@
1818

1919

2020
def use_requests_mock():
21-
rsps = responses.RequestsMock()
21+
rsps = responses.RequestsMock(assert_all_requests_are_fired=False)
2222
rsps.start()
2323

2424
ims_url = "https://ims-na1.adobelogin.com/ims/token/v3"
2525
image_url = "https://firefly-api.adobe.io/v3/images/generate"
2626
mock_image = "https://clio-assets.adobe.com/clio-playground/image-style-zeros/v3/images/Photo_manipulation/4.jpg"
27+
with open("tests/images/4.jpg", "rb") as img_file:
28+
img_data = img_file.read()
29+
2730
rsps.add(
2831
responses.POST,
2932
ims_url,
@@ -42,6 +45,14 @@ def use_requests_mock():
4245
},
4346
status=200,
4447
)
48+
# Add mock for the image download
49+
rsps.add(
50+
responses.GET,
51+
mock_image,
52+
body=img_data,
53+
status=200,
54+
content_type="image/jpeg",
55+
)
4556

4657
return rsps
4758

@@ -67,7 +78,8 @@ def download_image(image_url: str):
6778
filename = os.path.basename(path)
6879
with open(filename, "wb") as f:
6980
f.write(r.content)
70-
typer.echo(f"Image downloaded to {filename}")
81+
size = len(r.content)
82+
typer.echo(f"Downloaded image ({size} bytes) to {filename}")
7183

7284

7385
@app.command()

tests/images/4.jpg

298 KB
Loading

0 commit comments

Comments
 (0)