Viewset Tests

All the classes to assist with the development of tests for ViewSets are located under drf_tester.viewsets, and separated by user type:

  • Anonymous users

  • Authenticated users

  • Admin user (superusers)

  • Staff users

Within each file, there are classes that test the effects of different actions on the endpoint. For example:

# drf_tester/viewsets/

class NoCreate(BaseDrfTest):
    def test_anon_user_cannot_create_instance(self):
        """Anonymous user cannot create new instance"""

These single-action classes are grouped in bigger classes meant to be inherited by the final test cases. For example:

class AnonReadOnly(CanList, CanRetrieve, NoCreate, NoUpdate, NoDestroy):
    Anonymous user has only read access to endopint


A few different combinations are provided for your convenience:

  • For anonymous users:
    • AnonNoAccess

    • AnonReadOnly

    • AnonFullAccess

  • For authenticated users:
    • AuthFullAccess

    • AuthNoAccess

    • AuthReadOnly

    • AuthOwner: only controls instances linked to user

  • For admin users:
    • AdminNoAccess

    • AdminReadOnly

    • AdminFullAccess

  • For staff users:
    • StaffNoAccess

    • StaffReadOnly

    • StaffFullAccess

Custom groups can be made mixing and matching classes according with the level of access expected by each user-type from each endpoint.