Skip to content

Commit

Permalink
Add updatable QA reviewStatus field to crawls (#1575)
Browse files Browse the repository at this point in the history
Fixes #1539 

Adds `reviewStatus` field to `BaseCrawl` model, updatable via the crawl
update API endpoint. Acceptable values are "good", "acceptable" or
"failure", enforced by an Enum.

Added to `BaseCrawl` so that we can extend support to uploads more
easily later on, but for now we'll only display this for crawls in the
frontend.
  • Loading branch information
tw4l authored Mar 6, 2024
1 parent 780dd09 commit c20e754
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
14 changes: 14 additions & 0 deletions backend/btrixcloud/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,15 @@ class CrawlFileOut(BaseModel):
expireAt: Optional[str]


# ============================================================================
class ReviewStatus(str, Enum):
"""QA review statuses"""

GOOD = "good"
ACCEPTABLE = "acceptable"
FAILURE = "failure"


# ============================================================================
class BaseCrawl(BaseMongoModel):
"""Base Crawl object (representing crawls, uploads and manual sessions)"""
Expand Down Expand Up @@ -554,6 +563,8 @@ class BaseCrawl(BaseMongoModel):
fileSize: int = 0
fileCount: int = 0

reviewStatus: Optional[ReviewStatus] = None


# ============================================================================
class CollIdName(BaseModel):
Expand Down Expand Up @@ -617,6 +628,8 @@ class CrawlOut(BaseMongoModel):
crawlerChannel: str = "default"
image: Optional[str]

reviewStatus: Optional[ReviewStatus] = None


# ============================================================================
class CrawlOutWithResources(CrawlOut):
Expand All @@ -634,6 +647,7 @@ class UpdateCrawl(BaseModel):
description: Optional[str]
tags: Optional[List[str]]
collectionIds: Optional[List[UUID]]
reviewStatus: Optional[ReviewStatus]


# ============================================================================
Expand Down
37 changes: 37 additions & 0 deletions backend/test/test_run_crawl.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,43 @@ def test_update_crawl(
assert data["description"] == UPDATED_DESC
assert data["name"] == UPDATED_NAME
assert data["collectionIds"] == UPDATED_COLLECTION_IDS
assert data.get("reviewStatus") is None

# Update reviewStatus and verify
r = requests.patch(
f"{API_PREFIX}/orgs/{default_org_id}/crawls/{admin_crawl_id}",
headers=admin_auth_headers,
json={
"reviewStatus": "good",
},
)
assert r.status_code == 200
data = r.json()
assert data["updated"]

r = requests.get(
f"{API_PREFIX}/orgs/{default_org_id}/crawls/{admin_crawl_id}",
headers=admin_auth_headers,
)
assert r.status_code == 200
assert r.json()["reviewStatus"] == "good"

# Try to update to invalid reviewStatus
r = requests.patch(
f"{API_PREFIX}/orgs/{default_org_id}/crawls/{admin_crawl_id}",
headers=admin_auth_headers,
json={
"reviewStatus": "invalid",
},
)
assert r.status_code == 422

r = requests.get(
f"{API_PREFIX}/orgs/{default_org_id}/crawls/{admin_crawl_id}",
headers=admin_auth_headers,
)
assert r.status_code == 200
assert r.json()["reviewStatus"] == "good"

# Verify deleting works as well
r = requests.patch(
Expand Down

0 comments on commit c20e754

Please sign in to comment.