Tighten API typing and add return values

This commit is contained in:
Nick Sweeting
2026-03-15 19:24:54 -07:00
parent 95a105feb9
commit 5381f7584c
6 changed files with 20 additions and 20 deletions

View File

@@ -25,8 +25,8 @@ class CLIScheduleAPITests(TestCase):
def test_schedule_api_creates_schedule(self):
request = RequestFactory().post('/api/v1/cli/schedule')
request.user = self.user
request.stdout = StringIO()
request.stderr = StringIO()
setattr(request, 'stdout', StringIO())
setattr(request, 'stderr', StringIO())
args = ScheduleCommandSchema(
every='daily',
import_path='https://example.com/feed.xml',

View File

@@ -112,7 +112,7 @@ class RemoveCommandSchema(Schema):
def cli_add(request: HttpRequest, args: AddCommandSchema):
from archivebox.cli.archivebox_add import add
result = add(
crawl, snapshots = add(
urls=args.urls,
tag=args.tag,
depth=args.depth,
@@ -125,9 +125,9 @@ def cli_add(request: HttpRequest, args: AddCommandSchema):
created_by_id=request.user.pk,
)
snapshot_ids = [str(snapshot_id) for snapshot_id in result.values_list('id', flat=True)]
snapshot_ids = [str(snapshot_id) for snapshot_id in snapshots.values_list('id', flat=True)]
result_payload = {
"crawl_id": getattr(result, "crawl_id", None),
"crawl_id": str(crawl.id),
"num_snapshots": len(snapshot_ids),
"snapshot_ids": snapshot_ids,
"queued_urls": args.urls,

View File

@@ -427,7 +427,7 @@ def get_any(request: HttpRequest, id: str):
try:
response = getter(request, id)
if isinstance(response, Model):
return redirect(f"/api/v1/{response._meta.app_label}/{response._meta.model_name}/{response.id}?{request.META['QUERY_STRING']}")
return redirect(f"/api/v1/{response._meta.app_label}/{response._meta.model_name}/{response.pk}?{request.META['QUERY_STRING']}")
except Exception:
pass
@@ -435,7 +435,7 @@ def get_any(request: HttpRequest, id: str):
from archivebox.api.v1_crawls import get_crawl
response = get_crawl(request, id)
if isinstance(response, Model):
return redirect(f"/api/v1/{response._meta.app_label}/{response._meta.model_name}/{response.id}?{request.META['QUERY_STRING']}")
return redirect(f"/api/v1/{response._meta.app_label}/{response._meta.model_name}/{response.pk}?{request.META['QUERY_STRING']}")
except Exception:
pass