From d450455a2096220f931a9cde4240164f0eb75323 Mon Sep 17 00:00:00 2001 From: Ihor Sokhan Date: Fri, 12 Sep 2025 16:03:03 +0300 Subject: [PATCH] added description filtering for preprints --- api/preprints/serializers.py | 1 + api_tests/preprints/filters/test_filters.py | 27 ++++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/api/preprints/serializers.py b/api/preprints/serializers.py index 42b122e8091..7ef6512452d 100644 --- a/api/preprints/serializers.py +++ b/api/preprints/serializers.py @@ -103,6 +103,7 @@ class PreprintSerializer(TaxonomizableSerializerMixin, MetricsSerializerMixin, J 'reviews_state', 'node_is_public', 'tags', + 'description', ]) available_metrics = frozenset([ 'downloads', diff --git a/api_tests/preprints/filters/test_filters.py b/api_tests/preprints/filters/test_filters.py index 9a483ad55ec..6f1a1e6c0af 100644 --- a/api_tests/preprints/filters/test_filters.py +++ b/api_tests/preprints/filters/test_filters.py @@ -56,7 +56,9 @@ def preprint_one(self, user, project_one, provider_one, subject_one): creator=user, project=project_one, provider=provider_one, - subjects=[[subject_one._id]]) + subjects=[[subject_one._id]], + description='test1' + ) preprint_one.original_publication_date = '2013-12-25 10:09:08.070605+00:00' preprint_one.save() return preprint_one @@ -68,7 +70,9 @@ def preprint_two(self, user, project_two, provider_two, subject_two): project=project_two, filename='howto_reason.txt', provider=provider_two, - subjects=[[subject_two._id]]) + subjects=[[subject_two._id]], + description='2test' + ) preprint_two.created = '2013-12-11 10:09:08.070605+00:00' preprint_two.date_published = '2013-12-11 10:09:08.070605+00:00' preprint_two.original_publication_date = '2013-12-11 10:09:08.070605+00:00' @@ -84,7 +88,9 @@ def preprint_three( project=project_three, filename='darn_reason.txt', provider=provider_three, - subjects=[[subject_one._id], [subject_two._id]]) + subjects=[[subject_one._id], [subject_two._id]], + description='new preprint' + ) preprint_three.created = '2013-12-11 10:09:08.070605+00:00' preprint_three.date_published = '2013-12-11 10:09:08.070605+00:00' preprint_three.original_publication_date = '2013-12-11 10:09:08.070605+00:00' @@ -129,6 +135,10 @@ def is_published_and_modified_url(self, url): def node_is_public_url(self, url): return f'{url}filter[node_is_public]=' + @pytest.fixture() + def description_url(self, url): + return f'{url}filter[description]=' + def test_provider_filter_null(self, app, user, provider_url): expected = [] res = app.get(f'{provider_url}null', auth=user.auth) @@ -351,3 +361,14 @@ def actual(): expected.update( [p._id for p in preprints if p.provider_id == preprint.provider_id]) assert expected == actual() + + def test_description_filter( + self, app, user, description_url, preprint_one, preprint_two, preprint_three): + expected = {preprint_one._id, preprint_two._id} + res = app.get( + description_url + 'tes', + auth=user.auth + ) + actual = {preprint['id'] for preprint in res.json['data']} + assert expected == actual + assert preprint_three._id not in res.json['data']