forked from rc/aircox
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>
60 lines
1.5 KiB
Python
60 lines
1.5 KiB
Python
import pytest
|
|
|
|
|
|
from aircox import models
|
|
from aircox.test import Interface
|
|
from aircox.views import base
|
|
from .conftest import FakeView
|
|
|
|
|
|
@pytest.fixture
|
|
def fake_request(station):
|
|
return Interface(station=station)
|
|
|
|
|
|
@pytest.fixture
|
|
def base_view(fake_request):
|
|
class View(base.BaseView, FakeView):
|
|
model = models.Page
|
|
request = fake_request
|
|
|
|
return View()
|
|
|
|
|
|
@pytest.fixture
|
|
def base_api_view(fake_request):
|
|
class View(base.BaseAPIView, FakeView):
|
|
model = models.Program
|
|
queryset = models.Program.objects.all()
|
|
request = fake_request
|
|
|
|
return View()
|
|
|
|
|
|
class TestBaseView:
|
|
@pytest.mark.django_db
|
|
def test_station(self, base_view, station):
|
|
assert base_view.station == station
|
|
|
|
@pytest.mark.django_db
|
|
def test_get_context_data(self, base_view, station, published_pages):
|
|
context = base_view.get_context_data()
|
|
assert context == {
|
|
"view": base_view,
|
|
"station": station,
|
|
"page": None, # get_page() returns None
|
|
"model": base_view.model,
|
|
"nav_menu": [],
|
|
}
|
|
|
|
|
|
class TestBaseAPIView:
|
|
@pytest.mark.django_db
|
|
def test_station(self, base_api_view, station):
|
|
assert base_api_view.station == station
|
|
|
|
@pytest.mark.django_db
|
|
def test_get_queryset(self, base_api_view, station, programs):
|
|
query = base_api_view.get_queryset()
|
|
assert set(query.values_list("station", flat=True)) == {station.id}
|