API: Upload new version of an extension #138
@ -26,16 +26,19 @@ class VersionUploadAPITest(APITestCase):
|
||||
file__user=self.user,
|
||||
)
|
||||
self.extension = self.version.extension
|
||||
self.upload_url = reverse('extensions:upload-extension-version')
|
||||
self.file_path = TEST_FILES_DIR / "amaranth-1.0.8.zip"
|
||||
|
||||
@staticmethod
|
||||
def _get_upload_url(extension_id):
|
||||
upload_url = reverse('extensions:upload-extension-version', args=(extension_id,))
|
||||
return upload_url
|
||||
|
||||
def test_version_upload_unauthenticated(self):
|
||||
with open(self.file_path, 'rb') as version_file:
|
||||
response = self.client.post(
|
||||
self.upload_url,
|
||||
self._get_upload_url(self.extension.extension_id),
|
||||
{
|
||||
'version_file': version_file,
|
||||
'extension_id': self.extension.extension_id,
|
||||
'release_notes': 'These are the release notes',
|
||||
},
|
||||
format='multipart',
|
||||
@ -51,10 +54,9 @@ class VersionUploadAPITest(APITestCase):
|
||||
|
||||
with open(self.file_path, 'rb') as version_file:
|
||||
response = self.client.post(
|
||||
self.upload_url,
|
||||
self._get_upload_url(other_extension.extension_id),
|
||||
{
|
||||
'version_file': version_file,
|
||||
'extension_id': other_extension.extension_id,
|
||||
'release_notes': 'These are the release notes',
|
||||
},
|
||||
format='multipart',
|
||||
@ -71,10 +73,9 @@ class VersionUploadAPITest(APITestCase):
|
||||
extension_name = 'extension_do_not_exist'
|
||||
with open(self.file_path, 'rb') as version_file:
|
||||
response = self.client.post(
|
||||
self.upload_url,
|
||||
self._get_upload_url(extension_name),
|
||||
{
|
||||
'version_file': version_file,
|
||||
'extension_id': extension_name,
|
||||
'release_notes': 'These are the release notes',
|
||||
},
|
||||
format='multipart',
|
||||
@ -88,10 +89,9 @@ class VersionUploadAPITest(APITestCase):
|
||||
self.assertEqual(Version.objects.filter(extension=self.extension).count(), 1)
|
||||
with open(self.file_path, 'rb') as version_file:
|
||||
response = self.client.post(
|
||||
self.upload_url,
|
||||
self._get_upload_url(self.extension.extension_id),
|
||||
{
|
||||
'version_file': version_file,
|
||||
'extension_id': self.extension.extension_id,
|
||||
'release_notes': 'These are the release notes',
|
||||
},
|
||||
format='multipart',
|
||||
|
@ -17,7 +17,7 @@ urlpatterns = [
|
||||
# API
|
||||
path('api/v1/extensions/', api.ExtensionsAPIView.as_view(), name='api'),
|
||||
path(
|
||||
'api/v1/version-upload/',
|
||||
'api/v1/extensions/<str:extension_id>/versions/new/',
|
||||
Oleg-Komarov marked this conversation as resolved
Outdated
|
||||
api.UploadExtensionVersionView.as_view(),
|
||||
name='upload-extension-version',
|
||||
),
|
||||
|
@ -158,7 +158,6 @@ class ExtensionsAPIView(APIView):
|
||||
|
||||
|
||||
class ExtensionVersionSerializer(serializers.Serializer):
|
||||
extension_id = serializers.CharField(max_length=255)
|
||||
version_file = serializers.FileField()
|
||||
release_notes = serializers.CharField(max_length=1024, required=False)
|
||||
|
||||
@ -170,13 +169,12 @@ class UploadExtensionVersionView(APIView):
|
||||
request=ExtensionVersionSerializer,
|
||||
responses={201: 'Extension version uploaded successfully!'},
|
||||
)
|
||||
def post(self, request, *args, **kwargs):
|
||||
def post(self, request, extension_id, *args, **kwargs):
|
||||
serializer = ExtensionVersionSerializer(data=request.data)
|
||||
if not serializer.is_valid():
|
||||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
user = request.user
|
||||
extension_id = serializer.validated_data['extension_id']
|
||||
version_file = serializer.validated_data['version_file']
|
||||
release_notes = serializer.validated_data.get('release_notes', '')
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user
sorry, haven't thought of this before, let's restructure the parameters: make them more in line with REST conventions, and get a nice bonus for logs transparency
the url becomes
api/v1/extensions/<extension_id>/versions/new/
, and theextension_id
in the body is not needed