本文整理汇总了Python中virtualfolder.models.VirtualFolder.clean_fields方法的典型用法代码示例。如果您正苦于以下问题:Python VirtualFolder.clean_fields方法的具体用法?Python VirtualFolder.clean_fields怎么用?Python VirtualFolder.clean_fields使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类virtualfolder.models.VirtualFolder
的用法示例。
在下文中一共展示了VirtualFolder.clean_fields方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_vfolder_priority_not_greater_than_zero
# 需要导入模块: from virtualfolder.models import VirtualFolder [as 别名]
# 或者: from virtualfolder.models.VirtualFolder import clean_fields [as 别名]
def test_vfolder_priority_not_greater_than_zero():
"""Tests that the creation of a virtual folder fails if the provided
priority is not greater than zero.
"""
from django.core.exceptions import ValidationError
from virtualfolder.models import VirtualFolder
# Test priority less than zero.
vfolder_item = {
'name': "whatever",
'location': "/af/vfolder_test/",
'priority': -3,
'is_public': True,
'filter_rules': "browser/defines.po",
}
vfolder = VirtualFolder(**vfolder_item)
with pytest.raises(ValidationError) as excinfo:
vfolder.clean_fields()
assert u'Priority must be greater than zero.' in str(excinfo.value)
# Test zero priority.
vfolder_item['priority'] = 0
vfolder = VirtualFolder(**vfolder_item)
with pytest.raises(ValidationError) as excinfo:
vfolder.clean_fields()
assert u'Priority must be greater than zero.' in str(excinfo.value)
示例2: test_vfolder_location_starts_with_projects
# 需要导入模块: from virtualfolder.models import VirtualFolder [as 别名]
# 或者: from virtualfolder.models.VirtualFolder import clean_fields [as 别名]
def test_vfolder_location_starts_with_projects():
"""Tests that the creation of a virtual folder fails if it uses a location
that starts with /projects/.
"""
from django.core.exceptions import ValidationError
from virtualfolder.models import VirtualFolder
# Test just /projects/ location.
vfolder_item = {
'name': "whatever",
'location': "/projects/",
'priority': 4,
'is_public': True,
'filter_rules': "browser/defines.po",
}
vfolder = VirtualFolder(**vfolder_item)
with pytest.raises(ValidationError) as excinfo:
vfolder.clean_fields()
assert (u'Locations starting with "/projects/" are not allowed. Use '
u'"/{LANG}/" instead.') in str(excinfo.value)
# Test /projects/tutorial/ location.
vfolder_item['location'] = "/projects/tutorial/"
vfolder = VirtualFolder(**vfolder_item)
with pytest.raises(ValidationError) as excinfo:
vfolder.clean_fields()
assert (u'Locations starting with "/projects/" are not allowed. Use '
u'"/{LANG}/" instead.') in str(excinfo.value)
示例3: test_vfolder_with_no_filter_rules
# 需要导入模块: from virtualfolder.models import VirtualFolder [as 别名]
# 或者: from virtualfolder.models.VirtualFolder import clean_fields [as 别名]
def test_vfolder_with_no_filter_rules():
"""Tests that the creation of a virtual folder fails if it doesn't have any
filter rules.
"""
vfolder_item = {
'name': "whatever",
'location': "/af/vfolder_test/",
'priority': 4,
'is_public': True,
'filter_rules': "",
}
vfolder = VirtualFolder(**vfolder_item)
with pytest.raises(ValidationError) as excinfo:
vfolder.clean_fields()
assert u'Some filtering rule must be specified.' in str(excinfo.value)
示例4: test_vfolder_root_location
# 需要导入模块: from virtualfolder.models import VirtualFolder [as 别名]
# 或者: from virtualfolder.models.VirtualFolder import clean_fields [as 别名]
def test_vfolder_root_location():
"""Tests that the creation of a virtual folder fails if it uses location /
instead of /{LANG}/{PROJ}/.
"""
vfolder_item = {
'name': "whatever",
'location': "/",
'priority': 4,
'is_public': True,
'filter_rules': "browser/defines.po",
}
vfolder = VirtualFolder(**vfolder_item)
with pytest.raises(ValidationError) as excinfo:
vfolder.clean_fields()
assert (u'The "/" location is not allowed. Use "/{LANG}/{PROJ}/" instead.'
in str(excinfo.value))