#64 Testing drafts in differents views
This commit is contained in:
parent
df67bcf639
commit
bc0ace7bf3
@ -1,4 +1,4 @@
|
||||
23238#!/usr/bin/env python
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from django.test import TestCase, RequestFactory, Client
|
||||
@ -7,6 +7,7 @@ from django.db import models
|
||||
from django.contrib.auth.models import User, AnonymousUser
|
||||
from django.contrib.messages.storage.fallback import FallbackStorage
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import gettext as _
|
||||
from django.shortcuts import render
|
||||
|
||||
from lostplaces.models import Place
|
||||
@ -46,10 +47,6 @@ class TestIsAuthenticated(ViewTestCase):
|
||||
self.assertHttpRedirect(response, '?'.join([str(reverse_lazy('login')), 'next=/']))
|
||||
|
||||
self.assertTrue(len(messages) > 0)
|
||||
self.assertTrue(
|
||||
_('Please login to proceed') in response.content.decode(),
|
||||
msg='Expecting a message to tell the user to login'
|
||||
)
|
||||
|
||||
class TestIsPlaceSubmitterMixin(TestCase):
|
||||
|
||||
|
@ -678,5 +678,62 @@ class PlaceDetailViewTestCase(TaggableViewTestCaseMixin, MapableViewTestCaseMixi
|
||||
msg='Expecting the explorer to not be in the reverse list of visits after deleting visit'
|
||||
)
|
||||
|
||||
def test_accessing_place_in_draft(self):
|
||||
user = User.objects.get(username='testpeter')
|
||||
place = Place.objects.create(
|
||||
name='Im a own place in draft 387948',
|
||||
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,
|
||||
mode='draft'
|
||||
)
|
||||
|
||||
self.client.login(username='testpeter', password='Develop123')
|
||||
|
||||
response = self.client.get(
|
||||
reverse('place_detail', kwargs={
|
||||
'pk': place.pk
|
||||
})
|
||||
)
|
||||
self.assertHttpOK(response)
|
||||
self.assertTrue(
|
||||
'Im a own place in draft 387948' in response.content.decode(),
|
||||
msg='Expecting the user to see his own place in draft mode'
|
||||
)
|
||||
|
||||
|
||||
self.client.login(username='blubberbernd', password='Develop123')
|
||||
response = self.client.get(
|
||||
reverse('place_detail', kwargs={
|
||||
'pk': place.pk
|
||||
})
|
||||
)
|
||||
self.assertHttpForbidden(response)
|
||||
|
||||
self.client.login(username='toor', password='Develop123')
|
||||
response = self.client.get(
|
||||
reverse('place_detail', kwargs={
|
||||
'pk': place.pk
|
||||
})
|
||||
)
|
||||
self.assertHttpOK(response)
|
||||
self.assertTrue(
|
||||
'Im a own place in draft 387948' in response.content.decode(),
|
||||
msg='Expecting a superuser to see all places in draft mode'
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -12,6 +12,7 @@ from django.contrib import messages
|
||||
from django.contrib.messages.views import SuccessMessageMixin
|
||||
from django.utils.translation import gettext as _
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from django.shortcuts import render, redirect, get_object_or_404
|
||||
from django.urls import reverse_lazy, reverse
|
||||
@ -59,6 +60,12 @@ class PlaceDetailView(IsAuthenticatedMixin, IsEligibleToSeePlaceMixin, View):
|
||||
place.calculate_place_level()
|
||||
explorer = request.user.explorer
|
||||
|
||||
if place.mode == 'draft':
|
||||
messages.info(
|
||||
self.request,
|
||||
_('This place is still in draft mode and only visible to the submitter and superusers')
|
||||
)
|
||||
|
||||
context = {
|
||||
'place': place,
|
||||
'mapping_config': {
|
||||
|
Loading…
Reference in New Issue
Block a user