Monday, May 28, 2018

Definitive (or any) guide to testing Django admin actions with intermediate pages?

Looking for some help with a persistent problem.

While there are many examples scattered across the internet about how to incorporate intermediate pages (typically with a form involved) into a custom Django admin action, I have not been able to find a complete and definitive guide to how to create unit tests for such functions.

If anyone has, actually, created such a unit test, I'd appreciate your insight. I am not looking for "best practice" but something pragmatic that "Just Works".

I imagine the unit test looks something like this:

def test_custom_admin_action():
    # set up scaffolding - client? request? login a user?
    # set up the queryset data
    # set up the form data
    # call the action, passing in (?) the queryset and the form data
    # validate the response*
   
* in most cases, for the actions I write**, the action returns back to the original Django list page from where it was called, typically with a message indicating the success (or otherwise) of the action.  So validation would ideally need to check both the system changes (e.g. records altered or new records created) and the response to the user, which was made via the Django messages framework.
** for purpose of this question, its safe to assume that all logic for the action is included in it as a single whole.

Any help with this is appreciated - its the one part of testing that just eludes me.

Derek
   

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAF1Wu3MiLaU8TDW7dStQ4dDCZTW69EiXxRho_1gmJLAmcE0X0w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment