解决登录和oss问题
This commit is contained in:
1 parent
30c2e44dc0
commit
cd007e2f6a
15 files changed
+154
-12
No files matched your search
@@ -0,0 +1,58 @@
|
||||
from io import BytesIO
|
||||
from types import SimpleNamespace
|
||||
|
||||
from app.routers import admin as admin_router
|
||||
|
||||
|
||||
class FakeOssResponse:
|
||||
status = 200
|
||||
|
||||
def read(self, _size: int) -> bytes:
|
||||
return b""
|
||||
|
||||
|
||||
class FakeOssConnection:
|
||||
instances: list["FakeOssConnection"] = []
|
||||
|
||||
def __init__(self, host: str, timeout: int):
|
||||
self.host = host
|
||||
self.timeout = timeout
|
||||
self.request_path: str | None = None
|
||||
self.__class__.instances.append(self)
|
||||
|
||||
def request(self, _method, path, **_kwargs) -> None:
|
||||
self.request_path = path
|
||||
|
||||
def getresponse(self) -> FakeOssResponse:
|
||||
return FakeOssResponse()
|
||||
|
||||
def close(self) -> None:
|
||||
pass
|
||||
|
||||
|
||||
def test_upload_uses_internal_endpoint_but_returns_public_url(monkeypatch):
|
||||
FakeOssConnection.instances.clear()
|
||||
monkeypatch.setattr(
|
||||
admin_router,
|
||||
"oss_settings",
|
||||
lambda: SimpleNamespace(
|
||||
oss_access_key_id="test-access-key",
|
||||
oss_access_key_secret="test-access-secret",
|
||||
oss_endpoint="oss-cn-guangzhou-internal.aliyuncs.com",
|
||||
oss_public_base_url="https://one-feel-ota-data.oss-cn-guangzhou.aliyuncs.com",
|
||||
oss_bucket_name="one-feel-ota-data",
|
||||
),
|
||||
)
|
||||
monkeypatch.setattr(admin_router.http.client, "HTTPSConnection", FakeOssConnection)
|
||||
|
||||
url = admin_router.upload_image_to_oss(
|
||||
BytesIO(b"image"),
|
||||
"admin/general/image.webp",
|
||||
"image/webp",
|
||||
5,
|
||||
)
|
||||
|
||||
connection = FakeOssConnection.instances[0]
|
||||
assert connection.host == "one-feel-ota-data.oss-cn-guangzhou-internal.aliyuncs.com"
|
||||
assert connection.request_path == "/admin/general/image.webp"
|
||||
assert url == "https://one-feel-ota-data.oss-cn-guangzhou.aliyuncs.com/admin/general/image.webp"
|
||||
Reference in new issue
Block a user