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:
anon.py: Anonymous usersauth.py: Authenticated usersadmin.py: Admin user (superusers)staff.py: Staff users
Within each file, there are classes that test the effects of different actions on the endpoint. For example:
# drf_tester/viewsets/anon.py
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
"""
pass
A few different combinations are provided for your convenience:
- For anonymous users:
AnonNoAccessAnonReadOnlyAnonFullAccess
- For authenticated users:
AuthFullAccessAuthNoAccessAuthReadOnlyAuthOwner: only controls instances linked to user
- For admin users:
AdminNoAccessAdminReadOnlyAdminFullAccess
- For staff users:
StaffNoAccessStaffReadOnlyStaffFullAccess
Custom groups can be made mixing and matching classes according with the level of access expected by each user-type from each endpoint.