本文整理匯總了Python中mkt.extensions.models.Extension.from_upload方法的典型用法代碼示例。如果您正苦於以下問題:Python Extension.from_upload方法的具體用法?Python Extension.from_upload怎麽用?Python Extension.from_upload使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類mkt.extensions.models.Extension
的用法示例。
在下文中一共展示了Extension.from_upload方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_upload_new
# 需要導入模塊: from mkt.extensions.models import Extension [as 別名]
# 或者: from mkt.extensions.models.Extension import from_upload [as 別名]
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: test_upload_new
# 需要導入模塊: from mkt.extensions.models import Extension [as 別名]
# 或者: from mkt.extensions.models.Extension import from_upload [as 別名]
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: test_upload_new
# 需要導入模塊: from mkt.extensions.models import Extension [as 別名]
# 或者: from mkt.extensions.models.Extension import from_upload [as 別名]
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)
示例4: create
# 需要導入模塊: from mkt.extensions.models import Extension [as 別名]
# 或者: from mkt.extensions.models.Extension import from_upload [as 別名]
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)
示例5: test_upload_existing
# 需要導入模塊: from mkt.extensions.models import Extension [as 別名]
# 或者: from mkt.extensions.models.Extension import from_upload [as 別名]
def test_upload_existing(self):
extension = self.create_extension()
upload = self.upload('extension')
with self.assertRaises(NotImplementedError):
Extension.from_upload(upload, instance=extension)
示例6: test_upload_no_name
# 需要導入模塊: from mkt.extensions.models import Extension [as 別名]
# 或者: from mkt.extensions.models.Extension import from_upload [as 別名]
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)
示例7: test_upload_no_name
# 需要導入模塊: from mkt.extensions.models import Extension [as 別名]
# 或者: from mkt.extensions.models.Extension import from_upload [as 別名]
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)