This repository was archived by the owner on Sep 29, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +33
-2
lines changed
tests/pytest/pems/districts Expand file tree Collapse file tree 2 files changed +33
-2
lines changed Original file line number Diff line number Diff line change 11from django .views .generic import TemplateView
22
3+ from .models import District
4+
35
46class IndexView (TemplateView ):
57 template_name = "districts/index.html"
68
9+ def get_context_data (self , ** kwargs ):
10+ context = super ().get_context_data (** kwargs )
11+ context ["district_queryset" ] = District .objects .all ()
12+ return context
13+
714
815class DistrictView (TemplateView ):
916 template_name = "districts/district.html"
1017
1118 def get_context_data (self , ** kwargs ):
1219 context = super ().get_context_data (** kwargs )
1320 district = self .kwargs .get ("district" )
14- context ["district" ] = district
21+ context ["url_district" ] = district
22+ context ["district_queryset" ] = District .objects .all ()
23+ context ["district_query" ] = District .objects .all ().get (number = district )
1524 return context
Original file line number Diff line number Diff line change 11import pytest
22
33from pems .districts import views
4+ from pems .districts .models import District
5+
6+
7+ class TestIndexViewView :
8+ @pytest .fixture
9+ def view (app_request ):
10+ v = views .IndexView ()
11+ v .setup (app_request )
12+
13+ return v
14+
15+ @pytest .mark .django_db
16+ def test_get_context_data (self , view ):
17+
18+ context = view .get_context_data ()
19+
20+ assert set (context ["district_queryset" ]) == set (District .objects .all ())
21+
22+ def test_template_name (self , view ):
23+ assert view .template_name == "districts/index.html"
424
525
626class TestDistrictView :
@@ -11,11 +31,13 @@ def view(app_request):
1131
1232 return v
1333
34+ @pytest .mark .django_db
35+ @pytest .mark .usefixtures ("model_District" )
1436 def test_get_context_data (self , view ):
1537
1638 context = view .get_context_data ()
1739
18- assert context ["district " ] == 1
40+ assert context ["url_district " ] == 1
1941
2042 def test_template_name (self , view ):
2143 assert view .template_name == "districts/district.html"
You can’t perform that action at this time.
0 commit comments