From 80d68446c14dc71f0bd23d10d50ebc926cce4400 Mon Sep 17 00:00:00 2001 From: Vlad0n20 Date: Thu, 9 Jan 2025 17:23:53 +0200 Subject: [PATCH 1/2] Fix tests with target filtering in query params --- api/base/filters.py | 29 +++++++++++++++++++ .../views/test_preprint_list_mixin.py | 3 +- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/api/base/filters.py b/api/base/filters.py index 4d9bc37a442..0f8708ff789 100644 --- a/api/base/filters.py +++ b/api/base/filters.py @@ -338,6 +338,35 @@ def parse_query_params(self, query_params): }) elif self.should_parse_special_query_params(field_name): query = self.parse_special_query_params(field_name, key, value, query) + elif not isinstance(value, int) and source_field_name == 'target__guids___id': + base_guid, version = Guid.split_guid(value) + if base_guid is None and version is None: + raise InvalidFilterValue( + value=value, + field_type='guid', + ) + guid_filters = { + field_name: { + 'op': 'in', + 'value': self.bulk_get_values(value, field), + 'source_field_name': source_field_name, + }, + } + if version is not None: + guid_filters = { + field_name: { + 'op': 'eq', + 'value': base_guid, + 'source_field_name': 'target__guids___id', + }, + 'target__versioned_guids__version': { + 'op': 'eq', + 'value': version, + 'source_field_name': 'target__versioned_guids__version', + }, + } + + query.get(key).update(guid_filters) else: query.get(key).update({ field_name: { diff --git a/api_tests/preprints/views/test_preprint_list_mixin.py b/api_tests/preprints/views/test_preprint_list_mixin.py index 37ef40942ea..df11d3d0c30 100644 --- a/api_tests/preprints/views/test_preprint_list_mixin.py +++ b/api_tests/preprints/views/test_preprint_list_mixin.py @@ -208,7 +208,8 @@ def test_filter_published_false_admin( res = app.get( f'{url}filter[is_published]=false', auth=user_admin_contrib.auth) - assert len(res.json['data']) == 0 + assert len(res.json['data']) == 1 + assert preprint_unpublished._id in [d['id'] for d in res.json['data']] @pytest.mark.django_db From f54872c332cd4c2a41d1ef447621d89373ad3fcd Mon Sep 17 00:00:00 2001 From: Vlad0n20 Date: Fri, 10 Jan 2025 14:25:19 +0200 Subject: [PATCH 2/2] Fix test_claim_unauth_success_with_preprint_id --- api_tests/users/views/test_user_claim.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api_tests/users/views/test_user_claim.py b/api_tests/users/views/test_user_claim.py index 68e6cfd52dd..20e19dbf30d 100644 --- a/api_tests/users/views/test_user_claim.py +++ b/api_tests/users/views/test_user_claim.py @@ -148,7 +148,7 @@ def test_claim_unauth_success_with_unknown_email(self, app, url, project, unreg_ def test_claim_unauth_success_with_preprint_id(self, app, url, preprint, unreg_user, mock_mail): res = app.post_json_api( url.format(unreg_user._id), - self.payload(email='david@david.son', id=preprint._id), + self.payload(email='david@david.son', id=preprint.get_guid()._id), ) assert res.status_code == 204 assert mock_mail.call_count == 1