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 1
1
from django .views .generic import TemplateView
2
2
3
+ from .models import District
4
+
3
5
4
6
class IndexView (TemplateView ):
5
7
template_name = "districts/index.html"
6
8
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
+
7
14
8
15
class DistrictView (TemplateView ):
9
16
template_name = "districts/district.html"
10
17
11
18
def get_context_data (self , ** kwargs ):
12
19
context = super ().get_context_data (** kwargs )
13
20
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 )
15
24
return context
Original file line number Diff line number Diff line change 1
1
import pytest
2
2
3
3
from 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"
4
24
5
25
6
26
class TestDistrictView :
@@ -11,11 +31,13 @@ def view(app_request):
11
31
12
32
return v
13
33
34
+ @pytest .mark .django_db
35
+ @pytest .mark .usefixtures ("model_District" )
14
36
def test_get_context_data (self , view ):
15
37
16
38
context = view .get_context_data ()
17
39
18
- assert context ["district " ] == 1
40
+ assert context ["url_district " ] == 1
19
41
20
42
def test_template_name (self , view ):
21
43
assert view .template_name == "districts/district.html"
You can’t perform that action at this time.
0 commit comments