Skip to content

Commit

Permalink
about page unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adambreznicky committed Nov 27, 2017
1 parent 5295e86 commit 37e6d49
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
53 changes: 53 additions & 0 deletions lakegallery/map/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,15 @@ def test_story_pages(self):
response = self.client.get('/' + lake_region.lower() + '/' + lake_name)
self.assertEqual(response.status_code, 302)

def test_about(self):
"""
Test the about page URL
"""
response = self.client.get('/about/')
self.assertEqual(response.status_code, 200)
response = self.client.get('/about')
self.assertEqual(response.status_code, 301)


class ViewTests(TestCase):

Expand Down Expand Up @@ -906,6 +915,41 @@ def test_story_context(self):
True)
self.assertEqual(response.context['overlay_query'], m.id)

def test_about_context(self):
"""
Test the about template context; config & header lists
"""
# although the header functions are tested above, we will retest them
# here to verify they are in the context
region_nm_1, region_lt_1 = 'rwpa 1', 'A'
region_nm_2, region_lt_2 = 'rwpa 2', 'B'
RWPAs(objectid=1, reg_name=region_nm_1, letter=region_lt_1,
shape_leng=10, shape_area=2, geom=test_geom).save()
RWPAs(objectid=2, reg_name=region_nm_2, letter=region_lt_2,
shape_leng=10, shape_area=2, geom=test_geom).save()
res_nm_1, res_lt_1 = 'mr 1', 'A'
res_nm_2, res_lt_2 = 'mr 2', 'B'
MajorReservoirs(res_lbl=res_nm_1, region=res_lt_1,
geom=test_geom).save()
MajorReservoirs(res_lbl=res_nm_2, region=res_lt_2,
geom=test_geom).save()
response = self.client.get(reverse('map:about'))
hdr_reg = response.context['header_regions']
self.assertEqual(hdr_reg, [{'name': region_nm_1,
'letter': region_lt_1},
{'name': region_nm_2,
'letter': region_lt_2}])
hdr_lks = response.context['header_lakes']
self.assertEqual(hdr_lks, [{'name': res_nm_1,
'region': res_lt_1,
'class': 'disabled'},
{'name': res_nm_2,
'region': res_lt_2,
'class': 'disabled'}])
# check the version number in the context
self.assertIs('version' in response.context, True)
self.assertEqual(response.context['version'], settings.VERSION)

def test_templates(self):
"""
Test view templates include required leaflet and html
Expand All @@ -917,6 +961,7 @@ def test_templates(self):
region_template = 'map/region.html'
story_template = 'map/story.html'
story_mobile_template = 'map/story_mobile.html'
about_template = 'map/about.html'

# index template
response = self.client.get('/')
Expand Down Expand Up @@ -973,6 +1018,14 @@ def test_templates(self):
self.assertIs(story_mobile_template in template_names, True)
self.assertIs(base_template in template_names, True)

# about template
response = self.client.get('/about/')
template_names = []
for t in response.templates:
template_names.append(t.name)
self.assertIs(about_template in template_names, True)
self.assertIs(base_template in template_names, True)


class SignalTests(TestCase):

Expand Down
2 changes: 1 addition & 1 deletion lakegallery/map/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def about(request):
labels = get_region_header_list()
res = get_lake_header_list()
context = {'header_regions': labels, 'header_lakes': res,
'layers': layers, 'version': settings.VERSION}
'version': settings.VERSION}

return render(request, 'map/about.html', context)

Expand Down

0 comments on commit 37e6d49

Please sign in to comment.