<s> from __future__ import absolute_import , unicode_literals <EOL> import datetime <EOL> from django . test import TestCase , skipIfDBFeature <EOL> from django . utils import six <EOL> from django . utils . timezone import utc <EOL> from . models import Donut , RumBaba <EOL> class DataTypesTestCase ( TestCase ) : <EOL> def test_boolean_type ( self ) : <EOL> d = Donut ( name = '<STR_LIT>' ) <EOL> self . assertFalse ( d . is_frosted ) <EOL> self . assertTrue ( d . has_sprinkles is None ) <EOL> d . has_sprinkles = True <EOL> self . assertTrue ( d . has_sprinkles ) <EOL> d . save ( ) <EOL> d2 = Donut . objects . get ( name = '<STR_LIT>' ) <EOL> self . assertFalse ( d2 . is_frosted ) <EOL> self . assertTrue ( d2 . has_sprinkles ) <EOL> def test_date_type ( self ) : <EOL> d = Donut ( name = '<STR_LIT>' ) <EOL> d . baked_date = datetime . date ( year = <NUM_LIT> , month = <NUM_LIT:6> , day = <NUM_LIT:4> ) <EOL> d . baked_time = datetime . time ( hour = <NUM_LIT:5> , minute = <NUM_LIT:30> ) <EOL> d . consumed_at = datetime . datetime ( year = <NUM_LIT> , month = <NUM_LIT:4> , day = <NUM_LIT:20> , hour = <NUM_LIT:16> , minute = <NUM_LIT> , second = <NUM_LIT> ) <EOL> d . save ( ) <EOL> d2 = Donut . objects . get ( name = '<STR_LIT>' ) <EOL> self . assertEqual ( d2 . baked_date , datetime . date ( <NUM_LIT> , <NUM_LIT:6> , <NUM_LIT:4> ) ) <EOL> self . assertEqual ( d2 . baked_time , datetime . time ( <NUM_LIT:5> , <NUM_LIT:30> ) ) <EOL> self . assertEqual ( d2 . consumed_at , datetime . datetime ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:20> , <NUM_LIT:16> , <NUM_LIT> , <NUM_LIT> ) ) <EOL> def test_time_field ( self ) : <EOL> d = Donut ( name = '<STR_LIT>' ) <EOL> d . baked_time = datetime . datetime ( year = <NUM_LIT> , month = <NUM_LIT:4> , day = <NUM_LIT:20> , hour = <NUM_LIT:16> , minute = <NUM_LIT> , second = <NUM_LIT> ) <EOL> d . save ( ) <EOL> d2 = Donut . objects . get ( name = '<STR_LIT>' ) <EOL> self . assertEqual ( d2 . baked_time , datetime . time ( <NUM_LIT:16> , <NUM_LIT> , <NUM_LIT> ) ) <EOL> def test_year_boundaries ( self ) : <EOL> """<STR_LIT>""" <EOL> d = Donut . objects . create ( name = '<STR_LIT>' , <EOL> baked_date = datetime . datetime ( year = <NUM_LIT> , month = <NUM_LIT:12> , day = <NUM_LIT> ) , <EOL> consumed_at = datetime . datetime ( year = <NUM_LIT> , month = <NUM_LIT:12> , day = <NUM_LIT> , hour = <NUM_LIT> , minute = <NUM_LIT> , second = <NUM_LIT> ) ) <EOL> d1 = Donut . objects . create ( name = '<STR_LIT>' , <EOL> baked_date = datetime . datetime ( year = <NUM_LIT> , month = <NUM_LIT:1> , day = <NUM_LIT:1> ) , <EOL> consumed_at = datetime . datetime ( year = <NUM_LIT> , month = <NUM_LIT:1> , day = <NUM_LIT:1> ) ) <EOL> self . assertEqual ( "<STR_LIT>" , <EOL> Donut . objects . filter ( baked_date__year = <NUM_LIT> ) [ <NUM_LIT:0> ] . name ) <EOL> self . assertEqual ( "<STR_LIT>" , <EOL> Donut . objects . filter ( baked_date__year = <NUM_LIT> ) [ <NUM_LIT:0> ] . name ) <EOL> d2 = Donut . objects . create ( name = '<STR_LIT>' , <EOL> consumed_at = datetime . datetime ( year = <NUM_LIT> , month = <NUM_LIT:4> , day = <NUM_LIT:20> , hour = <NUM_LIT:16> , minute = <NUM_LIT> , second = <NUM_LIT> ) ) <EOL> self . assertEqual ( [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> list ( Donut . objects . filter ( consumed_at__year = <NUM_LIT> ) . order_by ( '<STR_LIT:name>' ) . values_list ( '<STR_LIT:name>' , flat = True ) ) ) <EOL> self . assertEqual ( <NUM_LIT:0> , Donut . objects . filter ( consumed_at__year = <NUM_LIT> ) . count ( ) ) <EOL> self . assertEqual ( <NUM_LIT:0> , Donut . objects . filter ( consumed_at__year = <NUM_LIT> ) . count ( ) ) <EOL> def test_textfields_unicode ( self ) : <EOL> """<STR_LIT>""" <EOL> d = Donut . objects . create ( name = '<STR_LIT>' , review = '<STR_LIT>' ) <EOL> newd = Donut . objects . get ( id = d . id ) <EOL> self . assertIsInstance ( newd . review , six . text_type ) <EOL> @ skipIfDBFeature ( '<STR_LIT>' ) <EOL> def test_error_on_timezone ( self ) : <EOL> """<STR_LIT>""" <EOL> dt = datetime . datetime ( <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:16> , <NUM_LIT:20> , tzinfo = utc ) <EOL> d = Donut ( name = '<STR_LIT>' , consumed_at = dt ) <EOL> self . assertRaises ( ValueError , d . save ) <EOL> def test_datefield_auto_now_add ( self ) : <EOL> """<STR_LIT>""" <EOL> b = RumBaba . objects . create ( ) <EOL> self . assertIsInstance ( b . baked_timestamp , datetime . datetime ) <EOL> self . assertIsInstance ( b . baked_date , datetime . date ) and not isinstance ( b . baked_date , datetime . datetime ) </s>
