1 | |
---|
2 | """ This module contains class that tests products' validator """ |
---|
3 | |
---|
4 | |
---|
5 | import os, sys, string |
---|
6 | if __name__ == '__main__': |
---|
7 | execfile(os.path.join(sys.path[0], 'framework.py')) |
---|
8 | |
---|
9 | from commonTestingStuff import * |
---|
10 | |
---|
11 | class TestValidator(PloneTestCase.PloneTestCase): |
---|
12 | """ Class for testing products' validator """ |
---|
13 | |
---|
14 | def testNoneValue(self): |
---|
15 | """ Test validator with None value, have to return 1 """ |
---|
16 | v = validator.MapFieldValidator(self) |
---|
17 | self.failUnlessEqual(v(None), 1) |
---|
18 | |
---|
19 | def testEmptyValues(self): |
---|
20 | """ Test validator with empty latitude and longitude values """ |
---|
21 | v = validator.MapFieldValidator(self) |
---|
22 | self.failUnlessEqual(v(('', '')), " This field is required. ") |
---|
23 | |
---|
24 | def testNonTupleValue(self): |
---|
25 | """ Test validator with non tuple input value """ |
---|
26 | v = validator.MapFieldValidator(self) |
---|
27 | self.failUnlessEqual(v('Bad format'), " Validation failed. Unexpected field value. ") |
---|
28 | |
---|
29 | def testNonDecimalValues(self): |
---|
30 | """ Test validator with none decimal values """ |
---|
31 | v = validator.MapFieldValidator(self) |
---|
32 | self.failUnlessEqual(v(('bad decimal', 22.3)), " Validation failed. Coordinates must be an decimal numbers. ") |
---|
33 | |
---|
34 | def testUnBoundingLatitude(self): |
---|
35 | """ Test validator with latitude out of the bounds """ |
---|
36 | v = validator.MapFieldValidator(self) |
---|
37 | self.failUnlessEqual(v((90.5, 45)), " Validation failed. Latitude not in bounds [-90, 90]. ") |
---|
38 | |
---|
39 | def testUnBoundingLongitude(self): |
---|
40 | """ Test validator with longitude out of the bounds """ |
---|
41 | v = validator.MapFieldValidator(self) |
---|
42 | self.failUnlessEqual(v((45, -181.5)), " Validation failed. Longitude not in bounds [-180, 180]. ") |
---|
43 | |
---|
44 | def testGoodInput(self): |
---|
45 | """ Test validator good input value """ |
---|
46 | v = validator.MapFieldValidator(self) |
---|
47 | self.failUnlessEqual(v((9.8, 10.3)), 1) |
---|
48 | |
---|
49 | def test_suite(): |
---|
50 | from unittest import TestSuite, makeSuite |
---|
51 | suite = TestSuite() |
---|
52 | suite.addTest(makeSuite(TestValidator)) |
---|
53 | return suite |
---|
54 | |
---|
55 | if __name__ == '__main__': |
---|
56 | framework() |
---|