test(instagram): update capability tests for schema changes

This commit is contained in:
Anish Sarkar 2026-07-11 02:21:11 +05:30
parent 42d03fdbc7
commit 82a63043f7
3 changed files with 11 additions and 48 deletions

View file

@ -9,8 +9,6 @@ from __future__ import annotations
import pytest
from app.capabilities.instagram.comments.executor import build_comments_executor
from app.capabilities.instagram.comments.schemas import CommentsInput, CommentsOutput
from app.capabilities.instagram.details.executor import build_details_executor
from app.capabilities.instagram.details.schemas import DetailsInput, DetailsOutput
from app.capabilities.instagram.scrape.executor import build_scrape_executor
@ -50,10 +48,10 @@ async def test_scrape_maps_urls_and_wraps_items():
async def test_scrape_joins_search_queries():
fake = _FakeScraper([])
execute = build_scrape_executor(fake)
await execute(ScrapeInput(search_queries=["fit", "gym"], search_type="hashtag"))
await execute(ScrapeInput(search_queries=["natgeo", "nasa"], search_type="profile"))
actor_input, _ = fake.calls[0]
assert actor_input.search == "fit,gym"
assert actor_input.searchType == "hashtag"
assert actor_input.search == "natgeo,nasa"
assert actor_input.searchType == "profile"
assert actor_input.directUrls == []
@ -66,26 +64,6 @@ async def test_scrape_access_blocked_maps_to_forbidden():
await execute(ScrapeInput(urls=["x"]))
async def test_comments_maps_flags():
fake = _FakeScraper([{"id": "c1", "text": "nice"}])
execute = build_comments_executor(fake)
out = await execute(
CommentsInput(
urls=["https://www.instagram.com/p/Cabc/"],
newest_first=True,
include_replies=True,
max_comments_per_post=25,
)
)
assert isinstance(out, CommentsOutput)
assert out.items[0].text == "nice"
actor_input, _ = fake.calls[0]
assert actor_input.resultsType == "comments"
assert actor_input.isNewestComments is True
assert actor_input.includeNestedComments is True
assert actor_input.resultsLimit == 25
async def test_details_maps_and_wraps_discriminated_items():
fake = _FakeScraper(
[

View file

@ -1,4 +1,4 @@
"""The instagram namespace registers its three verbs for the doors/agent to read.
"""The instagram namespace registers its verbs for the doors/agent to read.
Unlike the stale reddit assertion (``billing_unit is None``), these assert the
real meters the Capability definitions are the source of truth.
@ -23,12 +23,6 @@ def test_instagram_scrape_registered_with_item_meter():
assert cap.billing_unit is BillingUnit.INSTAGRAM_ITEM
def test_instagram_comments_registered_with_comment_meter():
cap = get_capability("instagram.comments")
assert cap.name == "instagram.comments"
assert cap.billing_unit is BillingUnit.INSTAGRAM_COMMENT
def test_instagram_details_registered_with_item_meter():
cap = get_capability("instagram.details")
assert cap.name == "instagram.details"

View file

@ -5,7 +5,6 @@ from __future__ import annotations
import pytest
from pydantic import ValidationError
from app.capabilities.instagram.comments.schemas import CommentsInput
from app.capabilities.instagram.details.schemas import DetailsInput, DetailsOutput
from app.capabilities.instagram.scrape.schemas import (
MAX_INSTAGRAM_ITEMS,
@ -47,30 +46,22 @@ def test_scrape_bounds():
)
def test_comments_requires_urls_and_caps_at_50():
def test_scrape_rejects_walled_search_type():
# Discovery is profile-only; hashtag/place are login-walled and rejected.
with pytest.raises(ValidationError):
CommentsInput(urls=[])
with pytest.raises(ValidationError):
CommentsInput(
urls=["https://www.instagram.com/p/Cabc/"], max_comments_per_post=51
)
ok = CommentsInput(
urls=["https://www.instagram.com/p/Cabc/"], max_comments_per_post=50
)
assert ok.max_comments_per_post == 50
ScrapeInput(search_queries=["travel"], search_type="hashtag")
def test_details_discriminated_union_selects_by_detail_kind():
def test_details_wraps_profile_items():
out = DetailsOutput(
items=[
{"detailKind": "profile", "username": "natgeo"},
{"detailKind": "hashtag", "name": "fit"},
{"detailKind": "place", "name": "Copenhagen"},
{"detailKind": "profile", "username": "nasa"},
]
)
kinds = [type(i).__name__ for i in out.items]
assert kinds == ["InstagramProfile", "InstagramHashtag", "InstagramPlace"]
assert out.billable_units == 3
assert kinds == ["InstagramProfile", "InstagramProfile"]
assert out.billable_units == 2
def test_details_rejects_both_sources():