|
@@ -14,8 +14,33 @@ from unittest.mock import AsyncMock, patch
|
|
|
|
|
|
|
|
import pytest
|
|
import pytest
|
|
|
|
|
|
|
|
-from backend.app.api.routes.makerworld import _canonical_url
|
|
|
|
|
|
|
+from backend.app.api.routes import makerworld as makerworld_routes
|
|
|
|
|
+from backend.app.core.permissions import Permission
|
|
|
from backend.app.models.library import LibraryFile, LibraryFolder
|
|
from backend.app.models.library import LibraryFile, LibraryFolder
|
|
|
|
|
+from backend.app.services.model_providers.base import (
|
|
|
|
|
+ ModelProvider,
|
|
|
|
|
+ ProviderDownload,
|
|
|
|
|
+ ProviderDownloadInfo,
|
|
|
|
|
+ ProviderResolvedModel,
|
|
|
|
|
+ ProviderResourceRef,
|
|
|
|
|
+ ProviderStatus,
|
|
|
|
|
+)
|
|
|
|
|
+from backend.app.services.model_providers.makerworld import makerworld_provider
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def _download_info(
|
|
|
|
|
+ model_id: int = 1400373,
|
|
|
|
|
+ profile_id: int = 298919107,
|
|
|
|
|
+ name: str = "benchy.3mf",
|
|
|
|
|
+ url: str = "https://makerworld.bblmw.com/makerworld/model/X/Y/f.3mf?exp=1&key=k",
|
|
|
|
|
+) -> ProviderDownloadInfo:
|
|
|
|
|
+ """What ``service.get_download`` hands the route: signed URL + raw upstream
|
|
|
|
|
+ name + the enriched resource ref (``sub_id`` carries the resolved profile)."""
|
|
|
|
|
+ return ProviderDownloadInfo(
|
|
|
|
|
+ ref=ProviderResourceRef(source_type="makerworld", external_id=str(model_id), sub_id=str(profile_id)),
|
|
|
|
|
+ url=url,
|
|
|
|
|
+ suggested_filename=name,
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
|
|
|
|
|
def _fake_service(**stubs):
|
|
def _fake_service(**stubs):
|
|
@@ -30,37 +55,117 @@ def _fake_service(**stubs):
|
|
|
return svc
|
|
return svc
|
|
|
|
|
|
|
|
|
|
|
|
|
-def _default_design(alphanumeric: str = "US2bb73b106683e5", model_id: int = 1400373):
|
|
|
|
|
- """Shape the backend needs from ``/design/{id}``: the alphanumeric
|
|
|
|
|
- ``modelId`` field that iot-service requires, plus at least one instance
|
|
|
|
|
- so the importer has a ``profile_id`` to fall back on."""
|
|
|
|
|
- return {
|
|
|
|
|
- "id": model_id,
|
|
|
|
|
- "modelId": alphanumeric,
|
|
|
|
|
- "title": "Seed Starter",
|
|
|
|
|
- "instances": [{"profileId": 298919107, "title": "9 cells"}],
|
|
|
|
|
- }
|
|
|
|
|
|
|
+class _DummyProvider(ModelProvider):
|
|
|
|
|
+ """Stand-in for a second registered model provider.
|
|
|
|
|
|
|
|
|
|
+ Lets the route tests exercise behaviour that differs from the MakerWorld
|
|
|
|
|
+ singleton — a provider-specific default folder name (or none at all), and
|
|
|
|
|
+ its own permissions — without registering anything in the app-wide
|
|
|
|
|
+ registry. The permissions deliberately are *not* the MakerWorld ones: the
|
|
|
|
|
+ routes must gate on whichever provider the request resolved to.
|
|
|
|
|
+ """
|
|
|
|
|
|
|
|
-def _default_manifest(name: str = "benchy.3mf"):
|
|
|
|
|
- return {
|
|
|
|
|
- "name": name,
|
|
|
|
|
- "url": "https://makerworld.bblmw.com/makerworld/model/X/Y/f.3mf?exp=1&key=k",
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ source_type = "dummy"
|
|
|
|
|
+ display_name = "Dummy"
|
|
|
|
|
|
|
|
|
|
+ def __init__(
|
|
|
|
|
+ self,
|
|
|
|
|
+ default_folder_name: str | None = "Dummy Imports",
|
|
|
|
|
+ view_permission: Permission | None = Permission.LIBRARY_READ,
|
|
|
|
|
+ import_permission: Permission | None = Permission.LIBRARY_UPLOAD,
|
|
|
|
|
+ ):
|
|
|
|
|
+ self.default_folder_name = default_folder_name
|
|
|
|
|
+ self.view_permission = view_permission
|
|
|
|
|
+ self.import_permission = import_permission
|
|
|
|
|
|
|
|
-class TestCanonicalUrl:
|
|
|
|
|
- """Unit test the dedupe-key builder directly — regressions break dedupe
|
|
|
|
|
- silently so it's worth pinning the exact shape."""
|
|
|
|
|
|
|
+ async def build_service(self, *, db, user, api_key_owner=None, client=None):
|
|
|
|
|
+ raise NotImplementedError
|
|
|
|
|
|
|
|
- def test_without_profile_id(self):
|
|
|
|
|
- assert _canonical_url(1400373) == "https://makerworld.com/models/1400373"
|
|
|
|
|
|
|
+ def parse_url(self, url):
|
|
|
|
|
+ return ProviderResourceRef(source_type=self.source_type, external_id="1400373", original_url=url)
|
|
|
|
|
|
|
|
- def test_without_profile_id_when_none(self):
|
|
|
|
|
- assert _canonical_url(1400373, None) == "https://makerworld.com/models/1400373"
|
|
|
|
|
|
|
+ def canonical_url(self, ref):
|
|
|
|
|
+ return f"https://dummy.example.com/models/{ref.external_id}"
|
|
|
|
|
|
|
|
- def test_with_profile_id(self):
|
|
|
|
|
- assert _canonical_url(1400373, 298919107) == ("https://makerworld.com/models/1400373#profileId-298919107")
|
|
|
|
|
|
|
+
|
|
|
|
|
+def _permission_spy():
|
|
|
|
|
+ """Record which permission the route hands the shared gate.
|
|
|
|
|
+
|
|
|
|
|
+ The gate itself still runs — the spy delegates to the real factory — so a
|
|
|
|
|
+ test using it proves the wiring without loosening the check.
|
|
|
|
|
+ """
|
|
|
|
|
+ seen: list = []
|
|
|
|
|
+ real = makerworld_routes.require_permission_if_auth_enabled
|
|
|
|
|
+
|
|
|
|
|
+ def factory(*permissions):
|
|
|
|
|
+ seen.extend(permissions)
|
|
|
|
|
+ return real(*permissions)
|
|
|
|
|
+
|
|
|
|
|
+ return seen, factory
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+class TestThumbnail:
|
|
|
|
|
+ """GET /makerworld/thumbnail — the anonymous CDN image proxy."""
|
|
|
|
|
+
|
|
|
|
|
+ def _patch_service(self, svc):
|
|
|
|
|
+ return patch("backend.app.api.routes.makerworld.MakerWorldService", return_value=svc)
|
|
|
|
|
+
|
|
|
|
|
+ @pytest.mark.asyncio
|
|
|
|
|
+ async def test_proxies_image_with_immutable_cache(self, async_client):
|
|
|
|
|
+ from unittest.mock import MagicMock
|
|
|
|
|
+
|
|
|
|
|
+ svc = MagicMock()
|
|
|
|
|
+ svc.fetch_thumbnail = AsyncMock(return_value=(b"png-bytes", "image/png"))
|
|
|
|
|
+ svc.close = AsyncMock()
|
|
|
|
|
+
|
|
|
|
|
+ with self._patch_service(svc):
|
|
|
|
|
+ resp = await async_client.get(
|
|
|
|
|
+ "/api/v1/makerworld/thumbnail",
|
|
|
|
|
+ params={"url": "https://makerworld.bblmw.com/img/x.png"},
|
|
|
|
|
+ )
|
|
|
|
|
+ assert resp.status_code == 200, resp.text
|
|
|
|
|
+ assert resp.content == b"png-bytes"
|
|
|
|
|
+ assert resp.headers["content-type"] == "image/png"
|
|
|
|
|
+ assert "immutable" in resp.headers["cache-control"]
|
|
|
|
|
+ # The SSRF allowlist is the provider's declared seam, not a local
|
|
|
|
|
+ # copy inside the route (review round 2).
|
|
|
|
|
+ assert svc.fetch_thumbnail.await_args.args[0] == "https://makerworld.bblmw.com/img/x.png"
|
|
|
|
|
+ svc.close.assert_awaited_once()
|
|
|
|
|
+
|
|
|
|
|
+ @pytest.mark.asyncio
|
|
|
|
|
+ async def test_allowlist_comes_from_the_provider_descriptor(self, async_client):
|
|
|
|
|
+ from unittest.mock import MagicMock
|
|
|
|
|
+
|
|
|
|
|
+ svc = MagicMock()
|
|
|
|
|
+ svc.fetch_thumbnail = AsyncMock(return_value=(b"x", "image/png"))
|
|
|
|
|
+ svc.close = AsyncMock()
|
|
|
|
|
+
|
|
|
|
|
+ with self._patch_service(svc) as cls:
|
|
|
|
|
+ await async_client.get(
|
|
|
|
|
+ "/api/v1/makerworld/thumbnail",
|
|
|
|
|
+ params={"url": "https://makerworld.bblmw.com/img/x.png"},
|
|
|
|
|
+ )
|
|
|
|
|
+ assert cls.call_args.kwargs["thumbnail_hosts"] == makerworld_provider.thumbnail_hosts()
|
|
|
|
|
+
|
|
|
|
|
+ @pytest.mark.asyncio
|
|
|
|
|
+ async def test_non_cdn_host_is_a_clean_400(self, async_client):
|
|
|
|
|
+ from unittest.mock import MagicMock
|
|
|
|
|
+
|
|
|
|
|
+ from backend.app.services.model_providers.makerworld.errors import MakerWorldUrlError
|
|
|
|
|
+
|
|
|
|
|
+ svc = MagicMock()
|
|
|
|
|
+ svc.fetch_thumbnail = AsyncMock(
|
|
|
|
|
+ side_effect=MakerWorldUrlError("Refusing to fetch thumbnail from non-MakerWorld host: 'evil.example'")
|
|
|
|
|
+ )
|
|
|
|
|
+ svc.close = AsyncMock()
|
|
|
|
|
+
|
|
|
|
|
+ with self._patch_service(svc):
|
|
|
|
|
+ resp = await async_client.get(
|
|
|
|
|
+ "/api/v1/makerworld/thumbnail",
|
|
|
|
|
+ params={"url": "https://evil.example/x.png"},
|
|
|
|
|
+ )
|
|
|
|
|
+ assert resp.status_code == 400
|
|
|
|
|
+ svc.close.assert_awaited_once()
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestStatus:
|
|
class TestStatus:
|
|
@@ -79,8 +184,8 @@ class TestStatus:
|
|
|
used to be a bare alias for ``has_cloud_token``, so the import button
|
|
used to be a bare alias for ``has_cloud_token``, so the import button
|
|
|
stayed live against a dead credential and the user only found out via a
|
|
stayed live against a dead credential and the user only found out via a
|
|
|
401 toast."""
|
|
401 toast."""
|
|
|
- from backend.app.api.routes.cloud import CLOUD_TOKEN_INVALID_KEY, CLOUD_TOKEN_KEY
|
|
|
|
|
from backend.app.models.settings import Settings
|
|
from backend.app.models.settings import Settings
|
|
|
|
|
+ from backend.app.services.bambu_cloud_credentials import CLOUD_TOKEN_INVALID_KEY, CLOUD_TOKEN_KEY
|
|
|
|
|
|
|
|
db_session.add(Settings(key=CLOUD_TOKEN_KEY, value="dead-token"))
|
|
db_session.add(Settings(key=CLOUD_TOKEN_KEY, value="dead-token"))
|
|
|
db_session.add(Settings(key=CLOUD_TOKEN_INVALID_KEY, value="2026-07-14T07:00:00+00:00"))
|
|
db_session.add(Settings(key=CLOUD_TOKEN_INVALID_KEY, value="2026-07-14T07:00:00+00:00"))
|
|
@@ -94,6 +199,33 @@ class TestStatus:
|
|
|
"sign_in_expired": True,
|
|
"sign_in_expired": True,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @pytest.mark.asyncio
|
|
|
|
|
+ async def test_sign_in_expired_reads_credential_rejected_not_auth_error(self, async_client):
|
|
|
|
|
+ """The route keys ``sign_in_expired`` off the machine-readable
|
|
|
|
|
+ ``credential_rejected`` flag, not ``auth_error`` (review round 3 note 1):
|
|
|
|
|
+ ``auth_error`` is the human-readable reason and may be set for non-
|
|
|
|
|
+ credential failures too. A service reporting an expired credential
|
|
|
|
|
+ *without* a message must still surface ``sign_in_expired=True``."""
|
|
|
|
|
+ svc = AsyncMock()
|
|
|
|
|
+ svc.close = AsyncMock()
|
|
|
|
|
+ svc.get_status = AsyncMock(
|
|
|
|
|
+ return_value=ProviderStatus(
|
|
|
|
|
+ authenticated=True,
|
|
|
|
|
+ can_download=False,
|
|
|
|
|
+ auth_error=None,
|
|
|
|
|
+ credential_rejected=True,
|
|
|
|
|
+ )
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ with patch("backend.app.api.routes.makerworld._build_service", AsyncMock(return_value=svc)):
|
|
|
|
|
+ resp = await async_client.get("/api/v1/makerworld/status")
|
|
|
|
|
+ assert resp.status_code == 200
|
|
|
|
|
+ assert resp.json() == {
|
|
|
|
|
+ "has_cloud_token": True,
|
|
|
|
|
+ "can_download": False,
|
|
|
|
|
+ "sign_in_expired": True,
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
|
|
|
class TestResolve:
|
|
class TestResolve:
|
|
|
@pytest.mark.asyncio
|
|
@pytest.mark.asyncio
|
|
@@ -102,20 +234,25 @@ class TestResolve:
|
|
|
"/api/v1/makerworld/resolve",
|
|
"/api/v1/makerworld/resolve",
|
|
|
json={"url": "https://thingiverse.com/thing/1"},
|
|
json={"url": "https://thingiverse.com/thing/1"},
|
|
|
)
|
|
)
|
|
|
|
|
+ # A pasted link for an unsupported host is a clean client-input 400,
|
|
|
|
|
+ # never a 500 — the registry guard runs before any provider call.
|
|
|
assert resp.status_code == 400
|
|
assert resp.status_code == 400
|
|
|
- assert "makerworld" in resp.json()["detail"].lower()
|
|
|
|
|
|
|
+ assert "provider" in resp.json()["detail"].lower()
|
|
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
@pytest.mark.asyncio
|
|
|
async def test_happy_path_returns_design_and_instances(self, async_client):
|
|
async def test_happy_path_returns_design_and_instances(self, async_client):
|
|
|
design_payload = {"id": 1400373, "title": "Seed Starter"}
|
|
design_payload = {"id": 1400373, "title": "Seed Starter"}
|
|
|
- instances_payload = {
|
|
|
|
|
- "total": 2,
|
|
|
|
|
- "hits": [
|
|
|
|
|
- {"id": 1452154, "profileId": 298919107, "title": "9 cells"},
|
|
|
|
|
- {"id": 1452158, "profileId": 298919564, "title": "12 cells"},
|
|
|
|
|
- ],
|
|
|
|
|
- }
|
|
|
|
|
- svc = _fake_service(get_design=design_payload, get_design_instances=instances_payload)
|
|
|
|
|
|
|
+ instances_payload = [
|
|
|
|
|
+ {"id": 1452154, "profileId": 298919107, "title": "9 cells"},
|
|
|
|
|
+ {"id": 1452158, "profileId": 298919564, "title": "12 cells"},
|
|
|
|
|
+ ]
|
|
|
|
|
+ svc = _fake_service(
|
|
|
|
|
+ resolve=ProviderResolvedModel(
|
|
|
|
|
+ ref=ProviderResourceRef(source_type="makerworld", external_id="1400373", sub_id="1452154"),
|
|
|
|
|
+ design=design_payload,
|
|
|
|
|
+ instances=instances_payload,
|
|
|
|
|
+ )
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
with patch("backend.app.api.routes.makerworld._build_service", AsyncMock(return_value=svc)):
|
|
with patch("backend.app.api.routes.makerworld._build_service", AsyncMock(return_value=svc)):
|
|
|
resp = await async_client.post(
|
|
resp = await async_client.post(
|
|
@@ -132,8 +269,10 @@ class TestResolve:
|
|
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
@pytest.mark.asyncio
|
|
|
async def test_flags_already_imported_library_ids(self, async_client, db_session):
|
|
async def test_flags_already_imported_library_ids(self, async_client, db_session):
|
|
|
- # Seed a matching LibraryFile so resolve() reports it back
|
|
|
|
|
- existing = LibraryFile(
|
|
|
|
|
|
|
+ """Both dedupe shapes must be found through the provider's
|
|
|
|
|
+ ``source_url_filter``: the whole-model canonical URL *and* any
|
|
|
|
|
+ plate-level ``#profileId-`` row."""
|
|
|
|
|
+ model_row = LibraryFile(
|
|
|
filename="prev.3mf",
|
|
filename="prev.3mf",
|
|
|
file_path="library/files/prev.3mf",
|
|
file_path="library/files/prev.3mf",
|
|
|
file_type="3mf",
|
|
file_type="3mf",
|
|
@@ -141,13 +280,25 @@ class TestResolve:
|
|
|
source_type="makerworld",
|
|
source_type="makerworld",
|
|
|
source_url="https://makerworld.com/models/1400373",
|
|
source_url="https://makerworld.com/models/1400373",
|
|
|
)
|
|
)
|
|
|
- db_session.add(existing)
|
|
|
|
|
|
|
+ plate_row = LibraryFile(
|
|
|
|
|
+ filename="prev-plate.3mf",
|
|
|
|
|
+ file_path="library/files/prev-plate.3mf",
|
|
|
|
|
+ file_type="3mf",
|
|
|
|
|
+ file_size=100,
|
|
|
|
|
+ source_type="makerworld",
|
|
|
|
|
+ source_url="https://makerworld.com/models/1400373#profileId-298919107",
|
|
|
|
|
+ )
|
|
|
|
|
+ db_session.add_all([model_row, plate_row])
|
|
|
await db_session.commit()
|
|
await db_session.commit()
|
|
|
- await db_session.refresh(existing)
|
|
|
|
|
|
|
+ await db_session.refresh(model_row)
|
|
|
|
|
+ await db_session.refresh(plate_row)
|
|
|
|
|
|
|
|
svc = _fake_service(
|
|
svc = _fake_service(
|
|
|
- get_design={"id": 1400373},
|
|
|
|
|
- get_design_instances={"total": 0, "hits": []},
|
|
|
|
|
|
|
+ resolve=ProviderResolvedModel(
|
|
|
|
|
+ ref=ProviderResourceRef(source_type="makerworld", external_id="1400373"),
|
|
|
|
|
+ design={"id": 1400373},
|
|
|
|
|
+ instances=[],
|
|
|
|
|
+ )
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
with patch("backend.app.api.routes.makerworld._build_service", AsyncMock(return_value=svc)):
|
|
with patch("backend.app.api.routes.makerworld._build_service", AsyncMock(return_value=svc)):
|
|
@@ -156,93 +307,34 @@ class TestResolve:
|
|
|
json={"url": "https://makerworld.com/en/models/1400373"},
|
|
json={"url": "https://makerworld.com/en/models/1400373"},
|
|
|
)
|
|
)
|
|
|
assert resp.status_code == 200, resp.text
|
|
assert resp.status_code == 200, resp.text
|
|
|
- assert resp.json()["already_imported_library_ids"] == [existing.id]
|
|
|
|
|
|
|
+ assert sorted(resp.json()["already_imported_library_ids"]) == sorted([model_row.id, plate_row.id])
|
|
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
@pytest.mark.asyncio
|
|
|
- async def test_merges_compatibility_from_design_into_instances(self, async_client):
|
|
|
|
|
- """Per-instance printer compatibility info lives on
|
|
|
|
|
- ``design.instances[].extention.modelInfo`` but not on
|
|
|
|
|
- ``/instances/hits``. Resolve enriches each hit with both
|
|
|
|
|
- ``compatibility`` (primary printer the instance was sliced for) and
|
|
|
|
|
- ``otherCompatibility`` (extra printers the uploader marked it
|
|
|
|
|
- compatible with) so the frontend can show "sliced for A1 / also
|
|
|
|
|
- marked compatible with: H2D, P1S".
|
|
|
|
|
- """
|
|
|
|
|
- design_payload = {
|
|
|
|
|
- "id": 1400373,
|
|
|
|
|
- "title": "Seed Starter",
|
|
|
|
|
- "instances": [
|
|
|
|
|
- {
|
|
|
|
|
- "id": 1452154,
|
|
|
|
|
- "extention": {
|
|
|
|
|
- "modelInfo": {
|
|
|
|
|
- "compatibility": ["A1"],
|
|
|
|
|
- "otherCompatibility": ["H2D", "P1S"],
|
|
|
|
|
- }
|
|
|
|
|
- },
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- "id": 1452158,
|
|
|
|
|
- "extention": {
|
|
|
|
|
- "modelInfo": {
|
|
|
|
|
- "compatibility": ["X1 Carbon"],
|
|
|
|
|
- "otherCompatibility": [],
|
|
|
|
|
- }
|
|
|
|
|
- },
|
|
|
|
|
- },
|
|
|
|
|
- ],
|
|
|
|
|
- }
|
|
|
|
|
- instances_payload = {
|
|
|
|
|
- "total": 2,
|
|
|
|
|
- "hits": [
|
|
|
|
|
- {"id": 1452154, "profileId": 298919107, "title": "9 cells"},
|
|
|
|
|
- {"id": 1452158, "profileId": 298919564, "title": "12 cells"},
|
|
|
|
|
- ],
|
|
|
|
|
- }
|
|
|
|
|
- svc = _fake_service(get_design=design_payload, get_design_instances=instances_payload)
|
|
|
|
|
-
|
|
|
|
|
- with patch("backend.app.api.routes.makerworld._build_service", AsyncMock(return_value=svc)):
|
|
|
|
|
- resp = await async_client.post(
|
|
|
|
|
- "/api/v1/makerworld/resolve",
|
|
|
|
|
- json={"url": "https://makerworld.com/en/models/1400373"},
|
|
|
|
|
|
|
+ async def test_gate_uses_the_permission_of_the_provider_the_url_routes_to(self, async_client):
|
|
|
|
|
+ """Same rule as import, keyed off the pasted URL instead of
|
|
|
|
|
+ ``source_type``: a link that routes to another provider is gated on
|
|
|
|
|
+ that provider's view permission, not ``makerworld:view``."""
|
|
|
|
|
+ seen, factory = _permission_spy()
|
|
|
|
|
+ dummy = _DummyProvider()
|
|
|
|
|
+ svc = _fake_service(
|
|
|
|
|
+ resolve=ProviderResolvedModel(
|
|
|
|
|
+ ref=ProviderResourceRef(source_type="dummy", external_id="1400373"),
|
|
|
|
|
+ design={"id": 1400373},
|
|
|
|
|
+ instances=[],
|
|
|
)
|
|
)
|
|
|
- assert resp.status_code == 200, resp.text
|
|
|
|
|
- instances = resp.json()["instances"]
|
|
|
|
|
- by_id = {i["id"]: i for i in instances}
|
|
|
|
|
- assert by_id[1452154]["compatibility"] == ["A1"]
|
|
|
|
|
- assert by_id[1452154]["otherCompatibility"] == ["H2D", "P1S"]
|
|
|
|
|
- assert by_id[1452158]["compatibility"] == ["X1 Carbon"]
|
|
|
|
|
- assert by_id[1452158]["otherCompatibility"] == []
|
|
|
|
|
-
|
|
|
|
|
- @pytest.mark.asyncio
|
|
|
|
|
- async def test_resolve_handles_missing_compatibility_gracefully(self, async_client):
|
|
|
|
|
- """Older designs (or hits without a matching design.instances entry)
|
|
|
|
|
- must not crash the resolve response — they just don't get the
|
|
|
|
|
- compat fields."""
|
|
|
|
|
- design_payload = {"id": 1400373, "instances": [{"id": 1452154}]} # no extention
|
|
|
|
|
- instances_payload = {
|
|
|
|
|
- "total": 2,
|
|
|
|
|
- "hits": [
|
|
|
|
|
- {"id": 1452154, "profileId": 298919107},
|
|
|
|
|
- {"id": 9999999, "profileId": 298919999}, # no design.instances match
|
|
|
|
|
- ],
|
|
|
|
|
- }
|
|
|
|
|
- svc = _fake_service(get_design=design_payload, get_design_instances=instances_payload)
|
|
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
- with patch("backend.app.api.routes.makerworld._build_service", AsyncMock(return_value=svc)):
|
|
|
|
|
|
|
+ with (
|
|
|
|
|
+ patch("backend.app.api.routes.makerworld.require_permission_if_auth_enabled", factory),
|
|
|
|
|
+ patch("backend.app.api.routes.makerworld._provider_for_url", return_value=dummy),
|
|
|
|
|
+ patch("backend.app.api.routes.makerworld._build_service", AsyncMock(return_value=svc)),
|
|
|
|
|
+ ):
|
|
|
resp = await async_client.post(
|
|
resp = await async_client.post(
|
|
|
"/api/v1/makerworld/resolve",
|
|
"/api/v1/makerworld/resolve",
|
|
|
- json={"url": "https://makerworld.com/en/models/1400373"},
|
|
|
|
|
|
|
+ json={"url": "https://dummy.example.com/models/1400373"},
|
|
|
)
|
|
)
|
|
|
assert resp.status_code == 200, resp.text
|
|
assert resp.status_code == 200, resp.text
|
|
|
- instances = resp.json()["instances"]
|
|
|
|
|
- # First instance: design entry exists but no extention → fields absent or None.
|
|
|
|
|
- first = next(i for i in instances if i["id"] == 1452154)
|
|
|
|
|
- assert first.get("compatibility") is None
|
|
|
|
|
- assert first.get("otherCompatibility") is None
|
|
|
|
|
- # Second instance: no design entry at all → no enrichment, no crash.
|
|
|
|
|
- second = next(i for i in instances if i["id"] == 9999999)
|
|
|
|
|
- assert "compatibility" not in second or second["compatibility"] is None
|
|
|
|
|
|
|
+ assert seen == [Permission.LIBRARY_READ]
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestImport:
|
|
class TestImport:
|
|
@@ -270,11 +362,8 @@ class TestImport:
|
|
|
await db_session.commit()
|
|
await db_session.commit()
|
|
|
await db_session.refresh(existing)
|
|
await db_session.refresh(existing)
|
|
|
|
|
|
|
|
- svc = _fake_service(
|
|
|
|
|
- get_design=_default_design(),
|
|
|
|
|
- get_profile_download=_default_manifest(),
|
|
|
|
|
- )
|
|
|
|
|
- svc.download_3mf = AsyncMock() # must remain uncalled
|
|
|
|
|
|
|
+ svc = _fake_service(get_download=_download_info())
|
|
|
|
|
+ svc.download = AsyncMock() # must remain uncalled
|
|
|
|
|
|
|
|
with patch("backend.app.api.routes.makerworld._build_service", AsyncMock(return_value=svc)):
|
|
with patch("backend.app.api.routes.makerworld._build_service", AsyncMock(return_value=svc)):
|
|
|
resp = await async_client.post(
|
|
resp = await async_client.post(
|
|
@@ -287,16 +376,52 @@ class TestImport:
|
|
|
assert body["library_file_id"] == existing.id
|
|
assert body["library_file_id"] == existing.id
|
|
|
assert body["was_existing"] is True
|
|
assert body["was_existing"] is True
|
|
|
assert body["profile_id"] == 298919107
|
|
assert body["profile_id"] == 298919107
|
|
|
- svc.download_3mf.assert_not_called()
|
|
|
|
|
|
|
+ svc.download.assert_not_called()
|
|
|
|
|
+
|
|
|
|
|
+ @pytest.mark.asyncio
|
|
|
|
|
+ async def test_unknown_source_type_is_a_clean_400(self, async_client, db_session):
|
|
|
|
|
+ """``source_type`` names the provider (there is no URL to route on);
|
|
|
|
|
+ an unregistered value is a client-input problem — 400 before any
|
|
|
|
|
+ service is built or bytes downloaded."""
|
|
|
|
|
+ svc = _fake_service(
|
|
|
|
|
+ get_download=_download_info(),
|
|
|
|
|
+ download=ProviderDownload(file_bytes=self._FAKE_3MF_BYTES, filename="benchy.3mf"),
|
|
|
|
|
+ )
|
|
|
|
|
+ svc.download = AsyncMock()
|
|
|
|
|
+
|
|
|
|
|
+ with patch("backend.app.api.routes.makerworld._build_service", AsyncMock(return_value=svc)):
|
|
|
|
|
+ resp = await async_client.post(
|
|
|
|
|
+ "/api/v1/makerworld/import",
|
|
|
|
|
+ json={"model_id": 1400373, "source_type": "thingiverse"},
|
|
|
|
|
+ )
|
|
|
|
|
+ assert resp.status_code == 400, resp.text
|
|
|
|
|
+ assert "thingiverse" in resp.json()["detail"].lower()
|
|
|
|
|
+ svc.download.assert_not_called()
|
|
|
|
|
+
|
|
|
|
|
+ @pytest.mark.asyncio
|
|
|
|
|
+ async def test_unknown_source_type_creates_no_folder_side_effect(self, async_client, db_session):
|
|
|
|
|
+ """Provider resolution must precede destination handling — a rejected
|
|
|
|
|
+ request must not leave an auto-created default folder behind."""
|
|
|
|
|
+ from sqlalchemy import select
|
|
|
|
|
+
|
|
|
|
|
+ svc = _fake_service(get_download=_download_info())
|
|
|
|
|
+
|
|
|
|
|
+ with patch("backend.app.api.routes.makerworld._build_service", AsyncMock(return_value=svc)):
|
|
|
|
|
+ await async_client.post(
|
|
|
|
|
+ "/api/v1/makerworld/import",
|
|
|
|
|
+ json={"model_id": 1400373, "source_type": "bogus"},
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ result = await db_session.execute(select(LibraryFolder))
|
|
|
|
|
+ assert result.scalars().all() == []
|
|
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
@pytest.mark.asyncio
|
|
|
async def test_autocreates_makerworld_folder_when_folder_id_none(self, async_client, db_session):
|
|
async def test_autocreates_makerworld_folder_when_folder_id_none(self, async_client, db_session):
|
|
|
"""Default destination — a top-level "MakerWorld" folder — is created
|
|
"""Default destination — a top-level "MakerWorld" folder — is created
|
|
|
on first import so users don't have to set it up."""
|
|
on first import so users don't have to set it up."""
|
|
|
svc = _fake_service(
|
|
svc = _fake_service(
|
|
|
- get_design=_default_design(),
|
|
|
|
|
- get_profile_download=_default_manifest(),
|
|
|
|
|
- download_3mf=(self._FAKE_3MF_BYTES, "benchy.3mf"),
|
|
|
|
|
|
|
+ get_download=_download_info(),
|
|
|
|
|
+ download=ProviderDownload(file_bytes=self._FAKE_3MF_BYTES, filename="benchy.3mf"),
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
with patch("backend.app.api.routes.makerworld._build_service", AsyncMock(return_value=svc)):
|
|
with patch("backend.app.api.routes.makerworld._build_service", AsyncMock(return_value=svc)):
|
|
@@ -315,6 +440,141 @@ class TestImport:
|
|
|
folder = result.scalar_one()
|
|
folder = result.scalar_one()
|
|
|
assert resp.json()["folder_id"] == folder.id
|
|
assert resp.json()["folder_id"] == folder.id
|
|
|
|
|
|
|
|
|
|
+ @pytest.mark.asyncio
|
|
|
|
|
+ async def test_default_folder_comes_from_resolved_provider(self, async_client, db_session):
|
|
|
|
|
+ """``import_instance`` must read ``default_folder_name`` off the provider
|
|
|
|
|
+ it resolved — not the MakerWorld singleton (review round 3 fix). Latent
|
|
|
|
|
+ with one provider, but the difference is visible behind a stand-in: a
|
|
|
|
|
+ second provider's import lands in *its* folder, not "MakerWorld"."""
|
|
|
|
|
+ dummy = _DummyProvider(default_folder_name="Dummy Imports")
|
|
|
|
|
+ svc = _fake_service(
|
|
|
|
|
+ get_download=_download_info(),
|
|
|
|
|
+ download=ProviderDownload(file_bytes=self._FAKE_3MF_BYTES, filename="benchy.3mf"),
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ with (
|
|
|
|
|
+ patch("backend.app.api.routes.makerworld._provider_for_source", return_value=dummy),
|
|
|
|
|
+ patch("backend.app.api.routes.makerworld._build_service", AsyncMock(return_value=svc)),
|
|
|
|
|
+ ):
|
|
|
|
|
+ resp = await async_client.post(
|
|
|
|
|
+ "/api/v1/makerworld/import",
|
|
|
|
|
+ json={"model_id": 1400373, "profile_id": 298919107, "source_type": "dummy"},
|
|
|
|
|
+ )
|
|
|
|
|
+ assert resp.status_code == 200, resp.text
|
|
|
|
|
+
|
|
|
|
|
+ from sqlalchemy import select
|
|
|
|
|
+
|
|
|
|
|
+ result = await db_session.execute(
|
|
|
|
|
+ select(LibraryFolder).where(LibraryFolder.name == "Dummy Imports", LibraryFolder.parent_id.is_(None))
|
|
|
|
|
+ )
|
|
|
|
|
+ assert result.scalar_one_or_none() is not None
|
|
|
|
|
+ # The MakerWorld singleton's folder must NOT be auto-created instead.
|
|
|
|
|
+ assert (
|
|
|
|
|
+ await db_session.execute(
|
|
|
|
|
+ select(LibraryFolder).where(LibraryFolder.name == "MakerWorld", LibraryFolder.parent_id.is_(None))
|
|
|
|
|
+ )
|
|
|
|
|
+ ).scalar_one_or_none() is None
|
|
|
|
|
+
|
|
|
|
|
+ @pytest.mark.asyncio
|
|
|
|
|
+ async def test_none_default_folder_name_imports_to_library_root(self, async_client, db_session):
|
|
|
|
|
+ """A provider that leaves ``default_folder_name`` unset imports into the
|
|
|
|
|
+ library root rather than minting a NULL-named folder (review round 3,
|
|
|
|
|
+ note 3)."""
|
|
|
|
|
+ dummy = _DummyProvider(default_folder_name=None)
|
|
|
|
|
+ svc = _fake_service(
|
|
|
|
|
+ get_download=_download_info(),
|
|
|
|
|
+ download=ProviderDownload(file_bytes=self._FAKE_3MF_BYTES, filename="benchy.3mf"),
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ with (
|
|
|
|
|
+ patch("backend.app.api.routes.makerworld._provider_for_source", return_value=dummy),
|
|
|
|
|
+ patch("backend.app.api.routes.makerworld._build_service", AsyncMock(return_value=svc)),
|
|
|
|
|
+ ):
|
|
|
|
|
+ resp = await async_client.post(
|
|
|
|
|
+ "/api/v1/makerworld/import",
|
|
|
|
|
+ json={"model_id": 1400373, "profile_id": 298919107, "source_type": "dummy", "folder_id": None},
|
|
|
|
|
+ )
|
|
|
|
|
+ assert resp.status_code == 200, resp.text
|
|
|
|
|
+ assert resp.json()["folder_id"] is None
|
|
|
|
|
+
|
|
|
|
|
+ from sqlalchemy import select
|
|
|
|
|
+
|
|
|
|
|
+ result = await db_session.execute(select(LibraryFolder))
|
|
|
|
|
+ assert result.scalars().all() == []
|
|
|
|
|
+
|
|
|
|
|
+ @pytest.mark.asyncio
|
|
|
|
|
+ async def test_gate_uses_the_makerworld_permission_for_makerworld(self, async_client):
|
|
|
|
|
+ """Control for the test below: the default ``source_type`` still gates
|
|
|
|
|
+ on ``makerworld:import``, exactly as the route decorator used to."""
|
|
|
|
|
+ seen, factory = _permission_spy()
|
|
|
|
|
+ svc = _fake_service(
|
|
|
|
|
+ get_download=_download_info(),
|
|
|
|
|
+ download=ProviderDownload(file_bytes=self._FAKE_3MF_BYTES, filename="benchy.3mf"),
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ with (
|
|
|
|
|
+ patch("backend.app.api.routes.makerworld.require_permission_if_auth_enabled", factory),
|
|
|
|
|
+ patch("backend.app.api.routes.makerworld._build_service", AsyncMock(return_value=svc)),
|
|
|
|
|
+ ):
|
|
|
|
|
+ resp = await async_client.post(
|
|
|
|
|
+ "/api/v1/makerworld/import",
|
|
|
|
|
+ json={"model_id": 1400373, "profile_id": 298919107},
|
|
|
|
|
+ )
|
|
|
|
|
+ assert resp.status_code == 200, resp.text
|
|
|
|
|
+ assert seen == [Permission.MAKERWORLD_IMPORT]
|
|
|
|
|
+
|
|
|
|
|
+ @pytest.mark.asyncio
|
|
|
|
|
+ async def test_gate_uses_the_resolved_providers_permission(self, async_client):
|
|
|
|
|
+ """The permission is the resolved provider's, not the MakerWorld
|
|
|
|
|
+ singleton's. It cannot be a route dependency — FastAPI resolves those
|
|
|
|
|
+ before the body exists, so the decorator could only ever name one
|
|
|
|
|
+ provider, and importing from a second one would be gated on
|
|
|
|
|
+ ``makerworld:import``."""
|
|
|
|
|
+ seen, factory = _permission_spy()
|
|
|
|
|
+ dummy = _DummyProvider()
|
|
|
|
|
+ svc = _fake_service(
|
|
|
|
|
+ get_download=_download_info(),
|
|
|
|
|
+ download=ProviderDownload(file_bytes=self._FAKE_3MF_BYTES, filename="benchy.3mf"),
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ with (
|
|
|
|
|
+ patch("backend.app.api.routes.makerworld.require_permission_if_auth_enabled", factory),
|
|
|
|
|
+ patch("backend.app.api.routes.makerworld._provider_for_source", return_value=dummy),
|
|
|
|
|
+ patch("backend.app.api.routes.makerworld._build_service", AsyncMock(return_value=svc)),
|
|
|
|
|
+ ):
|
|
|
|
|
+ resp = await async_client.post(
|
|
|
|
|
+ "/api/v1/makerworld/import",
|
|
|
|
|
+ json={"model_id": 1400373, "profile_id": 298919107, "source_type": "dummy"},
|
|
|
|
|
+ )
|
|
|
|
|
+ assert resp.status_code == 200, resp.text
|
|
|
|
|
+ assert seen == [Permission.LIBRARY_UPLOAD]
|
|
|
|
|
+ assert Permission.MAKERWORLD_IMPORT not in seen
|
|
|
|
|
+
|
|
|
|
|
+ @pytest.mark.asyncio
|
|
|
|
|
+ async def test_provider_without_a_permission_is_refused_not_waved_through(self, async_client, db_session):
|
|
|
|
|
+ """``import_permission`` is optional on the descriptor, so "unset" must
|
|
|
|
|
+ fail closed rather than read as "unrestricted"."""
|
|
|
|
|
+ dummy = _DummyProvider(import_permission=None)
|
|
|
|
|
+ svc = _fake_service(
|
|
|
|
|
+ get_download=_download_info(),
|
|
|
|
|
+ download=ProviderDownload(file_bytes=self._FAKE_3MF_BYTES, filename="benchy.3mf"),
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ with (
|
|
|
|
|
+ patch("backend.app.api.routes.makerworld._provider_for_source", return_value=dummy),
|
|
|
|
|
+ patch("backend.app.api.routes.makerworld._build_service", AsyncMock(return_value=svc)),
|
|
|
|
|
+ ):
|
|
|
|
|
+ resp = await async_client.post(
|
|
|
|
|
+ "/api/v1/makerworld/import",
|
|
|
|
|
+ json={"model_id": 1400373, "profile_id": 298919107, "source_type": "dummy"},
|
|
|
|
|
+ )
|
|
|
|
|
+ assert resp.status_code == 500
|
|
|
|
|
+ assert "declares no permission" in resp.json()["detail"]
|
|
|
|
|
+
|
|
|
|
|
+ from sqlalchemy import select
|
|
|
|
|
+
|
|
|
|
|
+ assert (await db_session.execute(select(LibraryFile))).scalars().all() == []
|
|
|
|
|
+
|
|
|
@pytest.mark.asyncio
|
|
@pytest.mark.asyncio
|
|
|
async def test_uses_existing_folder_when_folder_id_provided(self, async_client, db_session):
|
|
async def test_uses_existing_folder_when_folder_id_provided(self, async_client, db_session):
|
|
|
"""Caller-supplied ``folder_id`` must be honoured even if the default
|
|
"""Caller-supplied ``folder_id`` must be honoured even if the default
|
|
@@ -325,9 +585,8 @@ class TestImport:
|
|
|
await db_session.refresh(folder)
|
|
await db_session.refresh(folder)
|
|
|
|
|
|
|
|
svc = _fake_service(
|
|
svc = _fake_service(
|
|
|
- get_design=_default_design(),
|
|
|
|
|
- get_profile_download=_default_manifest(),
|
|
|
|
|
- download_3mf=(self._FAKE_3MF_BYTES, "benchy.3mf"),
|
|
|
|
|
|
|
+ get_download=_download_info(),
|
|
|
|
|
+ download=ProviderDownload(file_bytes=self._FAKE_3MF_BYTES, filename="benchy.3mf"),
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
with patch("backend.app.api.routes.makerworld._build_service", AsyncMock(return_value=svc)):
|
|
with patch("backend.app.api.routes.makerworld._build_service", AsyncMock(return_value=svc)):
|
|
@@ -343,9 +602,8 @@ class TestImport:
|
|
|
"""The saved row's ``source_url`` must include ``#profileId-`` so two
|
|
"""The saved row's ``source_url`` must include ``#profileId-`` so two
|
|
|
plates of the same model become two library rows (dedupe is per-plate)."""
|
|
plates of the same model become two library rows (dedupe is per-plate)."""
|
|
|
svc = _fake_service(
|
|
svc = _fake_service(
|
|
|
- get_design=_default_design(),
|
|
|
|
|
- get_profile_download=_default_manifest(),
|
|
|
|
|
- download_3mf=(self._FAKE_3MF_BYTES, "benchy.3mf"),
|
|
|
|
|
|
|
+ get_download=_download_info(),
|
|
|
|
|
+ download=ProviderDownload(file_bytes=self._FAKE_3MF_BYTES, filename="benchy.3mf"),
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
with patch("backend.app.api.routes.makerworld._build_service", AsyncMock(return_value=svc)):
|
|
with patch("backend.app.api.routes.makerworld._build_service", AsyncMock(return_value=svc)):
|
|
@@ -369,12 +627,8 @@ class TestImport:
|
|
|
library row. On-disk storage uses a UUID already, this is belt-and-
|
|
library row. On-disk storage uses a UUID already, this is belt-and-
|
|
|
braces protection for the human-readable field."""
|
|
braces protection for the human-readable field."""
|
|
|
svc = _fake_service(
|
|
svc = _fake_service(
|
|
|
- get_design=_default_design(),
|
|
|
|
|
- get_profile_download={
|
|
|
|
|
- "name": "../../evil.3mf",
|
|
|
|
|
- "url": "https://makerworld.bblmw.com/makerworld/model/X/Y/f.3mf?exp=1&key=k",
|
|
|
|
|
- },
|
|
|
|
|
- download_3mf=(self._FAKE_3MF_BYTES, "fallback.3mf"),
|
|
|
|
|
|
|
+ get_download=_download_info(name="../../evil.3mf"),
|
|
|
|
|
+ download=ProviderDownload(file_bytes=self._FAKE_3MF_BYTES, filename="fallback.3mf"),
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
with patch("backend.app.api.routes.makerworld._build_service", AsyncMock(return_value=svc)):
|
|
with patch("backend.app.api.routes.makerworld._build_service", AsyncMock(return_value=svc)):
|
|
@@ -391,9 +645,8 @@ class TestImport:
|
|
|
response field must always be populated, even when the caller provided
|
|
response field must always be populated, even when the caller provided
|
|
|
it explicitly (rather than the backend falling back to design defaults)."""
|
|
it explicitly (rather than the backend falling back to design defaults)."""
|
|
|
svc = _fake_service(
|
|
svc = _fake_service(
|
|
|
- get_design=_default_design(),
|
|
|
|
|
- get_profile_download=_default_manifest(),
|
|
|
|
|
- download_3mf=(self._FAKE_3MF_BYTES, "benchy.3mf"),
|
|
|
|
|
|
|
+ get_download=_download_info(),
|
|
|
|
|
+ download=ProviderDownload(file_bytes=self._FAKE_3MF_BYTES, filename="benchy.3mf"),
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
with patch("backend.app.api.routes.makerworld._build_service", AsyncMock(return_value=svc)):
|
|
with patch("backend.app.api.routes.makerworld._build_service", AsyncMock(return_value=svc)):
|
|
@@ -426,9 +679,8 @@ class TestImport:
|
|
|
await db_session.refresh(folder)
|
|
await db_session.refresh(folder)
|
|
|
|
|
|
|
|
svc = _fake_service(
|
|
svc = _fake_service(
|
|
|
- get_design=_default_design(),
|
|
|
|
|
- get_profile_download=_default_manifest("seed-starter.3mf"),
|
|
|
|
|
- download_3mf=(self._FAKE_3MF_BYTES, "seed-starter.3mf"),
|
|
|
|
|
|
|
+ get_download=_download_info(name="seed-starter.3mf"),
|
|
|
|
|
+ download=ProviderDownload(file_bytes=self._FAKE_3MF_BYTES, filename="seed-starter.3mf"),
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
with patch("backend.app.api.routes.makerworld._build_service", AsyncMock(return_value=svc)):
|
|
with patch("backend.app.api.routes.makerworld._build_service", AsyncMock(return_value=svc)):
|
|
@@ -453,8 +705,8 @@ class TestImport:
|
|
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
@pytest.mark.asyncio
|
|
|
async def test_import_to_readonly_external_rejected_at_route(self, async_client, db_session, tmp_path):
|
|
async def test_import_to_readonly_external_rejected_at_route(self, async_client, db_session, tmp_path):
|
|
|
- """The route-layer gate at ``makerworld.py:256-260`` rejects read-only
|
|
|
|
|
- externals with 403 before any download happens — so MakerWorld
|
|
|
|
|
|
|
+ """The route-layer gate in ``import_instance`` rejects read-only
|
|
|
|
|
+ external folders with 403 before any download happens — so MakerWorld
|
|
|
credentials and the upstream download bandwidth aren't wasted."""
|
|
credentials and the upstream download bandwidth aren't wasted."""
|
|
|
ext_dir = tmp_path / "nas-readonly"
|
|
ext_dir = tmp_path / "nas-readonly"
|
|
|
ext_dir.mkdir()
|
|
ext_dir.mkdir()
|
|
@@ -469,11 +721,8 @@ class TestImport:
|
|
|
await db_session.commit()
|
|
await db_session.commit()
|
|
|
await db_session.refresh(folder)
|
|
await db_session.refresh(folder)
|
|
|
|
|
|
|
|
- svc = _fake_service(
|
|
|
|
|
- get_design=_default_design(),
|
|
|
|
|
- get_profile_download=_default_manifest(),
|
|
|
|
|
- )
|
|
|
|
|
- svc.download_3mf = AsyncMock()
|
|
|
|
|
|
|
+ svc = _fake_service(get_download=_download_info())
|
|
|
|
|
+ svc.download = AsyncMock()
|
|
|
|
|
|
|
|
with patch("backend.app.api.routes.makerworld._build_service", AsyncMock(return_value=svc)):
|
|
with patch("backend.app.api.routes.makerworld._build_service", AsyncMock(return_value=svc)):
|
|
|
resp = await async_client.post(
|
|
resp = await async_client.post(
|
|
@@ -481,7 +730,7 @@ class TestImport:
|
|
|
json={"model_id": 1400373, "profile_id": 298919107, "folder_id": folder.id},
|
|
json={"model_id": 1400373, "profile_id": 298919107, "folder_id": folder.id},
|
|
|
)
|
|
)
|
|
|
assert resp.status_code == 403, resp.text
|
|
assert resp.status_code == 403, resp.text
|
|
|
- svc.download_3mf.assert_not_called()
|
|
|
|
|
|
|
+ svc.download.assert_not_called()
|
|
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
@pytest.mark.asyncio
|
|
|
async def test_import_to_external_with_missing_path_returns_400(self, async_client, db_session, tmp_path):
|
|
async def test_import_to_external_with_missing_path_returns_400(self, async_client, db_session, tmp_path):
|
|
@@ -501,9 +750,8 @@ class TestImport:
|
|
|
await db_session.refresh(folder)
|
|
await db_session.refresh(folder)
|
|
|
|
|
|
|
|
svc = _fake_service(
|
|
svc = _fake_service(
|
|
|
- get_design=_default_design(),
|
|
|
|
|
- get_profile_download=_default_manifest(),
|
|
|
|
|
- download_3mf=(self._FAKE_3MF_BYTES, "benchy.3mf"),
|
|
|
|
|
|
|
+ get_download=_download_info(),
|
|
|
|
|
+ download=ProviderDownload(file_bytes=self._FAKE_3MF_BYTES, filename="benchy.3mf"),
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
with patch("backend.app.api.routes.makerworld._build_service", AsyncMock(return_value=svc)):
|
|
with patch("backend.app.api.routes.makerworld._build_service", AsyncMock(return_value=svc)):
|
|
@@ -535,9 +783,8 @@ class TestImport:
|
|
|
await db_session.refresh(folder)
|
|
await db_session.refresh(folder)
|
|
|
|
|
|
|
|
svc = _fake_service(
|
|
svc = _fake_service(
|
|
|
- get_design=_default_design(),
|
|
|
|
|
- get_profile_download=_default_manifest("benchy.3mf"),
|
|
|
|
|
- download_3mf=(self._FAKE_3MF_BYTES, "benchy.3mf"),
|
|
|
|
|
|
|
+ get_download=_download_info(name="benchy.3mf"),
|
|
|
|
|
+ download=ProviderDownload(file_bytes=self._FAKE_3MF_BYTES, filename="benchy.3mf"),
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
with patch("backend.app.api.routes.makerworld._build_service", AsyncMock(return_value=svc)):
|
|
with patch("backend.app.api.routes.makerworld._build_service", AsyncMock(return_value=svc)):
|