Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add REST API tests for /requests API && test both versions of the export API #8216

Merged
merged 46 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
d5fc868
Update rest api tests
Marishka17 Jul 20, 2024
a99241a
Test /requests api
Marishka17 Jul 24, 2024
eb6e83b
Refactor code && fix export issues
Marishka17 Jul 26, 2024
0552685
Fix type
Marishka17 Jul 26, 2024
796b282
Fix requests filtration
Marishka17 Jul 26, 2024
86fd101
Update server schema
Marishka17 Jul 26, 2024
3a7bfae
[rest api tests] Black && isort && small fixes
Marishka17 Jul 26, 2024
2f63c07
Merge branch 'develop' into mk/rest_api_tests
Marishka17 Jul 26, 2024
4129851
t
Marishka17 Jul 26, 2024
0d389e3
Remove unused import
Marishka17 Jul 26, 2024
72d709e
Fix merge
Marishka17 Jul 26, 2024
f82b732
Fix isort issues
Marishka17 Jul 26, 2024
150d5d0
Fix typos && remove extra lines
Marishka17 Jul 31, 2024
61124c9
Apply comments
Marishka17 Jul 31, 2024
ef4ba9e
Update server schema
Marishka17 Jul 31, 2024
285c648
Use when testing simple filters
Marishka17 Jul 31, 2024
fdc30e7
Use import/export bucket as source/target storage
Marishka17 Jul 31, 2024
c1b649a
Remove unused imports
Marishka17 Jul 31, 2024
6538b36
Update default target/source storage for projects
Marishka17 Aug 1, 2024
55bee26
Fix helm tests
Marishka17 Aug 1, 2024
bf726bb
Test export API mixing
Marishka17 Aug 1, 2024
527b0f2
Fix pylint issues
Marishka17 Aug 1, 2024
ed3924b
t
Marishka17 Aug 1, 2024
9c62008
Update cvat/apps/engine/background.py
Marishka17 Aug 8, 2024
988a508
Update cvat/apps/engine/background.py
Marishka17 Aug 8, 2024
1f37236
Update cvat/apps/engine/background.py
Marishka17 Aug 8, 2024
0dfa747
Return rq_id on 202
Marishka17 Aug 9, 2024
ecfd7f5
Merge branch 'develop' into mk/rest_api_tests
Marishka17 Aug 9, 2024
ac7c054
Update cvat/apps/engine/background.py
Marishka17 Aug 12, 2024
4ea34e8
Apply comments && handle parallel requests
Marishka17 Aug 13, 2024
b3cef9b
Rename requests filter: resource -> target
Marishka17 Aug 14, 2024
cecc889
Use lock when fetching job
Marishka17 Aug 14, 2024
9efb382
Add engine/background.py to format_python_code
Marishka17 Aug 14, 2024
c96674e
Update cvat/apps/engine/background.py
Marishka17 Aug 14, 2024
15a0a6a
Remove unused import
Marishka17 Aug 14, 2024
5ecde3f
Remove f-string
Marishka17 Aug 14, 2024
d3c4d68
Reformat code
Marishka17 Aug 14, 2024
ec3e360
Update test
Marishka17 Aug 14, 2024
b328672
Merge branch 'develop' into mk/rest_api_tests
Marishka17 Aug 14, 2024
7c348bb
Resolve conflicts
Marishka17 Aug 19, 2024
7c7cc07
Merge branch 'mk/rest_api_tests' of https://github.com/opencv/cvat in…
Marishka17 Aug 19, 2024
240574c
Fix merge
Marishka17 Aug 19, 2024
d548a4f
Update changelog
Marishka17 Aug 20, 2024
bab4882
Add a note about used lock timeout
Marishka17 Aug 20, 2024
c3113c1
Reformat code
Marishka17 Aug 20, 2024
57198fa
Merge branch 'develop' into mk/rest_api_tests
Marishka17 Aug 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions changelog.d/20240820_134050_maria_rest_api_tests.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
### Fixed

