Exemplo n.º 1
0
    def test_date_field_type( self ):

        ft = DateFieldType()

        with self.assertRaises( FieldTypeError ):
            ft.getValue( 'invalid' )

        with self.assertRaises( FieldTypeError ):
            ft.getValue( 321312312 )

        with self.assertRaises( FieldTypeError ):
            ft.getValue( '2013-02-31' )

        self.assertEqual( ft.getValue('2013-02-03'), datetime.date( 2013, 2, 3 ) )
        self.assertEqual( ft.getValue('2013/02/03'), datetime.date( 2013, 2, 3 ) )
        self.assertEqual( ft.getValue('2013.02.03'), datetime.date( 2013, 2, 3 ) )
        self.assertEqual( ft.getValue('02/03/2013'), datetime.date( 2013, 2, 3 ) )
        self.assertEqual( ft.getValue('Dec 26, 2012 10:01:26 AM'), datetime.date( 2012, 12, 26 ) )
        self.assertEqual( ft.getValue('2012.12.26 10.01.26'), datetime.date( 2012, 12, 26 ) )
        self.assertEqual( ft.getValue( datetime.date( 2013, 2, 3 ) ), datetime.date( 2013, 2, 3 ) )
        self.assertEqual( ft.getValue( datetime.datetime.now().replace( year = 2013, month = 2, day = 3 ) ), datetime.date( 2013, 2, 3 ) )
        self.assertIsNone( ft.getValue( None ) )
Exemplo n.º 2
0
    def test_field_type_convert_to_date( self ):

        fs = DateFieldType()

        with self.assertRaises( FieldTypeError ):
            fs.getValue( BooleanFieldType().getValue( True ) )

        with self.assertRaises( FieldTypeError ):
            fs.getValue( FloatFieldType().getValue( 4.32112 ) )

        with self.assertRaises( FieldTypeError ):
            fs.getValue( IntegerFieldType().getValue( 5 ) )

        with self.assertRaises( FieldTypeError ):
            fs.getValue( StringFieldType().getValue('test') )

        with self.assertRaises( FieldTypeError ):
            fs.getValue( TextFieldType().getValue('test') )

        self.assertEqual( fs.getValue( DateFieldType().getValue( datetime.date.today() ) ), datetime.date.today() )
        self.assertEqual( fs.getValue( DateTimeFieldType().getValue( datetime.datetime.now() ) ), datetime.date.today() )
        self.assertEqual( fs.getValue( StringFieldType().getValue('2013-02-03') ), datetime.date( 2013, 2, 3 ) )
        self.assertEqual( fs.getValue( TextFieldType().getValue('2013-02-03') ), datetime.date( 2013, 2, 3 ) )
        self.assertIsNone( fs.getValue( None ) )