Skip to content

Commit

Permalink
test also some aspects of posting change_view
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrDlouhy committed Oct 4, 2016
1 parent 9b92f9e commit 9cc8ee2
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion django_admin_smoke_tests/tests.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import django

from django.contrib import admin, auth
from django.core.exceptions import ObjectDoesNotExist, PermissionDenied
from django.core.exceptions import ObjectDoesNotExist, PermissionDenied, ValidationError
from django.http.request import QueryDict
from django.test import TestCase
from django.test.client import RequestFactory
Expand Down Expand Up @@ -80,6 +80,13 @@ def get_request(self, params=None):
request.user = self.superuser
return request

def post_request(self, post_data={}, params=None):
request = self.factory.post('/', params, post_data=post_data)

request.user = self.superuser
request._dont_enforce_csrf_checks = True
return request

def strip_minus(self, attr, val):
if attr in self.strip_minus_attrs and val[0] == '-':
val = val[1:]
Expand Down Expand Up @@ -244,5 +251,23 @@ def test_change_view(self, model, model_admin):
self.assertEqual(response.status_code, 200)


@for_all_model_admins
def test_change_post(self, model, model_admin):
item = model.objects.last()
if not item or model._meta.proxy:
return
pk = item.pk
# TODO: If we generate default post_data for post request, the test would be stronger
request = self.post_request()
try:
response = model_admin.change_view(request, object_id=str(pk))
if isinstance(response, django.template.response.TemplateResponse):
response.render()
self.assertEqual(response.status_code, 200)
except ValidationError:
# This the form was sent, but did not pass it's validation
pass


class AdminSiteSmokeTest(AdminSiteSmokeTestMixin, TestCase):
pass

0 comments on commit 9cc8ee2

Please sign in to comment.