Compare commits

..

3 Commits

Author SHA1 Message Date
f7dab77229 #42 Testing place detail for level 2021-10-02 01:31:12 +02:00
8d96214a92 Nose testing sutie 2021-10-02 01:30:53 +02:00
6678f8ff02 Nose testing suite 2021-10-02 01:30:44 +02:00
3 changed files with 83 additions and 2 deletions

View File

@ -13,6 +13,7 @@ twine = "*"
pandoc = "*" pandoc = "*"
pylint-django = "*" pylint-django = "*"
setuptools = "*" setuptools = "*"
django-nose = "*"
[packages] [packages]
django = "*" django = "*"

View File

@ -49,7 +49,15 @@ INSTALLED_APPS = [
'django.contrib.contenttypes', 'django.contrib.contenttypes',
'django.contrib.sessions', 'django.contrib.sessions',
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles' 'django.contrib.staticfiles',
'django_nose'
]
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
NOSE_ARGS = [
'--with-coverage',
'--cover-package=lostplaces',
] ]
MIDDLEWARE = [ MIDDLEWARE = [

View File

@ -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)