#132 | #121: backoffice / dev-1.0-121 (#131)

cfr #121

Co-authored-by: Christophe Siraut <d@tobald.eu.org>
Co-authored-by: bkfox <thomas bkfox net>
Co-authored-by: Thomas Kairos <thomas@bkfox.net>
Reviewed-on: rc/aircox#131
Co-authored-by: Chris Tactic <ctactic@noreply.git.radiocampus.be>
Co-committed-by: Chris Tactic <ctactic@noreply.git.radiocampus.be>
This commit is contained in:
2024-04-28 22:02:09 +02:00
committed by Thomas Kairos
parent 1e17a1334a
commit 55123c386d
348 changed files with 124397 additions and 17879 deletions

View File

@ -11,6 +11,9 @@ class FakeView:
def ___init__(self):
self.kwargs = {}
def dispatch(self, *args, **kwargs):
pass
def get(self, *args, **kwargs):
pass

View File

@ -1,6 +1,5 @@
import pytest
from django.urls import reverse
from aircox import models
from aircox.test import Interface
@ -37,31 +36,15 @@ class TestBaseView:
def test_station(self, base_view, station):
assert base_view.station == station
@pytest.mark.django_db
def test_get_sidebar_queryset(self, base_view, pages, published_pages):
query = base_view.get_sidebar_queryset().values_list("id", flat=True)
page_ids = {r.id for r in published_pages}
assert set(query) == page_ids
@pytest.mark.django_db
def test_get_sidebar_url(self, base_view):
assert base_view.get_sidebar_url() == reverse("page-list")
@pytest.mark.django_db
def test_get_context_data(self, base_view, station, published_pages):
base_view.has_sidebar = True
base_view.get_sidebar_queryset = lambda: published_pages
context = base_view.get_context_data()
assert context == {
"view": base_view,
"station": station,
"page": None, # get_page() returns None
"has_sidebar": base_view.has_sidebar,
"has_filters": False,
"sidebar_object_list": published_pages[: base_view.list_count],
"sidebar_list_url": base_view.get_sidebar_url(),
"audio_streams": station.streams,
"model": base_view.model,
"nav_menu": [],
}

View File

@ -40,7 +40,7 @@ def parent_mixin():
@pytest.fixture
def attach_mixin():
class Mixin(mixins.AttachedToMixin, FakeView):
attach_to_value = models.StaticPage.ATTACH_TO_HOME
attach_to_value = models.StaticPage.Target.HOME
return Mixin()
@ -80,7 +80,7 @@ class TestGetDateMixin:
)
def test_get_calls_get_date(self, date_mixin):
date_mixin.get_date = lambda: today
date_mixin.get_date = lambda *_: today
date_mixin.get()
assert date_mixin.date == today
@ -105,10 +105,10 @@ class TestParentMixin:
def test_get_parent_not_parent_url_kwargs(self, parent_mixin):
assert parent_mixin.get_parent(self.req) is None
def test_get_calls_parent(self, parent_mixin):
def test_dispatch_calls_parent(self, parent_mixin):
parent = "parent object"
parent_mixin.get_parent = lambda *_, **kw: parent
parent_mixin.get(self.req)
parent_mixin.dispatch(self.req)
assert parent_mixin.parent == parent
@pytest.mark.django_db
@ -120,7 +120,7 @@ class TestParentMixin:
assert set(query) == episodes_id
def test_get_context_data_with_parent(self, parent_mixin):
parent_mixin.parent = Interface(cover="parent-cover")
parent_mixin.parent = Interface(cover=Interface(url="parent-cover"))
context = parent_mixin.get_context_data()
assert context["cover"] == "parent-cover"