content icon indicating copy to clipboard operation
content copied to clipboard

FeatureRequest with "Django Tutorial Part 10: Testing a Django web appl…": (Please show a UnitTest for Admin-Site "action"-)

Open ifrh opened this issue 4 years ago • 2 comments

MDN URL: https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django/Testing

A great overview of testing with python django ! Thank you very much.

What information was incorrect, unhelpful, or incomplete?

No example is given for writing a unit test which should test a "action" from admin site list views.

Proposed section or headline

Testing actions from admin site list views

What did you expect to see?

It would be very great, if there is a small example how to write a unit test for actions on admin site list views.

MDN Content page report details
  • Folder: en-us/learn/server-side/django/testing
  • MDN URL: https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django/Testing
  • GitHub URL: https://github.com/mdn/content/blob/master/files/en-us/learn/server-side/django/testing/index.html
  • Last commit: https://github.com/mdn/content/commit/edbcbfa37c7807eefc5346c734cfc55d3dcc2c8a
  • Document last modified: 2021-01-25T07:12:53.000Z

ifrh avatar Jan 31 '21 16:01 ifrh

@ifrh Thanks for posting this. Yes, that could be interesting as it isn't documented properly anywhere - including in Django docs. Some resources from around the place to help with this:

  • A video: https://youtu.be/S1hPHP9wBhw
  • Checkout what Django did in their tests: https://github.com/django/django/blob/master/tests/modeladmin/tests.py
  • This might be useful too: https://stackoverflow.com/a/54667823/894359

Would you like to take it on? (I might look at this, but not necessarily any time soon!)

hamishwillee avatar Feb 01 '21 00:02 hamishwillee

@ifrh Thanks for posting this. Yes, that could be interesting as it isn't documented properly anywhere - including in Django docs. Some resources from around the place to help with this:

@hamishwillee Thanks for your pointers :)

* A video: https://youtu.be/S1hPHP9wBhw

* Checkout what Django did in their tests: https://github.com/django/django/blob/master/tests/modeladmin/tests.py

* This might be useful too: https://stackoverflow.com/a/54667823/894359  "testing admin.ModelAdmin in django"

Would you like to take it on? (I might look at this, but not necessarily any time soon!)

Just now I found https://stackoverflow.com/a/54799934 and https://stackoverflow.com/a/29027215 which are answers to "Testing custom admin actions in django".

There (https://stackoverflow.com/a/29027215) it is written: change_url = urlresolvers.reverse('admin:app_model_changelist') Just pass the parameter action with the action name. response = client.post(change_url, {'action': 'mark_as_read', ...})

And https://stackoverflow.com/a/54799934 gives a more or less complete example. But for learning in contrast to copy and modify there are to few things that are explained.

ifrh avatar Feb 01 '21 18:02 ifrh