示例#1
0
 def test_upload_new(self):
     eq_(Extension.objects.count(), 0)
     upload = self.upload('extension')
     extension = Extension.from_upload(upload, user=self.user)
     eq_(extension.version, '0.1')
     eq_(list(extension.authors.all()), [self.user])
     eq_(extension.name, u'My Lîttle Extension')
     eq_(extension.default_language, 'en-GB')
     eq_(extension.slug, u'my-lîttle-extension')
     eq_(extension.filename, 'extension-%s.zip' % extension.version)
     ok_(extension.filename in extension.file_path)
     ok_(private_storage.exists(extension.file_path))
     eq_(extension.manifest, self.expected_manifest)
     eq_(Extension.objects.count(), 1)
示例#2
0
 def test_upload_new(self):
     eq_(Extension.objects.count(), 0)
     upload = self.upload('extension')
     extension = Extension.from_upload(upload)
     eq_(extension.version, '0.1')
     eq_(extension.name, u'My Lîttle Extension')
     eq_(extension.default_language, 'en-GB')
     eq_(extension.slug, u'my-lîttle-extension')
     eq_(extension.filename, 'extension-%s.zip' % extension.version)
     ok_(extension.filename in extension.file_path)
     ok_(extension.file_path.startswith(extension.path_prefix))
     ok_(private_storage.exists(extension.file_path))
     eq_(extension.manifest, self.expected_manifest)
     eq_(Extension.objects.count(), 1)
示例#3
0
 def test_upload_new(self):
     eq_(Extension.objects.count(), 0)
     upload = self.upload('extension')
     extension = Extension.from_upload(upload)
     eq_(extension.version, '0.1')
     eq_(extension.name, u'My Lîttle Extension')
     eq_(extension.default_language, 'en-GB')
     eq_(extension.slug, u'my-lîttle-extension')
     eq_(extension.filename, 'extension-%s.zip' % extension.version)
     ok_(extension.filename in extension.file_path)
     ok_(extension.file_path.startswith(extension.path_prefix))
     ok_(private_storage.exists(extension.file_path))
     eq_(extension.manifest, self.expected_manifest)
     eq_(Extension.objects.count(), 1)
示例#4
0
    def test_upload_new(self):
        eq_(Extension.objects.count(), 0)
        upload = self.upload('extension')
        extension = Extension.from_upload(upload, user=self.user)
        ok_(extension.pk)
        eq_(extension.latest_version, ExtensionVersion.objects.latest('pk'))
        eq_(Extension.objects.count(), 1)
        eq_(ExtensionVersion.objects.count(), 1)

        eq_(list(extension.authors.all()), [self.user])
        eq_(extension.name, u'My Lîttle Extension')
        eq_(extension.default_language, 'en-GB')
        eq_(extension.description, u'A Dummÿ Extension')
        eq_(extension.slug, u'my-lîttle-extension')
        eq_(extension.status, STATUS_PENDING)
        ok_(extension.uuid)

        version = extension.latest_version
        eq_(version.version, '0.1')
        eq_(version.default_language, 'en-GB')
        eq_(version.filename, 'extension-%s.zip' % version.version)
        ok_(version.filename in version.file_path)
        ok_(private_storage.exists(version.file_path))
        eq_(version.manifest, self.expected_manifest)
示例#5
0
    def create(self, request, *args, **kwargs):
        upload_pk = request.DATA.get('upload', '')
        if not upload_pk:
            raise exceptions.ParseError(_('No upload identifier specified.'))

        if not request.user.is_authenticated():
            raise exceptions.PermissionDenied(
                _('You need to be authenticated to perform this action.'))

        try:
            upload = FileUpload.objects.get(pk=upload_pk, user=request.user)
        except FileUpload.DoesNotExist:
            raise Http404(_('No such upload.'))
        if not upload.valid:
            raise exceptions.ParseError(
                _('The specified upload has not passed validation.'))

        try:
            obj = Extension.from_upload(upload, user=request.user)
        except ValidationError as e:
            raise exceptions.ParseError(unicode(e))
        log.info('Extension created: %s' % obj.pk)
        serializer = self.get_serializer(obj)
        return Response(serializer.data, status=status.HTTP_201_CREATED)
示例#6
0
 def test_upload_existing(self):
     extension = self.create_extension()
     upload = self.upload('extension')
     with self.assertRaises(NotImplementedError):
         Extension.from_upload(upload, instance=extension)
示例#7
0
 def test_upload_no_name(self, manifest_mock):
     manifest_mock.__get__ = mock.Mock(return_value={'version': '0.1'})
     upload = self.upload('extension')
     with self.assertRaises(ValidationError):
         Extension.from_upload(upload)
示例#8
0
 def test_upload_existing(self):
     extension = self.create_extension()
     upload = self.upload('extension')
     with self.assertRaises(NotImplementedError):
         Extension.from_upload(upload, instance=extension)
示例#9
0
 def test_upload_no_name(self, manifest_mock):
     manifest_mock.__get__ = mock.Mock(return_value={'version': '0.1'})
     upload = self.upload('extension')
     with self.assertRaises(ValidationError):
         Extension.from_upload(upload)
示例#10
0
 def test_upload_no_name(self, validate_mock):
     validate_mock.return_value = {'version': '0.1'}
     upload = self.upload('extension')
     with self.assertRaises(ParseError):
         Extension.from_upload(upload, user=self.user)