403 override functionality
This commit is contained in:
@@ -3,11 +3,42 @@ from django.contrib import admin
|
||||
from django.urls import path,include
|
||||
from django.conf import settings
|
||||
from django.conf.urls.static import static
|
||||
from django.shortcuts import render
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.http import HttpResponse
|
||||
from django.test import SimpleTestCase, override_settings
|
||||
|
||||
def response_error_handler(request, exception=None):
|
||||
context={}
|
||||
return render(request, '403.html',context,status=403)
|
||||
|
||||
|
||||
def permission_denied_view(request):
|
||||
raise PermissionDenied
|
||||
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
path('accounts/', include('allauth.urls')),
|
||||
path('', include('Clientes.urls')),
|
||||
path('403/', permission_denied_view),
|
||||
]
|
||||
handler403 = response_error_handler
|
||||
|
||||
|
||||
|
||||
if settings.DEBUG: #DEV only
|
||||
urlpatterns += static(settings.STATIC_URL, document_root= settings.STATIC_ROOT)
|
||||
urlpatterns += static(settings.MEDIA_URL, document_root= settings.MEDIA_ROOT)
|
||||
urlpatterns += static(settings.MEDIA_URL, document_root= settings.MEDIA_ROOT)
|
||||
|
||||
|
||||
|
||||
# ROOT_URLCONF must specify the module that contains handler403 = ...
|
||||
@override_settings(ROOT_URLCONF=__name__)
|
||||
class CustomErrorHandlerTests(SimpleTestCase):
|
||||
|
||||
def test_handler_renders_template_response(self):
|
||||
response = self.client.get('/403/')
|
||||
# Make assertions on the response here. For example:
|
||||
self.assertContains(response, 'Error handler content', status_code=403)
|
||||
Reference in New Issue
Block a user