source: products/qPloneGoogleMaps/tags/0.1.0/tests/testValidator.py @ 1591

Last change on this file since 1591 was 1, checked in by myroslav, 15 years ago

Building directory structure

  • Property svn:eol-style set to native
File size: 2.0 KB
Line 
1
2""" This module contains class that tests products' validator """
3
4
5import os, sys, string
6if __name__ == '__main__':
7    execfile(os.path.join(sys.path[0], 'framework.py'))
8
9from commonTestingStuff import *
10
11class 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
49def test_suite():
50    from unittest import TestSuite, makeSuite
51    suite = TestSuite()
52    suite.addTest(makeSuite(TestValidator))
53    return suite
54
55if __name__ == '__main__':
56    framework()
Note: See TracBrowser for help on using the repository browser.