Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions src/bpp/newsfragments/+fd503.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Wyszukiwanie bez wyników pokazuje teraz „Razem: 0" zamiast nieaktualnego licznika, a komunikat „Brak elementów" nie jest już numerowany jako pozycja „0." (FD#503).
65 changes: 63 additions & 2 deletions src/bpp/tests/test_views/test_mymultiseek_count_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
from django.test.utils import CaptureQueriesContext
from django.urls import reverse
from django.utils import translation
from multiseek.logic import STARTS_WITH
from model_bakery import baker
from multiseek.logic import EQUAL_NONE, STARTS_WITH
from multiseek.views import MULTISEEK_SESSION_KEY, MULTISEEK_SESSION_KEY_REMOVED

from bpp.models import Rekord
from bpp.models import Autor, Rekord
from bpp.tests.util import any_ciagle

TYTUL_PREFIX = "CCache multiseek"
LIST_REPORT_TYPE = "0"
TABLE_REPORT_TYPE = "1"


Expand Down Expand Up @@ -136,3 +138,62 @@ def test_zalogowanie_ma_osobny_cache(client, admin_client, dwa_rekordy, locmem_c
_ustaw_filtr(admin_client, TYTUL_PREFIX)
res = admin_client.get(reverse("multiseek:results"))
assert res.context["paginator_count"] == 2


@pytest.mark.django_db
@pytest.mark.parametrize("report_type", [LIST_REPORT_TYPE, TABLE_REPORT_TYPE])
def test_fd503_pusty_wynik_przelicza_nieaktualny_licznik(
client, standard_data, locmem_cache, report_type
):
"""FD#503: rekord zniknął z wyników w czasie życia wpisu cache — lista
była już pusta, a pasek dalej pokazywał „Razem: 1"."""
rekord = any_ciagle(tytul_oryginalny=f"{TYTUL_PREFIX} znika", rok=2024)
_ustaw_filtr(client, TYTUL_PREFIX, report_type)
assert client.get(reverse("multiseek:results")).context["paginator_count"] == 1

rekord.delete()

res = client.get(reverse("multiseek:results"))
assert res.context["paginator_count"] == 0
assert "Razem: 0" in res.content.decode()


@pytest.mark.django_db
def test_fd503_autor_bez_prac_ma_licznik_zero(client, standard_data):
"""FD#503: bez cache autor bez prac daje 0 — rozjazd z ticketu nie
pochodzi z zapytania, tylko z nieaktualnego wpisu cache."""
autor = baker.make(Autor)
with translation.override(django_settings.LANGUAGE_CODE):
operator = str(EQUAL_NONE)

session = client.session
session[MULTISEEK_SESSION_KEY] = json.dumps(
{
"form_data": [
None,
{
"field": "Nazwisko i imię",
"operator": operator,
"value": str(autor.pk),
"prev_op": None,
},
],
"ordering": {},
"report_type": LIST_REPORT_TYPE,
}
)
session.save()

assert client.get(reverse("multiseek:results")).context["paginator_count"] == 0


@pytest.mark.django_db
def test_fd503_brak_elementow_nie_jest_numerowana_pozycja(client, standard_data):
"""FD#503: komunikat o braku wyników jako <li> dostawał z CSS numer „0."."""
_ustaw_filtr(client, f"{TYTUL_PREFIX} nie ma", LIST_REPORT_TYPE)

tresc = client.get(reverse("multiseek:results")).content.decode()

lista = tresc[tresc.index("<ol") : tresc.index("</ol>")]
assert "Brak elementów" in tresc
assert "Brak elementów" not in lista
4 changes: 4 additions & 0 deletions src/bpp/views/mymultiseek.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ def get_context_data(self, **kwargs):
# kazda zmiana formularza / wyrzucenie rekordu zmienia klucz.
cache_key = self._aggregate_cache_key()
agregaty = cache.get(cache_key)
# Wszystkie rekordy zniknely z wynikow w czasie zycia wpisu: pusta
# lista obok niezerowego licznika to widoczna sprzecznosc (FD#503).
if agregaty is not None and agregaty["paginator_count"] and not qset.exists():
agregaty = None
if agregaty is None:
if ctx["report_type"] in EXTRA_TYPES:
# Licznik i sumy jednym skanem — przy DISTINCT + join do
Expand Down
6 changes: 4 additions & 2 deletions src/django_bpp/templates/multiseek/report-body-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@
</span>
{% endif %}
</li>
{% empty %}
<li style="text-align: center; color: #6c757d; padding: 20px;">{% trans "No elements" %}</li>
{% endfor %}
</ol>
{# Poza <ol>: każdy <li> dostaje z CSS numer, więc komunikat byłby pozycją „0.". #}
{% if not object_list %}
<p style="text-align: center; color: #6c757d; padding: 20px;">{% trans "No elements" %}</p>
{% endif %}
</div>
Loading