fix(upload): identify image host requests
This commit is contained in:
1 parent
d6d90f6753
commit
fd4e7b395f
4 files changed
+18
-4
No files matched your search
@@ -1,10 +1,20 @@
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from app.belki.image_host import ImageHostClient, ImageHostError
|
||||
|
||||
|
||||
class ImageHostClientTests(unittest.TestCase):
|
||||
def test_initiate_identifies_the_belki_client(self) -> None:
|
||||
client = ImageHostClient(api_url="https://api.example.test")
|
||||
response = MagicMock()
|
||||
response.__enter__.return_value = response
|
||||
with patch("app.belki.image_host.urlopen", return_value=response) as urlopen:
|
||||
with patch("app.belki.image_host.json.load", return_value={"files": []}):
|
||||
client._request_json("/api/uploads/initiate", {"files": []})
|
||||
request = urlopen.call_args.args[0]
|
||||
self.assertEqual(request.get_header("User-agent"), "BelkiCalculator/1.0 (+https://cat.nyan404.ru/belki)")
|
||||
|
||||
def test_upload_wraps_presigned_put_failure(self) -> None:
|
||||
client = ImageHostClient(api_url="https://api.example.test")
|
||||
with patch.object(client, "_request_json", return_value={"files": [{"uploadUrl": "https://storage.example.test/upload"}]}):
|
||||
|
||||
Reference in new issue
Block a user