From 9cc8ee289afa566778faf887b1c4648028ab605f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Dlouh=C3=BD?= Date: Tue, 4 Oct 2016 16:26:16 +0200 Subject: [PATCH] test also some aspects of posting change_view --- django_admin_smoke_tests/tests.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/django_admin_smoke_tests/tests.py b/django_admin_smoke_tests/tests.py index ac35f74c..8d223690 100644 --- a/django_admin_smoke_tests/tests.py +++ b/django_admin_smoke_tests/tests.py @@ -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 @@ -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:] @@ -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