本文整理汇总了Python中mkt.api.forms.PreviewJSONForm.is_valid方法的典型用法代码示例。如果您正苦于以下问题:Python PreviewJSONForm.is_valid方法的具体用法?Python PreviewJSONForm.is_valid怎么用?Python PreviewJSONForm.is_valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mkt.api.forms.PreviewJSONForm
的用法示例。
在下文中一共展示了PreviewJSONForm.is_valid方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_bad_file
# 需要导入模块: from mkt.api.forms import PreviewJSONForm [as 别名]
# 或者: from mkt.api.forms.PreviewJSONForm import is_valid [as 别名]
def test_bad_file(self):
file_ = base64.b64encode(
open(self.packaged_app_path('mozball.zip'), 'r').read())
form = PreviewJSONForm({'file': {'data': file_, 'type': 'image/png'},
'position': 1})
assert not form.is_valid()
eq_(form.errors['file'], ['Images must be either PNG or JPG.'])
示例2: _create
# 需要导入模块: from mkt.api.forms import PreviewJSONForm [as 别名]
# 或者: from mkt.api.forms.PreviewJSONForm import is_valid [as 别名]
def _create(self, request, *args, **kwargs):
"""
Handle creation. This is directly called by the @action on AppViewSet,
allowing the URL to depend on the app id. AppViewSet passes this method
a Webapp instance in kwargs['app'] (optionally raising a 404 if the
app in the URL doesn't exist, or a 403 if the app belongs to someone
else).
Note: this method is called '_create' and not 'create' because DRF
would automatically make an 'app-preview-list' url name if this
method was called 'create', which we don't want - the app-preview-list
url name needs to be generated by AppViewSet's @action to include the
app pk.
"""
app = kwargs['app']
data_form = PreviewJSONForm(request.data)
if not data_form.is_valid():
return Response(data_form.errors, status=HTTP_400_BAD_REQUEST)
form = PreviewForm(data_form.cleaned_data)
if not form.is_valid():
return Response(data_form.errors, status=HTTP_400_BAD_REQUEST)
form.save(app)
log.info('Preview created: %s' % form.instance)
serializer = self.get_serializer(form.instance)
return Response(serializer.data, status=HTTP_201_CREATED)
示例3: obj_create
# 需要导入模块: from mkt.api.forms import PreviewJSONForm [as 别名]
# 或者: from mkt.api.forms.PreviewJSONForm import is_valid [as 别名]
def obj_create(self, bundle, request, **kwargs):
# Ensure that people don't pass strings through.
args = PreviewArgsForm(request.GET)
if not args.is_valid():
raise self.form_errors(args)
addon = self.get_object_or_404(Addon,
pk=args.cleaned_data['app'],
type=amo.ADDON_WEBAPP)
if not AppOwnerAuthorization().is_authorized(request, object=addon):
raise http_error(http.HttpForbidden,
'You are not an author of that app.')
data_form = PreviewJSONForm(bundle.data)
if not data_form.is_valid():
raise self.form_errors(data_form)
form = PreviewForm(data_form.cleaned_data)
if not form.is_valid():
raise self.form_errors(form)
form.save(addon)
bundle.obj = form.instance
log.info('Preview created: %s' % bundle.obj.pk)
return bundle
示例4: obj_create
# 需要导入模块: from mkt.api.forms import PreviewJSONForm [as 别名]
# 或者: from mkt.api.forms.PreviewJSONForm import is_valid [as 别名]
def obj_create(self, bundle, request, **kwargs):
addon = self.get_object_or_404(Webapp, pk=request.GET.get('app'))
if not AppOwnerAuthorization().is_authorized(request, object=addon):
raise ImmediateHttpResponse(response=http.HttpForbidden())
data_form = PreviewJSONForm(bundle.data)
if not data_form.is_valid():
raise self.form_errors(data_form)
form = PreviewForm(data_form.cleaned_data)
if not form.is_valid():
raise self.form_errors(form)
form.save(addon)
bundle.obj = form.instance
log.info('Preview created: %s' % bundle.obj.pk)
return bundle
示例5: test_not_file
# 需要导入模块: from mkt.api.forms import PreviewJSONForm [as 别名]
# 或者: from mkt.api.forms.PreviewJSONForm import is_valid [as 别名]
def test_not_file(self):
form = PreviewJSONForm({'position': 1})
assert not form.is_valid()
eq_(form.errors['file'], ['This field is required.'])
示例6: test_not_json
# 需要导入模块: from mkt.api.forms import PreviewJSONForm [as 别名]
# 或者: from mkt.api.forms.PreviewJSONForm import is_valid [as 别名]
def test_not_json(self):
form = PreviewJSONForm({'file': 1, 'position': 1})
assert not form.is_valid()
eq_(form.errors['file'], ['File must be a dictionary.'])
示例7: test_preview
# 需要导入模块: from mkt.api.forms import PreviewJSONForm [as 别名]
# 或者: from mkt.api.forms.PreviewJSONForm import is_valid [as 别名]
def test_preview(self):
form = PreviewJSONForm({'file': {'type': '', 'data': ''},
'position': 1})
assert not form.is_valid()
eq_(form.errors['file'], ['Images must be either PNG or JPG.'])
示例8: test_position_missing
# 需要导入模块: from mkt.api.forms import PreviewJSONForm [as 别名]
# 或者: from mkt.api.forms.PreviewJSONForm import is_valid [as 别名]
def test_position_missing(self):
form = PreviewJSONForm({'file': {'data': self.file,
'type': 'image/jpg'}})
assert not form.is_valid()
eq_(form.errors['position'], ['This field is required.'])