diff options
author | 2018-08-16 22:43:34 +0200 | |
---|---|---|
committer | 2018-08-16 22:43:34 +0200 | |
commit | 083dc3dbc09525ac74e7a2553079bda268ffe9ac (patch) | |
tree | 65c7117e14dcd311a988972fbf8c2adc1c2a917b /api | |
parent | Add a simple `list` / `retrieve` documentation link endpoint. (diff) |
Make test user superuser.
Diffstat (limited to 'api')
-rw-r--r-- | api/tests/base.py | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/api/tests/base.py b/api/tests/base.py index aa8157bc..06f7233c 100644 --- a/api/tests/base.py +++ b/api/tests/base.py @@ -3,9 +3,13 @@ from rest_framework.authtoken.models import Token from rest_framework.test import APIClient, APITestCase -test_user = User.objects.get(username='test') -if test_user is None: - test_user = User.objects.create_user('test', '[email protected]', 'testpass') +test_user, _created = User.objects.get_or_create( + username='test', + email='[email protected]', + password='testpass', + is_superuser=True, + is_staff=True +) class APISubdomainTestCase(APITestCase): @@ -13,6 +17,12 @@ class APISubdomainTestCase(APITestCase): Configures the test client to use the proper subdomain for requests and forces authentication for the test user. + The test user is considered staff and superuser. + If you want to test for a custom user (for example, to test model permissions), + create the user, assign the relevant permissions, and use + `self.client.force_authenticate(user=created_user)` to force authentication + through the created user. + Using this performs the following niceties for you which ease writing tests: - setting the `HTTP_HOST` request header to `api.pythondiscord.local:8000`, and - forcing authentication for the test user. |