11import datetime
2+ from datetime import timedelta
23
34import pytest
4- from datetime import timedelta
5+
56from appkernel import ValidationException
67from tests .utils import ExampleClass , Project , Task , Payment , PaymentMethod
78
@@ -22,6 +23,52 @@ def test_regexp_validation():
2223 test_model_correct_format .finalise_and_validate ()
2324
2425
26+ def test_email_validator ():
27+ example = ExampleClass (just_numbers = '1234' )
28+ example .finalise_and_validate ()
29+
30+ with pytest .raises (ValidationException ):
31+ example .email = 'some_mail'
32+ example .finalise_and_validate ()
33+
34+ example .email = 'acme@coppa.com'
35+ example .finalise_and_validate ()
36+
37+
38+ def test_min_max ():
39+ example = ExampleClass (just_numbers = '1234' )
40+ example .finalise_and_validate ()
41+
42+ with pytest .raises (ValidationException ):
43+ example .distance = 1
44+ example .finalise_and_validate ()
45+
46+ with pytest .raises (ValidationException ):
47+ example .distance = 16
48+ example .finalise_and_validate ()
49+
50+ example .distance = 10
51+ example .finalise_and_validate ()
52+
53+
54+ def test_unique ():
55+ example = ExampleClass (just_numbers = '1234' )
56+ example .finalise_and_validate ()
57+ with pytest .raises (ValidationException ):
58+ example .numbers = [1 , 2 , 1 ]
59+ example .finalise_and_validate ()
60+
61+ with pytest .raises (ValidationException ):
62+ example .numbers = ['a' , 'b' , 'a' ]
63+ example .finalise_and_validate ()
64+
65+ example .numbers = ['a' , 'b' , 'c' ]
66+ example .finalise_and_validate ()
67+
68+ example .numbers = [1 , 2 , 3 ]
69+ example .finalise_and_validate ()
70+
71+
2572def test_not_empty_validation ():
2673 project = Project ().update (name = '' )
2774 with pytest .raises (ValidationException ):
@@ -39,9 +86,13 @@ def test_past_validation():
3986 project .tasks [0 ].update (closed_date = (datetime .datetime .now () - timedelta (days = 1 )))
4087 print (('\n \n > one day in the past \n {}' .format (project )))
4188 project .finalise_and_validate ()
89+
4290 with pytest .raises (ValidationException ):
4391 project .tasks [0 ].update (closed_date = (datetime .datetime .now () + timedelta (days = 1 )))
44- print (('\n \n > one day in the in the future \n {}' .format (project )))
92+ project .finalise_and_validate ()
93+
94+ with pytest .raises (ValidationException ):
95+ project .tasks [0 ].update (closed_date = 'past' )
4596 project .finalise_and_validate ()
4697
4798
@@ -56,10 +107,14 @@ def test_future_validation():
56107 print (('\n \n > one day in the in the future \n {}' .format (test_model )))
57108 test_model .finalise_and_validate ()
58109
110+ with pytest .raises (ValidationException ):
111+ test_model .future_field = 'future'
112+ test_model .finalise_and_validate ()
113+
59114
60115def test_validate_method ():
61116 payment = Payment (method = PaymentMethod .MASTER , customer_id = '123456' , customer_secret = '123' )
62117 with pytest .raises (ValidationException ):
63118 payment .finalise_and_validate ()
64- payment .customer_id = '1234567890123456'
119+ payment .customer_id = '1234567890123456'
65120 payment .finalise_and_validate ()
0 commit comments