<s> from __future__ import unicode_literals <EOL> import unittest <EOL> from nose . plugins . attrib import attr <EOL> from nose . tools import nottest <EOL> from tornado . testing import gen_test <EOL> from goblin . tests import BaseGoblinTestCase <EOL> from goblin . _compat import PY2 <EOL> from . base_tests import GraphPropertyBaseClassTestCase <EOL> from goblin . properties . properties import DateTime , GraphProperty <EOL> from goblin . properties . validators import DateTimeUTCValidator <EOL> from goblin . models import Vertex <EOL> from goblin . exceptions import ValidationError <EOL> from goblin . _compat import print_ <EOL> import datetime <EOL> from pytz import utc <EOL> @ attr ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> class DateTimePropertyTestCase ( GraphPropertyBaseClassTestCase ) : <EOL> klass = DateTime <EOL> good_cases = ( datetime . datetime . now ( tz = utc ) , None , datetime . datetime . now ( ) ) <EOL> if PY2 : <EOL> bad_cases = ( <EOL> '<STR_LIT>' , [ ] , ( ) , { } , <NUM_LIT:0> , long ( <NUM_LIT:1> ) , False , <NUM_LIT> ) <EOL> else : <EOL> bad_cases = ( '<STR_LIT>' , [ ] , ( ) , { } , <NUM_LIT:0> , False , <NUM_LIT> ) <EOL> def test_to_database_method ( self ) : <EOL> d = self . klass ( strict = False ) <EOL> self . assertIsNone ( d . to_database ( None ) ) <EOL> self . assertIsInstance ( d . to_database ( <NUM_LIT> ) , float ) <EOL> with self . assertRaises ( ValidationError ) : <EOL> d . to_database ( lambda x : x ) <EOL> def test_input_output_equality ( self ) : <EOL> d = datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , tzinfo = utc ) <EOL> prop = self . klass ( ) <EOL> result = prop . to_python ( prop . to_database ( d ) ) <EOL> print_ ( "<STR_LIT>" % ( d , result ) ) <EOL> self . assertEqual ( d , result ) <EOL> class DateTimeTestVertex ( Vertex ) : <EOL> element_type = '<STR_LIT>' <EOL> test_val = DateTime ( ) <EOL> CHOICES = ( <EOL> ( datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , tzinfo = utc ) , '<STR_LIT:A>' ) , <EOL> ( datetime . datetime ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT:1> , tzinfo = utc ) , '<STR_LIT:B>' ) <EOL> ) <EOL> class DateTimeTestChoicesVertex ( Vertex ) : <EOL> element_type = '<STR_LIT>' <EOL> test_val = DateTime ( choices = CHOICES ) <EOL> @ attr ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> class DateTimeVertexTestCase ( GraphPropertyBaseClassTestCase ) : <EOL> @ gen_test <EOL> def test_datetime_io ( self ) : <EOL> print_ ( "<STR_LIT>" ) <EOL> dt = yield DateTimeTestVertex . create ( <EOL> test_val = datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , tzinfo = utc ) ) <EOL> print_ ( "<STR_LIT>" % dt ) <EOL> dt2 = yield DateTimeTestVertex . get ( dt . _id ) <EOL> print_ ( "<STR_LIT>" % dt2 ) <EOL> self . assertEqual ( dt2 . test_val , dt . test_val ) <EOL> print_ ( "<STR_LIT>" ) <EOL> yield dt2 . delete ( ) <EOL> dt = yield DateTimeTestVertex . create ( <EOL> test_val = datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , tzinfo = utc ) ) <EOL> print_ ( "<STR_LIT>" % ( dt , dt . test_val ) ) <EOL> dt2 = yield DateTimeTestVertex . get ( dt . _id ) <EOL> print_ ( "<STR_LIT>" % dt2 ) <EOL> self . assertEqual ( <EOL> dt2 . test_val , datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , tzinfo = utc ) ) <EOL> print_ ( "<STR_LIT>" ) <EOL> yield dt2 . delete ( ) <EOL> @ attr ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> class TestVertexChoicesTestCase ( BaseGoblinTestCase ) : <EOL> @ gen_test <EOL> def test_good_choices_key_io ( self ) : <EOL> print_ ( "<STR_LIT>" ) <EOL> dt = yield DateTimeTestChoicesVertex . create ( <EOL> test_val = datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , tzinfo = utc ) ) <EOL> print_ ( "<STR_LIT>" ) <EOL> self . assertEqual ( <EOL> dt . test_val , datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , tzinfo = utc ) ) <EOL> print_ ( "<STR_LIT>" ) <EOL> yield dt . delete ( ) <EOL> @ nottest <EOL> @ gen_test <EOL> def test_good_choices_value_io ( self ) : <EOL> print_ ( "<STR_LIT>" ) <EOL> dt = yield DateTimeTestChoicesVertex . create ( test_val = '<STR_LIT:B>' ) <EOL> print_ ( "<STR_LIT>" ) <EOL> self . assertEqual ( <EOL> dt . test_val , datetime . datetime ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT:1> , tzinfo = utc ) ) <EOL> print_ ( "<STR_LIT>" ) <EOL> yield dt . delete ( ) <EOL> @ gen_test <EOL> def test_bad_choices_io ( self ) : <EOL> with self . assertRaises ( ValidationError ) : <EOL> print_ ( "<STR_LIT>" ) <EOL> dt = yield DateTimeTestChoicesVertex . create ( <EOL> test_val = datetime . datetime ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT:1> , tzinfo = utc ) ) <EOL> print_ ( "<STR_LIT>" ) <EOL> self . assertEqual ( dt . test_val , '<STR_LIT:C>' ) <EOL> print_ ( "<STR_LIT>" ) <EOL> yield dt . delete ( ) </s>
