[Django] #29885: mock called never gets set after upgrade to 2.1

2 views
Skip to first unread message

Django

unread,
Oct 24, 2018, 11:13:53 AM10/24/18
to django-...@googlegroups.com
#29885: mock called never gets set after upgrade to 2.1
---------------------------------------------+------------------------
Reporter: Julz | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 2.1
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
---------------------------------------------+------------------------
after upgrading from 2.0.9 to 2.1.2 we have a problem with a test like
this:
{{{
@patch.object(SomeModelAdmin, 'action_to_mock')
def test_admin_action_is_triggered(self, action_mock):
url = reverse('admin:some_model_changelist')
data = {'action': 'action_to_mock', '_selected_action': [1, 2]}
self.client.post(url, data)
self.assertTrue(action_mock.called)
}}}
on versions <2.1 it works fine. called is set to True and the call_count
increases.
I can't find anything in the changelogs so I assume it's a bug

--
Ticket URL: <https://code.djangoproject.com/ticket/29885>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Oct 24, 2018, 11:19:24 AM10/24/18
to django-...@googlegroups.com
#29885: mock called never gets set after upgrade to 2.1
-----------------------------------+--------------------------------------

Reporter: Julz | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 2.1
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Description changed by Julz:

Old description:

> after upgrading from 2.0.9 to 2.1.2 we have a problem with a test like
> this:
> {{{
> @patch.object(SomeModelAdmin, 'action_to_mock')
> def test_admin_action_is_triggered(self, action_mock):
> url = reverse('admin:some_model_changelist')
> data = {'action': 'action_to_mock', '_selected_action': [1, 2]}
> self.client.post(url, data)
> self.assertTrue(action_mock.called)
> }}}
> on versions <2.1 it works fine. called is set to True and the call_count
> increases.
> I can't find anything in the changelogs so I assume it's a bug

New description:

after upgrading from 2.0.9 to 2.1.2 we have a problem with a test like
this:
{{{

#!python


@patch.object(SomeModelAdmin, 'action_to_mock')
def test_admin_action_is_triggered(self, action_mock):
url = reverse('admin:some_model_changelist')
data = {'action': 'action_to_mock', '_selected_action': [1, 2]}
self.client.post(url, data)
self.assertTrue(action_mock.called)
}}}
on versions <2.1 it works fine. called is set to True and the call_count
increases.
I can't find anything in the changelogs so I assume it's a bug

--

--
Ticket URL: <https://code.djangoproject.com/ticket/29885#comment:1>

Django

unread,
Oct 24, 2018, 11:28:57 AM10/24/18
to django-...@googlegroups.com
#29885: mock called never gets set after upgrade to 2.1
-----------------------------------+--------------------------------------
Reporter: Julz | Owner: nobody
Type: Bug | Status: closed

Component: Testing framework | Version: 2.1
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Changes (by Simon Charette):

* status: new => closed
* resolution: => invalid


Comment:

This was probably caused by #29419.

Which is mentioned in the release notes

https://docs.djangoproject.com/en/2.1/releases/2.1/#minor-features
https://docs.djangoproject.com/en/2.1/ref/contrib/admin/actions/#setting-
permissions-for-actions

Since you are mocking the function you must make sure it doesn't have an
`allowed_permissions` attribute

https://github.com/django/django/commit/958c7b301ead79974db8edd5b9c6588a10a28ae7
#diff-3c42de3e53aba87b32c494f995a728dfR878

A simple `delattr(action_mock, 'allowed_permissions')` before the
`self.client.post` should do.

--
Ticket URL: <https://code.djangoproject.com/ticket/29885#comment:2>

Reply all
Reply to author
Forward
0 new messages