本文整理汇总了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)