Skip to content

Commit 03112da

Browse files
authored
[Dependent] [CVAT] Improve active job filter (#3563)
1 parent e26426d commit 03112da

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

packages/examples/cvat/exchange-oracle/src/endpoints/exchange.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,12 @@ async def list_jobs(
140140
if status:
141141
match status:
142142
case JobStatuses.active:
143-
query = query.filter(cvat_service.Project.status == ProjectStatuses.annotation)
143+
query = query.filter(
144+
cvat_service.Project.status == ProjectStatuses.annotation,
145+
cvat_service.Project.jobs.any(
146+
cvat_service.Job.status == cvat_service.JobStatuses.new
147+
),
148+
)
144149
case JobStatuses.canceled:
145150
query = query.filter(
146151
cvat_service.Project.status == cvat_service.ProjectStatuses.canceled

packages/examples/cvat/exchange-oracle/tests/api/test_exchange_api.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,66 @@ def test_can_list_jobs_200_with_filters(client: TestClient, session: Session):
588588
)
589589

590590

591+
def test_can_list_jobs_200_can_show_only_active_jobs_with_free_assignments(
592+
client: TestClient, session: Session
593+
):
594+
session.begin()
595+
596+
user = User(
597+
wallet_address=WALLET_ADDRESS1,
598+
cvat_email=cvat_email,
599+
cvat_id=1,
600+
)
601+
session.add(user)
602+
603+
cvat_project1, _, _ = create_project_task_and_job(
604+
session, "0x86e83d346041E8806e352681f3F14549C0d2001", 1
605+
)
606+
cvat_project1.status = ProjectStatuses.annotation
607+
session.add(cvat_project1)
608+
609+
cvat_project2, _, cvat_job2 = create_project_task_and_job(
610+
session, "0x86e83d346041E8806e352681f3F14549C0d2002", 2
611+
)
612+
cvat_project2.status = ProjectStatuses.annotation
613+
cvat_job2.status = JobStatuses.in_progress
614+
session.add(cvat_project2)
615+
session.add(cvat_job2)
616+
617+
assignment = Assignment(
618+
id=str(uuid.uuid4()),
619+
user_wallet_address=user.wallet_address,
620+
cvat_job_id=cvat_job2.cvat_id,
621+
status=AssignmentStatuses.created,
622+
created_at=utcnow() - timedelta(hours=1),
623+
expires_at=utcnow() + timedelta(hours=1),
624+
)
625+
session.add(assignment)
626+
627+
session.commit()
628+
629+
with (
630+
open("tests/utils/manifest.json") as data,
631+
patch("src.endpoints.serializers.get_escrow_manifest") as mock_get_manifest,
632+
patch(
633+
"src.endpoints.serializers.get_escrow_fund_token_symbol"
634+
) as mock_get_escrow_fund_token_symbol,
635+
):
636+
manifest = json.load(data)
637+
mock_get_manifest.return_value = manifest
638+
mock_get_escrow_fund_token_symbol.return_value = "HMT"
639+
640+
response = client.get(
641+
"/job",
642+
headers=get_auth_header(token=generate_jwt_token()),
643+
params={"status": APIJobStatuses.active.value},
644+
)
645+
646+
assert response.status_code == 200
647+
paginated_result = response.json()
648+
assert paginated_result["total_results"] == 1
649+
650+
591651
def test_can_list_jobs_200_check_values(client: TestClient, session: Session) -> None:
592652
session.begin()
593653
user = User(

0 commit comments

Comments
 (0)