From 0ba2d63f88a2dbf41e28c106e757cc9ac34f6f61 Mon Sep 17 00:00:00 2001 From: Mat Moore Date: Tue, 27 Feb 2024 17:10:08 +0000 Subject: [PATCH] Expand docstring --- .github/workflows/test.yml | 2 +- home/forms/search.py | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3fe426ed..0b47dfcc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -38,7 +38,7 @@ jobs: - run: poetry install --no-interaction - name: run unit tests with coverage id: fast-tests - run: poetry run pytest --cov -m 'not slow' + run: poetry run pytest --cov -m 'not slow' --doctest-modules - name: Get Chromium version 🌐 run: | diff --git a/home/forms/search.py b/home/forms/search.py index 599e257b..95066954 100644 --- a/home/forms/search.py +++ b/home/forms/search.py @@ -112,7 +112,23 @@ def __init__(self, *args, **kwargs): self.initial["sort"] = "relevance" def encode_without_filter(self, filter_name: str, filter_value: str): - """Preformat hrefs to drop individual filters""" + """ + Generate a query string that can be used to generate "remove filter" + links. + + The query string includes all submitted form parameters except + the one identified by filter_name and filter_value. + + >>> formdata = {'domain': 'urn:li:domain:HMCTS', 'classifications': ['OFFICIAL']} + >>> form = SearchForm(formdata) + >>> assert form.is_valid() + + >>> form.encode_without_filter('domain', 'urn:li:domain:HMCTS') + '?query=&classifications=OFFICIAL&sort=&clear_filter=False&clear_label=False' + + >>> form.encode_without_filter('classifications', 'OFFICIAL') + '?query=&domain=urn%3Ali%3Adomain%3AHMCTS&subdomain=&sort=&clear_filter=False&clear_label=False' + """ # Deepcopy the cleaned data dict to avoid modifying it inplace query_params = deepcopy(self.cleaned_data) value = query_params.get(filter_name)