Compare commits
3 Commits
4f465b3162
...
51addd8fbb
Author | SHA1 | Date | |
---|---|---|---|
51addd8fbb | |||
29d2813fcc | |||
cc9343270a |
@ -28,6 +28,6 @@ from lostplaces.views import SignUpView
|
|||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
path('signup/', SignUpView.as_view(), name='signup'),
|
path('signup/', SignUpView.as_view(), name='signup'),
|
||||||
path('explorers/', include('django.contrib.auth.urls')),
|
path('explorer/', include('django.contrib.auth.urls')),
|
||||||
path('', include('lostplaces.urls')),
|
path('', include('lostplaces.urls')),
|
||||||
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form id="id_tag_submit_form" class="LP-Form LP-Form--inline LP-Form--tagging" method="POST" action="{% url config.submit_url_name tagged_id=config.tagged_item.id%}">
|
<form id="id_tag_submit_form" class="LP-Form LP-Form--inline LP-Form--tagging" method="POST" action="{{config.submit_url}}">
|
||||||
<fieldset class="LP-Form__Fieldset">
|
<fieldset class="LP-Form__Fieldset">
|
||||||
<legend class="LP-Form__Legend">{% translate 'Add tags' %}</legend>
|
<legend class="LP-Form__Legend">{% translate 'Add tags' %}</legend>
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
@ -17,6 +17,20 @@ class ViewTestCase(TestCase):
|
|||||||
'''
|
'''
|
||||||
view = None
|
view = None
|
||||||
|
|
||||||
|
def assertMessage(self, response, message_text, message_type, msg=None):
|
||||||
|
self.assertNotEqual(
|
||||||
|
None,
|
||||||
|
re.search(
|
||||||
|
"""<div.*message.*%s.*>.*%s.*</div>""" % (
|
||||||
|
message_type.lower(),
|
||||||
|
message_text.lower()
|
||||||
|
),
|
||||||
|
response.content.decode().replace('\n', '').lower()
|
||||||
|
),
|
||||||
|
msg
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def assertContext(self, response, key, value=None):
|
def assertContext(self, response, key, value=None):
|
||||||
'''
|
'''
|
||||||
Checks weather the response's context has the given key
|
Checks weather the response's context has the given key
|
||||||
|
@ -9,6 +9,7 @@ from django.urls import reverse
|
|||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
|
|
||||||
from lostplaces.models import Place
|
from lostplaces.models import Place
|
||||||
@ -99,7 +100,7 @@ class TestPlaceCreateView(ViewTestCase):
|
|||||||
self.client.login(username='testpeter', password='Develop123')
|
self.client.login(username='testpeter', password='Develop123')
|
||||||
response = self.client.post(
|
response = self.client.post(
|
||||||
reverse('place_create'),
|
reverse('place_create'),
|
||||||
{
|
data={
|
||||||
'name': 'test place 486',
|
'name': 'test place 486',
|
||||||
'location': 'test location',
|
'location': 'test location',
|
||||||
'latitude': 45.804192,
|
'latitude': 45.804192,
|
||||||
@ -107,23 +108,27 @@ class TestPlaceCreateView(ViewTestCase):
|
|||||||
'description': """
|
'description': """
|
||||||
Cupiditate harum reprehenderit ipsam iure consequuntur eaque eos reiciendis. Blanditiis vel minima minus repudiandae voluptate aut quia sed. Provident ex omnis illo molestiae. Ullam eos et est provident enim deserunt.
|
Cupiditate harum reprehenderit ipsam iure consequuntur eaque eos reiciendis. Blanditiis vel minima minus repudiandae voluptate aut quia sed. Provident ex omnis illo molestiae. Ullam eos et est provident enim deserunt.
|
||||||
"""
|
"""
|
||||||
}
|
},
|
||||||
|
follow=True
|
||||||
)
|
)
|
||||||
self.assertHttpRedirect(response)
|
self.assertHttpOK(response)
|
||||||
place = Place.objects.get(name='test place 486')
|
place = Place.objects.get(name='test place 486')
|
||||||
self.assertNotEqual(
|
self.assertNotEqual(
|
||||||
None,
|
None,
|
||||||
place,
|
place,
|
||||||
msg='Submitted place not found in database / model'
|
msg='Submitted place not found in database / model'
|
||||||
),
|
),
|
||||||
self.assertNotEqual(
|
self.assertEqual(
|
||||||
None,
|
reverse(
|
||||||
re.search(
|
|
||||||
""".*%s""" % reverse(
|
|
||||||
'place_detail', kwargs={'pk': place.id}
|
'place_detail', kwargs={'pk': place.id}
|
||||||
),
|
),
|
||||||
response.url
|
response.redirect_chain[-1][0]
|
||||||
)
|
)
|
||||||
|
self.assertMessage(
|
||||||
|
response,
|
||||||
|
_('Successfully created place'),
|
||||||
|
'success',
|
||||||
|
msg='Expecting a visible success message'
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_positive_image(self):
|
def test_positive_image(self):
|
||||||
@ -138,7 +143,7 @@ class TestPlaceCreateView(ViewTestCase):
|
|||||||
)
|
)
|
||||||
response = self.client.post(
|
response = self.client.post(
|
||||||
reverse('place_create'),
|
reverse('place_create'),
|
||||||
{
|
data={
|
||||||
'name': 'test place 894',
|
'name': 'test place 894',
|
||||||
'location': 'test location',
|
'location': 'test location',
|
||||||
'latitude': 45.804192,
|
'latitude': 45.804192,
|
||||||
@ -147,29 +152,33 @@ class TestPlaceCreateView(ViewTestCase):
|
|||||||
Cupiditate harum reprehenderit ipsam iure consequuntur eaque eos reiciendis. Blanditiis vel minima minus repudiandae voluptate aut quia sed. Provident ex omnis illo molestiae. Ullam eos et est provident enim deserunt.
|
Cupiditate harum reprehenderit ipsam iure consequuntur eaque eos reiciendis. Blanditiis vel minima minus repudiandae voluptate aut quia sed. Provident ex omnis illo molestiae. Ullam eos et est provident enim deserunt.
|
||||||
""",
|
""",
|
||||||
'filename': [image]
|
'filename': [image]
|
||||||
}
|
},
|
||||||
|
follow=True
|
||||||
)
|
)
|
||||||
self.assertHttpRedirect(response)
|
self.assertHttpOK(response)
|
||||||
place = Place.objects.get(name='test place 894')
|
place = Place.objects.get(name='test place 894')
|
||||||
self.assertNotEqual(
|
self.assertNotEqual(
|
||||||
None,
|
None,
|
||||||
place,
|
place,
|
||||||
msg='Submitted place not found in database / model'
|
msg='Submitted place not found in database / model'
|
||||||
),
|
),
|
||||||
self.assertNotEqual(
|
self.assertEqual(
|
||||||
None,
|
reverse(
|
||||||
re.search(
|
|
||||||
""".*%s""" % reverse(
|
|
||||||
'place_detail', kwargs={'pk': place.id}
|
'place_detail', kwargs={'pk': place.id}
|
||||||
),
|
),
|
||||||
response.url
|
response.redirect_chain[-1][0]
|
||||||
)
|
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
len(place.placeimages.all()),
|
len(place.placeimages.all()),
|
||||||
1,
|
1,
|
||||||
msg='Expecting the place to have exactly 1 place image'
|
msg='Expecting the place to have exactly 1 place image'
|
||||||
)
|
)
|
||||||
|
self.assertMessage(
|
||||||
|
response,
|
||||||
|
_('Successfully created place'),
|
||||||
|
'success',
|
||||||
|
msg='Expecting a visible success message'
|
||||||
|
)
|
||||||
|
|
||||||
def test_negative_no_name(self):
|
def test_negative_no_name(self):
|
||||||
self.client.login(username='testpeter', password='Develop123')
|
self.client.login(username='testpeter', password='Develop123')
|
||||||
@ -190,6 +199,12 @@ class TestPlaceCreateView(ViewTestCase):
|
|||||||
0,
|
0,
|
||||||
msg='Expecting no place to be created'
|
msg='Expecting no place to be created'
|
||||||
)
|
)
|
||||||
|
self.assertMessage(
|
||||||
|
response,
|
||||||
|
_('Please fill in all required fields.'),
|
||||||
|
'error',
|
||||||
|
msg='Expecing a visible error message'
|
||||||
|
)
|
||||||
|
|
||||||
def test_negative_no_location(self):
|
def test_negative_no_location(self):
|
||||||
self.client.login(username='testpeter', password='Develop123')
|
self.client.login(username='testpeter', password='Develop123')
|
||||||
@ -210,6 +225,12 @@ class TestPlaceCreateView(ViewTestCase):
|
|||||||
0,
|
0,
|
||||||
msg='Expecting no place to be created'
|
msg='Expecting no place to be created'
|
||||||
)
|
)
|
||||||
|
self.assertMessage(
|
||||||
|
response,
|
||||||
|
_('Please fill in all required fields.'),
|
||||||
|
'error',
|
||||||
|
msg='Expecing a visible error message'
|
||||||
|
)
|
||||||
|
|
||||||
def test_negative_no_latitude(self):
|
def test_negative_no_latitude(self):
|
||||||
self.client.login(username='testpeter', password='Develop123')
|
self.client.login(username='testpeter', password='Develop123')
|
||||||
@ -230,6 +251,12 @@ class TestPlaceCreateView(ViewTestCase):
|
|||||||
0,
|
0,
|
||||||
msg='Expecting no place to be created'
|
msg='Expecting no place to be created'
|
||||||
)
|
)
|
||||||
|
self.assertMessage(
|
||||||
|
response,
|
||||||
|
_('Please fill in all required fields.'),
|
||||||
|
'error',
|
||||||
|
msg='Expecing a visible error message'
|
||||||
|
)
|
||||||
|
|
||||||
def test_negative_no_longitude(self):
|
def test_negative_no_longitude(self):
|
||||||
self.client.login(username='testpeter', password='Develop123')
|
self.client.login(username='testpeter', password='Develop123')
|
||||||
@ -250,6 +277,12 @@ class TestPlaceCreateView(ViewTestCase):
|
|||||||
0,
|
0,
|
||||||
msg='Expecting no place to be created'
|
msg='Expecting no place to be created'
|
||||||
)
|
)
|
||||||
|
self.assertMessage(
|
||||||
|
response,
|
||||||
|
_('Please fill in all required fields.'),
|
||||||
|
'error',
|
||||||
|
msg='Expecing a visible error message'
|
||||||
|
)
|
||||||
|
|
||||||
class PlaceDetailViewTestCase(TaggableViewTestCaseMixin, MapableViewTestCaseMixin, ViewTestCase):
|
class PlaceDetailViewTestCase(TaggableViewTestCaseMixin, MapableViewTestCaseMixin, ViewTestCase):
|
||||||
view = PlaceDetailView
|
view = PlaceDetailView
|
||||||
@ -273,6 +306,19 @@ class PlaceDetailViewTestCase(TaggableViewTestCaseMixin, MapableViewTestCaseMixi
|
|||||||
place.tags.add('I a tag', 'testlocation')
|
place.tags.add('I a tag', 'testlocation')
|
||||||
place.save()
|
place.save()
|
||||||
|
|
||||||
|
def test_not_authenticated(self):
|
||||||
|
response = self.client.get(reverse('place_detail', kwargs={'pk': 1}))
|
||||||
|
self.assertHttpRedirect(response)
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
'%s?next=%s' % (
|
||||||
|
reverse('login'),
|
||||||
|
reverse('place_detail', kwargs={'pk': 1})
|
||||||
|
),
|
||||||
|
response.url,
|
||||||
|
msg='Expecting unauthenticated user to be redirected to login page, using the \'next\' GET-Param to store the places details page'
|
||||||
|
)
|
||||||
|
|
||||||
def test_context(self):
|
def test_context(self):
|
||||||
self.client.login(username='testpeter', password='Develop123')
|
self.client.login(username='testpeter', password='Develop123')
|
||||||
response = self.client.get(reverse('place_detail', kwargs={'pk': 1}))
|
response = self.client.get(reverse('place_detail', kwargs={'pk': 1}))
|
||||||
|
@ -50,7 +50,7 @@ class PlaceDetailView(IsAuthenticatedMixin, View):
|
|||||||
'all_tags': Tag.objects.all(),
|
'all_tags': Tag.objects.all(),
|
||||||
'submit_form': TagSubmitForm(),
|
'submit_form': TagSubmitForm(),
|
||||||
'tagged_item': place,
|
'tagged_item': place,
|
||||||
'submit_url_name': 'place_tag_submit',
|
'submit_url': reverse('place_tag_submit', kwargs={'tagged_id': place.id}),
|
||||||
'delete_url_name': 'place_tag_delete'
|
'delete_url_name': 'place_tag_delete'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user