Skip to content

Commit

Permalink
Merge pull request #286 from augustobmoura/fix/incorrect-get-fieldset…
Browse files Browse the repository at this point in the history
…s-calling

Fix incorrect calling of get_fieldsets
  • Loading branch information
gutierri authored May 1, 2024
2 parents babdfd4 + 475b35c commit 1050f92
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion django_reverse_admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def _changeform_view(self, request, object_id, form_url, extra_context):
readonly_fields = self.get_readonly_fields(request, obj)

adminForm = helpers.AdminForm(form,
list(self.get_fieldsets(request)),
list(self.get_fieldsets(request, obj)),
self.prepopulated_fields,
readonly_fields=readonly_fields,
model_admin=self
Expand Down
22 changes: 21 additions & 1 deletion tests/polls/tests/test_admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from unittest import mock

from django.contrib.auth.models import User
from django.test import TestCase
from django.test import Client
from django.urls import reverse
from django.core.handlers.wsgi import WSGIRequest

from polls.models import Address
from polls.models import AddressNonId
Expand All @@ -10,7 +13,7 @@
from polls.models import PersonWithTwoAddresses
from polls.admin import SITE_HEADER
import polls.tests.config as test_config

from django_reverse_admin import ReverseModelAdmin

class AddressAdminTest(TestCase):
def setUp(self):
Expand Down Expand Up @@ -137,3 +140,20 @@ def test_admin_header(self):
change_url = reverse('admin:polls_personwithtwoaddresses_add')
res = client.get(change_url)
self.assertTrue(SITE_HEADER in str(res.content), 'Custom header is set')

@mock.patch.object(ReverseModelAdmin, 'get_fieldsets')
def test_called_args(self, mock):
person = PersonWithAddressNonId.objects.create(name='Toto', home_addr=AddressNonId.objects.create())

client = Client()
client.login(**test_config.ADMIN_USER)
change_url = reverse('admin:polls_personwithaddressnonid_change', args=(person.pk,))
# Ensure it doesn't raise any exception.
client.get(change_url, test_config.PERSON_WITH_TWO_ADDRESSES)
self.assertEqual(mock.call_count, 2)
self.assertEqual(2, len(mock.call_args_list[0].args))
self.assertIsInstance(mock.call_args_list[0].args[0], WSGIRequest)
self.assertIsInstance(mock.call_args_list[0].args[1], PersonWithAddressNonId)
self.assertEqual(2, len(mock.call_args_list[1].args))
self.assertIsInstance(mock.call_args_list[1].args[0], WSGIRequest)
self.assertIsInstance(mock.call_args_list[1].args[1], PersonWithAddressNonId)

0 comments on commit 1050f92

Please sign in to comment.