#42 Tests for Level-System / Homepage

This commit is contained in:
reverend 2021-12-31 00:35:19 +01:00
parent c6a28c7b66
commit 399fa70ab6
2 changed files with 47 additions and 2 deletions

View File

@ -34,6 +34,32 @@ class TestHomeView(GlobalTemplateTestCaseMixin, ViewTestCase):
place.tags.add('I a tag', 'testlocation') place.tags.add('I a tag', 'testlocation')
place.save() place.save()
# Creating a place with level one to test against
# unauth's users and users with level 1
Place.objects.create(
name='Im a place level 1',
submitted_when=timezone.now(),
submitted_by=user.explorer,
location='Testtown',
latitude=50.5,
longitude=7.0,
description='This is just a test, do not worry',
level=1
)
# Creating a place with level two to test against
# unauth's users and users above level 1
Place.objects.create(
name='Im a place level 2',
submitted_when=timezone.now(),
submitted_by=user.explorer,
location='Testtown',
latitude=50.5,
longitude=7.0,
description='This is just a test, do not worry',
level=2
)
def setUp(self): def setUp(self):
self.client = Client() self.client = Client()
@ -81,6 +107,25 @@ class TestHomeView(GlobalTemplateTestCaseMixin, ViewTestCase):
msg='Expecting the test place to show up on the homepage' msg='Expecting the test place to show up on the homepage'
) )
print(response.content.decode().replace('\n', ''))
self.assertNotEqual(
None,
re.search(
"""Im a place level 1""",
response.content.decode().replace('\n', '')
),
msg="Expecting the level 1 places to show up on the homepage publicly"
)
self.assertEqual(
None,
re.search(
"""Im a place level 2""",
response.content.decode().replace('\n', '')
),
msg="Expecting the level 2 places to *not* show up on the homepage publicly"
)
def test_map_authenticated(self): def test_map_authenticated(self):
""" """
Testing there is a map showing all the lates places Testing there is a map showing all the lates places

View File

@ -42,7 +42,7 @@ class HomeView(IsAuthenticatedMixin, View):
return render(request, 'home.html', context) return render(request, 'home.html', context)
def handle_no_permission(self): def handle_no_permission(self):
place_list = Place.objects.all().order_by('-submitted_when')[:5] place_list = Place.objects.filter(level=1)[:5]
context = { context = {
'place_list': place_list 'place_list': place_list
} }