- Prevent export process from restarting when downloading a result file,
that resulted in downloading a file with new request ID
(<https://github.com/cvat-ai/cvat/pull/8216>)
- Race condition occurred while handling parallel export requests
(<https://github.com/cvat-ai/cvat/pull/8216>)
- Requests filtering using format and target filters
(<https://github.com/cvat-ai/cvat/pull/8216>)

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions cvat/apps/engine/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from django.db.models.query import QuerySet
from django.utils.translation import gettext_lazy as _
from django.utils.encoding import force_str
from django.http import HttpRequest
from rest_framework.request import Request
from rest_framework import filters
from rest_framework.compat import coreapi, coreschema
from rest_framework.exceptions import ValidationError
Expand Down Expand Up @@ -412,11 +412,11 @@ def get_schema_operation_parameters(self, view):
parameters.append(parameter)
return parameters

def filter_queryset(self, request: HttpRequest, queryset: Iterable, view):
def filter_queryset(self, request: Request, queryset: Iterable, view):
filtered_queryset = queryset

query_params = request.query_params
filters_to_use = set(query_params)
filters_to_use = set(query_params.keys())

simple_filters = getattr(view, self.filter_fields_attr, None)
lookup_fields = self.get_lookup_fields(view)
Expand Down Expand Up @@ -465,7 +465,7 @@ def get_ordering(self, request, queryset, view) -> Tuple[List[str], bool]:

return result, reverse

def filter_queryset(self, request: HttpRequest, queryset: Iterable, view) -> Iterable:
def filter_queryset(self, request: Request, queryset: Iterable, view) -> Iterable:
ordering, reverse = self.get_ordering(request, queryset, view)

if ordering:
Expand Down Expand Up @@ -520,7 +520,7 @@ def _apply_filter(self, rules, lookup_fields, obj):
else:
raise ValidationError(f'filter: {op} operation with {args} arguments is not implemented')

def filter_queryset(self, request: HttpRequest, queryset: Iterable, view) -> Iterable:
def filter_queryset(self, request: Request, queryset: Iterable, view) -> Iterable:
filtered_queryset = queryset
json_rules = request.query_params.get(self.filter_param)
if json_rules:
Expand Down
2 changes: 1 addition & 1 deletion cvat/apps/engine/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from rest_framework.response import Response
from rest_framework.views import APIView

from cvat.apps.engine.background_operations import (BackupExportManager,
from cvat.apps.engine.background import (BackupExportManager,
DatasetExportManager)
from cvat.apps.engine.handlers import clear_import_cache
from cvat.apps.engine.location import StorageType, get_location_configuration
Expand Down
4 changes: 4 additions & 0 deletions cvat/apps/engine/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ def get_rq_lock_by_user(queue: DjangoRQ, user_id: int) -> Union[Lock, nullcontex
return queue.connection.lock(f'{queue.name}-lock-{user_id}', timeout=30)
return nullcontext()

def get_rq_lock_for_job(queue: DjangoRQ, rq_id: str) -> Lock:
# lock timeout corresponds to the nginx request timeout (proxy_read_timeout)
return queue.connection.lock(f'lock-for-job-{rq_id}'.lower(), timeout=60)

def get_rq_job_meta(
request: HttpRequest,
db_obj: Any,
Expand Down
12 changes: 6 additions & 6 deletions cvat/apps/engine/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ def upload_finished(self, request):
return Response(data='Unknown upload was finished',
status=status.HTTP_400_BAD_REQUEST)

@extend_schema(summary='Get project annotations or export them as a dataset',
@extend_schema(summary='Export project annotations as a dataset',
description=textwrap.dedent("""\
Deprecation warning:

Expand Down Expand Up @@ -535,11 +535,7 @@ def upload_finished(self, request):
def annotations(self, request, pk):
# FUTURE-TODO: mark exporting dataset using this endpoint as deprecated when new API for result file downloading will be implemented
self._object = self.get_object() # force call of check_object_permissions()
return self.export_dataset_v1(
request=request,
save_images=False,
get_data=dm.task.get_job_data,
)
return self.export_dataset_v1(request=request, save_images=False)

@extend_schema(summary='Back up a project',
description=textwrap.dedent("""\
Expand Down Expand Up @@ -3275,6 +3271,7 @@ class RequestViewSet(viewsets.GenericViewSet):
'job_id',
# derivatives fields (from parsed rq_id)
'action',
'target',
'subresource',
'format',
]
Expand All @@ -3284,7 +3281,9 @@ class RequestViewSet(viewsets.GenericViewSet):
lookup_fields = {
'created_date': 'created_at',
'action': 'parsed_rq_id.action',
'target': 'parsed_rq_id.target',
'subresource': 'parsed_rq_id.subresource',
'format': 'parsed_rq_id.format',
'status': 'get_status',
'project_id': 'meta.project_id',
'task_id': 'meta.task_id',
Expand All @@ -3300,6 +3299,7 @@ class RequestViewSet(viewsets.GenericViewSet):
'task_id': SchemaField('integer'),
'job_id': SchemaField('integer'),
'action': SchemaField('string', RequestAction.choices),
'target': SchemaField('string', RequestTarget.choices),
'subresource': SchemaField('string', RequestSubresource.choices),
'format': SchemaField('string'),
'org': SchemaField('string'),
Expand Down
13 changes: 11 additions & 2 deletions cvat/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3552,7 +3552,7 @@ paths:
- POST /api/projects/<project_id>/dataset/export?save_images=False to initiate exporting process
- GET /api/requests/<rq_id> to check export status,
where rq_id is request id returned on initializing request'
summary: Get project annotations or export them as a dataset
summary: Export project annotations as a dataset
parameters:
- in: query
name: action
Expand Down Expand Up @@ -4541,7 +4541,7 @@ paths:

Details about the syntax used can be found at the link: https://jsonlogic.com/

Available filter_fields: ['status', 'project_id', 'task_id', 'job_id', 'action', 'subresource', 'format'].
Available filter_fields: ['status', 'project_id', 'task_id', 'job_id', 'action', 'target', 'subresource', 'format'].
schema:
type: string
- name: format
Expand Down Expand Up @@ -4602,6 +4602,15 @@ paths:
- annotations
- dataset
- backup
- name: target
in: query
description: A simple equality filter for the target field
schema:
type: string
enum:
- project
- task
- job
- name: task_id
in: query
description: A simple equality filter for the task_id field
Expand Down
1 change: 1 addition & 0 deletions dev/format_python_code.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ for paths in \
"cvat/apps/quality_control" \
"cvat/apps/analytics_report" \
"cvat/apps/engine/lazy_list.py" \
"cvat/apps/engine/background.py" \
; do
${BLACK} -- ${paths}
${ISORT} -- ${paths}
Expand Down
2 changes: 1 addition & 1 deletion tests/python/rest_api/test_cloud_storages.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def _get_endpoint(self, api_client: ApiClient) -> Endpoint:
("provider_type", "name", "resource", "credentials_type", "owner"),
)
def test_can_use_simple_filter_for_object_list(self, field):
return super().test_can_use_simple_filter_for_object_list(field)
return super()._test_can_use_simple_filter_for_object_list(field)


@pytest.mark.usefixtures("restore_db_per_function")
Expand Down
2 changes: 1 addition & 1 deletion tests/python/rest_api/test_invitations.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def _get_endpoint(self, api_client: ApiClient) -> Endpoint:
("owner",),
)
def test_can_use_simple_filter_for_object_list(self, field):
return super().test_can_use_simple_filter_for_object_list(field)
return super()._test_can_use_simple_filter_for_object_list(field)


@pytest.mark.usefixtures("restore_db_per_class")
Expand Down
4 changes: 2 additions & 2 deletions tests/python/rest_api/test_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ def _get_endpoint(self, api_client: ApiClient) -> Endpoint:
("owner", "assignee", "job_id", "resolved", "frame_id"),
)
def test_can_use_simple_filter_for_object_list(self, field):
return super().test_can_use_simple_filter_for_object_list(field)
return super()._test_can_use_simple_filter_for_object_list(field)


class TestCommentsListFilters(CollectionSimpleFilterTestBase):
Expand Down Expand Up @@ -393,7 +393,7 @@ def _get_field_samples(self, field: str) -> Tuple[Any, List[Dict[str, Any]]]:
("owner", "issue_id", "job_id", "frame_id"),
)
def test_can_use_simple_filter_for_object_list(self, field):
return super().test_can_use_simple_filter_for_object_list(field)
return super()._test_can_use_simple_filter_for_object_list(field)


@pytest.mark.usefixtures("restore_db_per_class")
Expand Down
Loading
Loading