diff --git a/django_lostplaces/lostplaces/tests/views/test_views.py b/django_lostplaces/lostplaces/tests/views/test_views.py index 6b40892..c6f9b5d 100644 --- a/django_lostplaces/lostplaces/tests/views/test_views.py +++ b/django_lostplaces/lostplaces/tests/views/test_views.py @@ -33,6 +33,32 @@ class TestHomeView(GlobalTemplateTestCaseMixin, ViewTestCase): ) place.tags.add('I a tag', 'testlocation') 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): self.client = Client() @@ -80,7 +106,26 @@ class TestHomeView(GlobalTemplateTestCaseMixin, ViewTestCase): ), 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): """ Testing there is a map showing all the lates places diff --git a/django_lostplaces/lostplaces/views/views.py b/django_lostplaces/lostplaces/views/views.py index a72fd8f..d0130b2 100644 --- a/django_lostplaces/lostplaces/views/views.py +++ b/django_lostplaces/lostplaces/views/views.py @@ -42,7 +42,7 @@ class HomeView(IsAuthenticatedMixin, View): return render(request, 'home.html', context) def handle_no_permission(self): - place_list = Place.objects.all().order_by('-submitted_when')[:5] + place_list = Place.objects.filter(level=1)[:5] context = { 'place_list': place_list }