API: Upload new version of an extension #138
@ -8,7 +8,7 @@ from common.tests.factories.users import UserFactory
|
||||
from common.tests.factories.extensions import create_approved_version
|
||||
|
||||
from extensions.models import Version
|
||||
from tokens.models import UserToken
|
||||
from apitokens.models import UserToken
|
||||
|
||||
|
||||
TEST_FILES_DIR = Path(__file__).resolve().parent / 'files'
|
||||
@ -17,7 +17,12 @@ TEST_FILES_DIR = Path(__file__).resolve().parent / 'files'
|
||||
class VersionUploadAPITest(APITestCase):
|
||||
dfelinto marked this conversation as resolved
Outdated
|
||||
def setUp(self):
|
||||
self.user = UserFactory()
|
||||
self.token = UserToken.objects.create(user=self.user)
|
||||
self.token_key = UserToken.generate_token_key()
|
||||
self.token = UserToken.objects.create(
|
||||
user=self.user,
|
||||
token_prefix=UserToken.generate_token_prefix(self.token_key),
|
||||
token_hash=UserToken.generate_hash(self.token_key),
|
||||
)
|
||||
|
||||
self.client = APIClient()
|
||||
self.version = create_approved_version(
|
||||
@ -44,7 +49,7 @@ class VersionUploadAPITest(APITestCase):
|
||||
'release_notes': 'These are the release notes',
|
||||
},
|
||||
format='multipart',
|
||||
HTTP_AUTHORIZATION=f'Bearer {self.token.token}',
|
||||
HTTP_AUTHORIZATION=f'Bearer {self.token_key}',
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
|
||||
@ -64,7 +69,7 @@ class VersionUploadAPITest(APITestCase):
|
||||
'release_notes': 'These are the release notes',
|
||||
},
|
||||
format='multipart',
|
||||
HTTP_AUTHORIZATION=f'Bearer {self.token.token}',
|
||||
HTTP_AUTHORIZATION=f'Bearer {self.token_key}',
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
|
||||
@ -81,9 +86,8 @@ class VersionUploadAPITest(APITestCase):
|
||||
'release_notes': 'These are the release notes',
|
||||
},
|
||||
format='multipart',
|
||||
dfelinto marked this conversation as resolved
Outdated
Oleg-Komarov
commented
this assert must be failing now after the changes to the response this assert must be failing now after the changes to the response
|
||||
HTTP_AUTHORIZATION=f'Bearer {self.token.token}',
|
||||
HTTP_AUTHORIZATION=f'Bearer {self.token_key}',
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||
self.assertIn('version_id', response.data)
|
||||
self.assertEqual(Version.objects.filter(extension=self.extension).count(), 2)
|
||||
|
Loading…
Reference in New Issue
Block a user
should include a test for a non-authenticated request
returning 403 is ok: maybe not 100% correct from a purist perspective, but it serves the purpose