#42 Testing place detail for level
This commit is contained in:
parent
8d96214a92
commit
f7dab77229
@ -145,6 +145,15 @@ class TestPlaceListView(GlobalTemplateTestCaseMixin, ViewTestCase):
|
|||||||
'Im a own place' in response.content.decode(),
|
'Im a own place' in response.content.decode(),
|
||||||
msg='Expecting the user to see it\'s own places'
|
msg='Expecting the user to see it\'s own places'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_eligible_to_see(self):
|
||||||
|
self.client.login(username='testpeter', password='Develop123')
|
||||||
|
response = self.client.get(reverse('place_list'))
|
||||||
|
|
||||||
|
self.assertTrue(
|
||||||
|
'Im a own place' in response.content.decode(),
|
||||||
|
msg='Expecting the user to see places where their level is high enough'
|
||||||
|
)
|
||||||
|
|
||||||
class TestPlaceCreateView(ViewTestCase):
|
class TestPlaceCreateView(ViewTestCase):
|
||||||
view = PlaceCreateView
|
view = PlaceCreateView
|
||||||
@ -363,6 +372,8 @@ class PlaceDetailViewTestCase(TaggableViewTestCaseMixin, MapableViewTestCaseMixi
|
|||||||
username='testpeter',
|
username='testpeter',
|
||||||
password='Develop123'
|
password='Develop123'
|
||||||
)
|
)
|
||||||
|
user.explorer.level = 3
|
||||||
|
user.explorer.save()
|
||||||
|
|
||||||
place = Place.objects.create(
|
place = Place.objects.create(
|
||||||
name='Im a place',
|
name='Im a place',
|
||||||
@ -371,11 +382,72 @@ class PlaceDetailViewTestCase(TaggableViewTestCaseMixin, MapableViewTestCaseMixi
|
|||||||
location='Testtown',
|
location='Testtown',
|
||||||
latitude=50.5,
|
latitude=50.5,
|
||||||
longitude=7.0,
|
longitude=7.0,
|
||||||
description='This is just a test, do not worry'
|
description='This is just a test, do not worry',
|
||||||
|
level=3
|
||||||
)
|
)
|
||||||
place.tags.add('I a tag', 'testlocation')
|
place.tags.add('I a tag', 'testlocation')
|
||||||
place.save()
|
place.save()
|
||||||
|
|
||||||
|
other_user = User.objects.create_user(
|
||||||
|
username='blubberbernd',
|
||||||
|
password='Develop123'
|
||||||
|
)
|
||||||
|
|
||||||
|
superuser = User.objects.create_user(
|
||||||
|
username='toor',
|
||||||
|
password='Develop123'
|
||||||
|
)
|
||||||
|
|
||||||
|
superuser.is_superuser = True
|
||||||
|
superuser.save()
|
||||||
|
|
||||||
|
Place.objects.create(
|
||||||
|
name='Im a own place',
|
||||||
|
submitted_when=timezone.now(),
|
||||||
|
submitted_by=other_user.explorer,
|
||||||
|
location='Test %d town' % 5,
|
||||||
|
latitude=50.5 + 5/10,
|
||||||
|
longitude=7.0 - 5/10,
|
||||||
|
description='This is just a test, do not worry %d' % 5,
|
||||||
|
level=3
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_not_eligible_to_see_because_of_low_level(self):
|
||||||
|
self.client.login(username='blubberbernd', password='Develop123')
|
||||||
|
response = self.client.get(reverse('place_detail', kwargs={'pk': 1}))
|
||||||
|
|
||||||
|
self.assertFalse(
|
||||||
|
'Im a place' in response.content.decode(),
|
||||||
|
msg='Expecting the user to not see the places'
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_not_eligible_to_see_because_of_low_level_superuser(self):
|
||||||
|
self.client.login(username='toor', password='Develop123')
|
||||||
|
response = self.client.get(reverse('place_detail', kwargs={'pk': 1}))
|
||||||
|
|
||||||
|
self.assertTrue(
|
||||||
|
'Im a place' in response.content.decode(),
|
||||||
|
msg='Expecting the superuser to see all places'
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_not_eligible_to_see_because_of_low_level_own_place(self):
|
||||||
|
self.client.login(username='blubberbernd', password='Develop123')
|
||||||
|
response = self.client.get(reverse('place_detail', kwargs={'pk': 2}))
|
||||||
|
|
||||||
|
self.assertTrue(
|
||||||
|
'Im a own place' in response.content.decode(),
|
||||||
|
msg='Expecting the user to see it\'s own places'
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_eligible_to_see(self):
|
||||||
|
self.client.login(username='testpeter', password='Develop123')
|
||||||
|
response = self.client.get(reverse('place_detail', kwargs={'pk': 2}))
|
||||||
|
|
||||||
|
self.assertTrue(
|
||||||
|
'Im a own place' in response.content.decode(),
|
||||||
|
msg='Expecting the user to see places where their level is high enough'
|
||||||
|
)
|
||||||
|
|
||||||
def test_not_authenticated(self):
|
def test_not_authenticated(self):
|
||||||
response = self.client.get(reverse('place_detail', kwargs={'pk': 1}))
|
response = self.client.get(reverse('place_detail', kwargs={'pk': 1}))
|
||||||
self.assertHttpRedirect(response)
|
self.assertHttpRedirect(response)
|
||||||
|
Loading…
Reference in New Issue
Block a user