#42 Tests for Level-System / Homepage
This commit is contained in:
		@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user