Skip to content

Commit

Permalink
Więcej testów + poprawny [Jednostka,Wydzial]QueryObject
Browse files Browse the repository at this point in the history
  • Loading branch information
mpasternak committed Feb 17, 2019
1 parent 2400725 commit 291d336
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/bpp/multiseek_registry.py
Expand Up @@ -208,9 +208,9 @@ class PierwszeNazwiskoIImie(NazwiskoIImieWZakresieKolejnosci):


class OstatnieNazwiskoIImie(NazwiskoIImieWZakresieKolejnosci):
ops = [EQUAL,]
ops = [EQUAL, ]
# bez operatora UNION, bo F('liczba_autorow') nie istnieje, gdy
# generujemy zapytanie dla niego.
# generujemy zapytanie dla niego.
kolejnosc_gte = F('liczba_autorow') - 1
kolejnosc_lt = F('liczba_autorow')
label = "Ostatnie nazwisko i imię"
Expand Down Expand Up @@ -340,9 +340,10 @@ class JednostkaQueryObject(ForeignKeyDescribeMixin, AutocompleteQueryObject):
def real_query(self, value, operation):
if operation in EQUALITY_OPS_ALL:
ret = Q(autorzy__jednostka__pk=value.pk)

elif operation in UNION_OPS_ALL:
q = Autorzy.objects.filter(
autor__jednostka__pk=value.pk
jednostka__pk=value.pk
).values("rekord_id")
ret = Q(pk__in=q)
else:
Expand All @@ -365,9 +366,10 @@ class WydzialQueryObject(ForeignKeyDescribeMixin, AutocompleteQueryObject):
def real_query(self, value, operation):
if operation in EQUALITY_OPS_ALL:
ret = Q(autorzy__jednostka__wydzial__pk=value.pk)

elif operation in UNION_OPS_ALL:
q = Autorzy.objects.filter(
jednostka__pk=value.pk
jednostka__wydzial__pk=value.pk
).values("rekord_id")
ret = Q(pk__in=q)

Expand Down
29 changes: 28 additions & 1 deletion src/bpp/tests/test_multiseek_registry.py
Expand Up @@ -16,7 +16,8 @@
OpenaccessCzasPublikacjiQueryObject, ForeignKeyDescribeMixin, PierwszeNazwiskoIImie, \
TypOgolnyAutorQueryObject, TypOgolnyRedaktorQueryObject, TypOgolnyTlumaczQueryObject, TypOgolnyRecenzentQueryObject, \
NazwiskoIImieQueryObject, DataUtworzeniaQueryObject, OstatnieNazwiskoIImie, OstatnioZmieniony, \
OstatnioZmienionyDlaPBN, RodzajKonferenckjiQueryObject, LiczbaAutorowQueryObject, UNION
OstatnioZmienionyDlaPBN, RodzajKonferenckjiQueryObject, LiczbaAutorowQueryObject, UNION, JednostkaQueryObject, \
WydzialQueryObject


@pytest.mark.django_db
Expand Down Expand Up @@ -81,6 +82,32 @@ def test_NazwiskoIImieQueryObject(autor_jan_nowak):
assert ret is not None


def test_JednostkaQueryObject(jednostka):
n = JednostkaQueryObject()

ret = n.real_query(jednostka, logic.EQUAL)
assert ret is not None

ret = n.real_query(jednostka, logic.DIFFERENT)
assert ret is not None

ret = n.real_query(jednostka, UNION)
assert ret is not None


def test_WydzialQueryObject(wydzial):
n = WydzialQueryObject()

ret = n.real_query(wydzial, logic.EQUAL)
assert ret is not None

ret = n.real_query(wydzial, logic.DIFFERENT)
assert ret is not None

ret = n.real_query(wydzial, UNION)
assert ret is not None


@pytest.mark.django_db
def test_PierwszeNazwiskoIImie_real_query(wydawnictwo_zwarte, autor_jan_kowalski, jednostka):
wydawnictwo_zwarte.dodaj_autora(autor_jan_kowalski, jednostka)
Expand Down

0 comments on commit 291d336

Please sign in to comment.