#64 TDD: Tests for draft view
This commit is contained in:
parent
06d68380c9
commit
724c26c926
@ -166,4 +166,107 @@ class TestExplorerProfileView(GlobalTemplateTestCaseMixin, ViewTestCase):
|
||||
self.assertTrue(
|
||||
'Im a exmpale link label 6423' in response.content.decode(),
|
||||
msg='Expecting the latest photoalbum label to be on the submitters profile page'
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class TestExplorerDraftsView(GlobalTemplateTestCaseMixin, ViewTestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
user = User.objects.create_user(
|
||||
username='testpeter',
|
||||
password='Develop123'
|
||||
)
|
||||
|
||||
User.objects.create_user(
|
||||
username='otheruser',
|
||||
password='Develop123'
|
||||
)
|
||||
|
||||
superuser = User.objects.create_user(
|
||||
username='toor',
|
||||
password='Develop123'
|
||||
)
|
||||
superuser.is_superuser = True
|
||||
superuser.save()
|
||||
|
||||
def test_draft_view(self):
|
||||
user = User.objects.get(username='testpeter')
|
||||
self.client.login(username='testpeter', password='Develop123')
|
||||
response = self.client.get(
|
||||
reverse('explorer_drafts', kwargs={
|
||||
'explorer_id': user.explorer.id
|
||||
})
|
||||
)
|
||||
self.assertHttpOK(response)
|
||||
|
||||
def test_draft_view_unauthorized_user(self):
|
||||
user = User.objects.get(username='testpeter')
|
||||
self.client.login(username='otheruser', password='Develop123')
|
||||
response = self.client.get(
|
||||
reverse('explorer_drafts', kwargs={
|
||||
'explorer_id': user.explorer.id
|
||||
})
|
||||
)
|
||||
self.assertHttpForbidden(response)
|
||||
|
||||
def test_draft_view_superuser(self):
|
||||
user = User.objects.get(username='testpeter')
|
||||
self.client.login(username='toor', password='Develop123')
|
||||
response = self.client.get(
|
||||
reverse('explorer_drafts', kwargs={
|
||||
'explorer_id': user.explorer.id
|
||||
})
|
||||
)
|
||||
self.assertHttpOK(response)
|
||||
|
||||
def test_place_in_draft_view(self):
|
||||
user = User.objects.get(username='testpeter')
|
||||
Place.objects.create(
|
||||
name='Im a draft place 3792',
|
||||
submitted_when=timezone.now(),
|
||||
submitted_by=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,
|
||||
mode='draft',
|
||||
level=3
|
||||
)
|
||||
|
||||
self.client.login(username='testpeter', password='Develop123')
|
||||
response = self.client.get(
|
||||
reverse('explorer_drafts', kwargs={
|
||||
'explorer_id': user.explorer.id
|
||||
})
|
||||
)
|
||||
|
||||
self.assertTrue(
|
||||
'Im a draft place 3792' in response.content.decode(),
|
||||
msg='Expecting a place draft to be visible in the submitters drafs view'
|
||||
)
|
||||
|
||||
def test_place_not_in_draft_view(self):
|
||||
user = User.objects.get(username='testpeter')
|
||||
Place.objects.create(
|
||||
name='Im a draft place 3819',
|
||||
submitted_when=timezone.now(),
|
||||
submitted_by=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
|
||||
)
|
||||
|
||||
self.client.login(username='testpeter', password='Develop123')
|
||||
response = self.client.get(
|
||||
reverse('explorer_drafts', kwargs={
|
||||
'explorer_id': user.explorer.id
|
||||
})
|
||||
)
|
||||
|
||||
self.assertFalse(
|
||||
'Im a draft place 3819' in response.content.decode(),
|
||||
msg='Expecting a live place to not be visible in the submitters drafs view'
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user