validatestest.py :  » Web-Server » SkunkWEB » skunkweb-3.4.4 » test » formlib » unittests » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Web Server » SkunkWEB 
SkunkWEB » skunkweb 3.4.4 » test » formlib » unittests » validatestest.py
import unittest
from formlib import *

class IntegerFieldUnitTest(unittest.TestCase):
    def __init__(self, aStr):
        self.intField = IntegerField('intTest', 'int field for testing')
        unittest.TestCase.__init__(self, aStr)
        

    def testValidateSucceeds(self):
        # there should be no error messages for valid int field values
        self.intField.value='123'
        retVal = self.intField.validate()
        assert len(retVal) < 1

        self.intField.value='0'
        retVal = self.intField.validate()
        assert len(retVal) < 1

        self.intField.value='-392874937'
        retVal = self.intField.validate()
        assert len(retVal) < 1

        self.intField.value='+123456789'
        retVal = self.intField.validate()
        assert len(retVal) < 1
        

    def testValidateFails(self):
        # errors must be generated for invalid integer literals
        self.intField.value='lsjkfds'
        retVal = self.intField.validate()
        assert len(retVal) > 0

        self.intField.value="123kl"
        retVal = self.intField.validate()
        assert len(retVal) > 0

        self.intField.value='-JK45'
        retVal = self.intField.validate()
        assert len(retVal) > 0 
        

class DoubleFieldUnitTest(unittest.TestCase):
    def __init__(self, aStr):
        self.dblField = DoubleField('doubleTest', 'double field for testing')
        unittest.TestCase.__init__(self, aStr)

    def testValidateSucceeds(self):
        # there should be no error messages for valid dbl field values
        self.dblField.value='123.1'
        retVal = self.dblField.validate()
        assert len(retVal) < 1

        self.dblField.value='0.0'
        retVal = self.dblField.validate()
        assert len(retVal) < 1

        self.dblField.value='-392874937'
        retVal = self.dblField.validate()
        assert len(retVal) < 1

        self.dblField.value='+123456789.45'
        retVal = self.dblField.validate()
        assert len(retVal) < 1

        self.dblField.value='-123456789.45'
        retVal = self.dblField.validate()
        assert len(retVal) < 1
        

    def testValidateFails(self):
        # errors must be generated for invalid double literals
        self.dblField.value='lsjkfds'
        retVal = self.dblField.validate()
        assert len(retVal) > 0

        self.dblField.value="123kl.05"
        retVal = self.dblField.validate()
        assert len(retVal) > 0

        self.dblField.value='-JK45'
        retVal = self.dblField.validate()
        assert len(retVal) > 0

        self.dblField.value='0.as89'
        retVal = self.dblField.validate()
        assert len(retVal) > 0

        
class DateFieldUnitTest(unittest.TestCase):
    def __init__(self, aStr):
        self.dfltDtField = DateField('defaultDateTest', 'date field for testing using default date format')
        self.cstmDtField = DateField('customDateTest', 'date field for testing using custom date format', formatString='%Y%d%m' )
        # default field uses %m/%d/%Y format
        self.defaultTests = ['11/02/2002','01/01/1750','01/01/0001','12/30/2041','01/01/1970','02/02/1901','04/19/2011','06/09/1999']
        # custom field uses %Y%d%m format
        self.customTests = ['19993002','20011303','20000101','00010101','19700101','23003001','19000205','04951010','05270101','11272304']
        self.defaultFails = ['bogus', '19993002', '1900/01/01', '12ad/12/12', '0']
        self.customFails = ['bogus', '993002', '1900/01/01', '12/12/12', '0']
        unittest.TestCase.__init__(self, aStr)


    def testValidateSucceeds(self):
        for aTst in self.defaultTests:
            self.dfltDtField.value = aTst
            retVal = self.dfltDtField.validate()
            assert len(retVal) < 1

        for aTst in self.customTests:
            self.cstmDtField.value = aTst
            retVal = self.cstmDtField.validate()
            assert len(retVal) < 1
                

    def testValidateFails(self):
        for aTst in self.defaultFails:
            self.dfltDtField.value = aTst
            retVal = self.dfltDtField.validate()
            assert len(retVal) > 0

        for aTst in self.customFails:
            self.cstmDtField.value = aTst
            retVal = self.cstmDtField.validate()
            assert len(retVal) > 0

    

def suite():
    suite = unittest.TestSuite()
    suite.addTest(IntegerFieldUnitTest('testValidateSucceeds'))
    suite.addTest(IntegerFieldUnitTest('testValidateFails'))
    suite.addTest(DoubleFieldUnitTest('testValidateSucceeds'))
    suite.addTest(DoubleFieldUnitTest('testValidateFails'))    
    suite.addTest(DateFieldUnitTest('testValidateSucceeds'))
    suite.addTest(DateFieldUnitTest('testValidateFails'))    
    return suite

if __name__ == "__main__":
    unittest.main()
                  
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.