2016-09-18 02:29:00 +03:00
|
|
|
from django.core.exceptions import ValidationError
|
2022-11-14 13:56:18 +03:00
|
|
|
from pytest import raises
|
2016-09-18 02:29:00 +03:00
|
|
|
|
2018-07-20 02:51:33 +03:00
|
|
|
from ..forms import GlobalIDFormField, GlobalIDMultipleChoiceField
|
2016-09-18 02:29:00 +03:00
|
|
|
|
|
|
|
|
|
|
|
# 'TXlUeXBlOmFiYw==' -> 'MyType', 'abc'
|
|
|
|
|
|
|
|
|
|
|
|
def test_global_id_valid():
|
|
|
|
field = GlobalIDFormField()
|
2018-07-20 02:51:33 +03:00
|
|
|
field.clean("TXlUeXBlOmFiYw==")
|
2016-09-18 02:29:00 +03:00
|
|
|
|
|
|
|
|
|
|
|
def test_global_id_invalid():
|
|
|
|
field = GlobalIDFormField()
|
|
|
|
with raises(ValidationError):
|
2018-07-20 02:51:33 +03:00
|
|
|
field.clean("badvalue")
|
2016-09-18 02:29:00 +03:00
|
|
|
|
|
|
|
|
2017-12-12 05:23:00 +03:00
|
|
|
def test_global_id_multiple_valid():
|
|
|
|
field = GlobalIDMultipleChoiceField()
|
2018-07-20 02:51:33 +03:00
|
|
|
field.clean(["TXlUeXBlOmFiYw==", "TXlUeXBlOmFiYw=="])
|
2017-12-12 05:23:00 +03:00
|
|
|
|
|
|
|
|
|
|
|
def test_global_id_multiple_invalid():
|
|
|
|
field = GlobalIDMultipleChoiceField()
|
|
|
|
with raises(ValidationError):
|
2018-07-20 02:51:33 +03:00
|
|
|
field.clean(["badvalue", "another bad avue"])
|
2017-12-12 05:23:00 +03:00
|
|
|
|
|
|
|
|
2016-09-18 02:29:00 +03:00
|
|
|
def test_global_id_none():
|
|
|
|
field = GlobalIDFormField()
|
|
|
|
with raises(ValidationError):
|
|
|
|
field.clean(None)
|
|
|
|
|
|
|
|
|
|
|
|
def test_global_id_none_optional():
|
|
|
|
field = GlobalIDFormField(required=False)
|
|
|
|
field.clean(None)
|