5
5
from django .urls import reverse
6
6
from django .test import TestCase , override_settings
7
7
8
+ from rest_framework .authtoken .models import Token
8
9
from rest_framework .test import APITestCase
9
10
10
11
from .base import BaseDownloadTests , DownloadMixin
@@ -90,7 +91,7 @@ def test_without_latest_python3_release(self):
90
91
self .assertEqual (len (response .context ['python_files' ]), 3 )
91
92
92
93
93
- class BaseDownloadApiViewsTest (BaseAPITestCase ):
94
+ class BaseDownloadApiViewsTest (BaseDownloadTests , BaseAPITestCase ):
94
95
# This API used by add-to-pydotorg.py in python/release-tools.
95
96
app_label = 'downloads'
96
97
@@ -101,12 +102,8 @@ def setUp(self):
101
102
password = 'passworduser' ,
102
103
is_staff = True ,
103
104
)
104
- self .staff_key = self .staff_user .api_key .key
105
- self .token_header = 'ApiKey'
106
- self .Authorization = '{} {}:{}' .format (
107
- self .token_header , self .staff_user .username , self .staff_key ,
108
- )
109
- self .Authorization_invalid = '%s invalid:token' % self .token_header
105
+ self .Authorization = f'Token { self .staff_user .api_v2_token } '
106
+ self .Authorization_invalid = 'Token invalid-token'
110
107
111
108
def get_json (self , response ):
112
109
json_response = response .json ()
@@ -438,6 +435,15 @@ def test_filter_release_file(self):
438
435
class DownloadApiV1ViewsTest (BaseDownloadApiViewsTest , BaseDownloadTests ):
439
436
api_version = 'v1'
440
437
438
+ def setUp (self ):
439
+ super ().setUp ()
440
+ self .staff_key = self .staff_user .api_key .key
441
+ self .token_header = 'ApiKey'
442
+ self .Authorization = '{} {}:{}' .format (
443
+ self .token_header , self .staff_user .username , self .staff_key ,
444
+ )
445
+ self .Authorization_invalid = '%s invalid:token' % self .token_header
446
+
441
447
442
448
class DownloadApiV2ViewsTest (BaseDownloadApiViewsTest , BaseDownloadTests , APITestCase ):
443
449
api_version = 'v2'
0 commit comments