diff options
| author | 2018-08-16 22:43:34 +0200 | |
|---|---|---|
| committer | 2018-08-22 20:02:23 +0200 | |
| commit | 922498114a60016a29bdf457e4725968195fe196 (patch) | |
| tree | 087ce3591839e17806519f18d57c349929ded1d9 /api | |
| parent | Add a `HealthcheckView`. (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. | 
