<s> import datetime <EOL> import iso8601 <EOL> from oslo_versionedobjects import exception as ovo_exc <EOL> import six <EOL> from nova . network import model as network_model <EOL> from nova . objects import fields <EOL> from nova import signature_utils <EOL> from nova import test <EOL> from nova import utils <EOL> class FakeFieldType ( fields . FieldType ) : <EOL> def coerce ( self , obj , attr , value ) : <EOL> return '<STR_LIT>' % value <EOL> def to_primitive ( self , obj , attr , value ) : <EOL> return '<STR_LIT>' % value <EOL> def from_primitive ( self , obj , attr , value ) : <EOL> return value [ <NUM_LIT:1> : - <NUM_LIT:1> ] <EOL> class FakeEnum ( fields . Enum ) : <EOL> FROG = "<STR_LIT>" <EOL> PLATYPUS = "<STR_LIT>" <EOL> ALLIGATOR = "<STR_LIT>" <EOL> ALL = ( FROG , PLATYPUS , ALLIGATOR ) <EOL> def __init__ ( self , ** kwargs ) : <EOL> super ( FakeEnum , self ) . __init__ ( valid_values = FakeEnum . ALL , <EOL> ** kwargs ) <EOL> class FakeEnumAlt ( fields . Enum ) : <EOL> FROG = "<STR_LIT>" <EOL> PLATYPUS = "<STR_LIT>" <EOL> AARDVARK = "<STR_LIT>" <EOL> ALL = ( FROG , PLATYPUS , AARDVARK ) <EOL> def __init__ ( self , ** kwargs ) : <EOL> super ( FakeEnumAlt , self ) . __init__ ( valid_values = FakeEnumAlt . ALL , <EOL> ** kwargs ) <EOL> class FakeEnumField ( fields . BaseEnumField ) : <EOL> AUTO_TYPE = FakeEnum ( ) <EOL> class FakeEnumAltField ( fields . BaseEnumField ) : <EOL> AUTO_TYPE = FakeEnumAlt ( ) <EOL> class TestField ( test . NoDBTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestField , self ) . setUp ( ) <EOL> self . field = fields . Field ( FakeFieldType ( ) ) <EOL> self . coerce_good_values = [ ( '<STR_LIT:foo>' , '<STR_LIT>' ) ] <EOL> self . coerce_bad_values = [ ] <EOL> self . to_primitive_values = [ ( '<STR_LIT:foo>' , '<STR_LIT>' ) ] <EOL> self . from_primitive_values = [ ( '<STR_LIT>' , '<STR_LIT:foo>' ) ] <EOL> def test_coerce_good_values ( self ) : <EOL> for in_val , out_val in self . coerce_good_values : <EOL> self . assertEqual ( out_val , self . field . coerce ( '<STR_LIT>' , '<STR_LIT>' , in_val ) ) <EOL> def test_coerce_bad_values ( self ) : <EOL> for in_val in self . coerce_bad_values : <EOL> self . assertRaises ( ( TypeError , ValueError ) , <EOL> self . field . coerce , '<STR_LIT>' , '<STR_LIT>' , in_val ) <EOL> def test_to_primitive ( self ) : <EOL> for in_val , prim_val in self . to_primitive_values : <EOL> self . assertEqual ( prim_val , self . field . to_primitive ( '<STR_LIT>' , '<STR_LIT>' , <EOL> in_val ) ) <EOL> def test_from_primitive ( self ) : <EOL> class ObjectLikeThing ( object ) : <EOL> _context = '<STR_LIT>' <EOL> for prim_val , out_val in self . from_primitive_values : <EOL> self . assertEqual ( out_val , self . field . from_primitive ( <EOL> ObjectLikeThing , '<STR_LIT>' , prim_val ) ) <EOL> def test_stringify ( self ) : <EOL> self . assertEqual ( '<STR_LIT>' , self . field . stringify ( <NUM_LIT> ) ) <EOL> class TestString ( TestField ) : <EOL> def setUp ( self ) : <EOL> super ( TestString , self ) . setUp ( ) <EOL> self . field = fields . StringField ( ) <EOL> self . coerce_good_values = [ ( '<STR_LIT:foo>' , '<STR_LIT:foo>' ) , ( <NUM_LIT:1> , '<STR_LIT:1>' ) , ( True , '<STR_LIT:True>' ) ] <EOL> if six . PY2 : <EOL> self . coerce_good_values . append ( ( int ( <NUM_LIT:1> ) , '<STR_LIT:1>' ) ) <EOL> self . coerce_bad_values = [ None ] <EOL> self . to_primitive_values = self . coerce_good_values [ <NUM_LIT:0> : <NUM_LIT:1> ] <EOL> self . from_primitive_values = self . coerce_good_values [ <NUM_LIT:0> : <NUM_LIT:1> ] <EOL> def test_stringify ( self ) : <EOL> self . assertEqual ( "<STR_LIT>" , self . field . stringify ( <NUM_LIT> ) ) <EOL> class TestBaseEnum ( TestField ) : <EOL> def setUp ( self ) : <EOL> super ( TestBaseEnum , self ) . setUp ( ) <EOL> self . field = FakeEnumField ( ) <EOL> self . coerce_good_values = [ ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> self . coerce_bad_values = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . to_primitive_values = self . coerce_good_values [ <NUM_LIT:0> : <NUM_LIT:1> ] <EOL> self . from_primitive_values = self . coerce_good_values [ <NUM_LIT:0> : <NUM_LIT:1> ] <EOL> def test_stringify ( self ) : <EOL> self . assertEqual ( "<STR_LIT>" , self . field . stringify ( '<STR_LIT>' ) ) <EOL> def test_stringify_invalid ( self ) : <EOL> self . assertRaises ( ValueError , self . field . stringify , '<STR_LIT>' ) <EOL> def test_fingerprint ( self ) : <EOL> field1 = FakeEnumField ( ) <EOL> field2 = FakeEnumAltField ( ) <EOL> self . assertNotEqual ( str ( field1 ) , str ( field2 ) ) <EOL> class TestEnum ( TestField ) : <EOL> def setUp ( self ) : <EOL> super ( TestEnum , self ) . setUp ( ) <EOL> self . field = fields . EnumField ( <EOL> valid_values = [ '<STR_LIT:foo>' , '<STR_LIT:bar>' , <NUM_LIT:1> , <NUM_LIT:1> , True ] ) <EOL> self . coerce_good_values = [ ( '<STR_LIT:foo>' , '<STR_LIT:foo>' ) , ( <NUM_LIT:1> , '<STR_LIT:1>' ) , ( True , '<STR_LIT:True>' ) ] <EOL> if six . PY2 : <EOL> self . coerce_good_values . append ( ( int ( <NUM_LIT:1> ) , '<STR_LIT:1>' ) ) <EOL> self . coerce_bad_values = [ '<STR_LIT>' , <NUM_LIT:2> , False ] <EOL> self . to_primitive_values = self . coerce_good_values [ <NUM_LIT:0> : <NUM_LIT:1> ] <EOL> self . from_primitive_values = self . coerce_good_values [ <NUM_LIT:0> : <NUM_LIT:1> ] <EOL> def test_stringify ( self ) : <EOL> self . assertEqual ( "<STR_LIT>" , self . field . stringify ( '<STR_LIT:foo>' ) ) <EOL> def test_stringify_invalid ( self ) : <EOL> self . assertRaises ( ValueError , self . field . stringify , '<STR_LIT>' ) <EOL> def test_fingerprint ( self ) : <EOL> field1 = fields . EnumField ( valid_values = [ '<STR_LIT:foo>' , '<STR_LIT:bar>' ] ) <EOL> field2 = fields . EnumField ( valid_values = [ '<STR_LIT:foo>' , '<STR_LIT>' ] ) <EOL> self . assertNotEqual ( str ( field1 ) , str ( field2 ) ) <EOL> def test_without_valid_values ( self ) : <EOL> self . assertRaises ( ovo_exc . EnumValidValuesInvalidError , <EOL> fields . EnumField , <NUM_LIT:1> ) <EOL> def test_with_empty_values ( self ) : <EOL> self . assertRaises ( ovo_exc . EnumRequiresValidValuesError , <EOL> fields . EnumField , [ ] ) <EOL> class TestImageSignatureTypes ( TestField ) : <EOL> def setUp ( self ) : <EOL> super ( TestImageSignatureTypes , self ) . setUp ( ) <EOL> self . hash_field = fields . ImageSignatureHashType ( ) <EOL> self . key_type_field = fields . ImageSignatureKeyType ( ) <EOL> def test_hashes ( self ) : <EOL> for hash_name in list ( signature_utils . HASH_METHODS . keys ( ) ) : <EOL> self . assertIn ( hash_name , self . hash_field . hashes ) <EOL> def test_key_types ( self ) : <EOL> key_type_dict = signature_utils . SignatureKeyType . _REGISTERED_TYPES <EOL> key_types = list ( key_type_dict . keys ( ) ) <EOL> for key_type in key_types : <EOL> self . assertIn ( key_type , self . key_type_field . key_types ) <EOL> class TestResourceClass ( TestField ) : <EOL> def setUp ( self ) : <EOL> super ( TestResourceClass , self ) . setUp ( ) <EOL> self . field = fields . ResourceClassField ( ) <EOL> self . coerce_good_values = [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ] <EOL> self . expected_indexes = [ <EOL> ( '<STR_LIT>' , <NUM_LIT:0> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:1> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:2> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:3> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:4> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:5> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:6> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:7> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:8> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:9> ) , <EOL> ] <EOL> self . coerce_bad_values = [ '<STR_LIT>' ] <EOL> self . to_primitive_values = self . coerce_good_values [ <NUM_LIT:0> : <NUM_LIT:1> ] <EOL> self . from_primitive_values = self . coerce_good_values [ <NUM_LIT:0> : <NUM_LIT:1> ] <EOL> def test_stringify ( self ) : <EOL> self . assertEqual ( "<STR_LIT>" , self . field . stringify ( <EOL> fields . ResourceClass . VCPU ) ) <EOL> def test_stringify_invalid ( self ) : <EOL> self . assertRaises ( ValueError , self . field . stringify , '<STR_LIT>' ) <EOL> def test_index ( self ) : <EOL> for name , index in self . expected_indexes : <EOL> self . assertEqual ( index , self . field . index ( name ) ) <EOL> def test_index_invalid ( self ) : <EOL> self . assertRaises ( ValueError , self . field . index , '<STR_LIT>' ) <EOL> def test_from_index ( self ) : <EOL> for name , index in self . expected_indexes : <EOL> self . assertEqual ( name , self . field . from_index ( index ) ) <EOL> def test_from_index_invalid ( self ) : <EOL> self . assertRaises ( IndexError , self . field . from_index , <NUM_LIT> ) <EOL> class TestInteger ( TestField ) : <EOL> def setUp ( self ) : <EOL> super ( TestInteger , self ) . setUp ( ) <EOL> self . field = fields . IntegerField ( ) <EOL> self . coerce_good_values = [ ( <NUM_LIT:1> , <NUM_LIT:1> ) , ( '<STR_LIT:1>' , <NUM_LIT:1> ) ] <EOL> self . coerce_bad_values = [ '<STR_LIT:foo>' , None ] <EOL> self . to_primitive_values = self . coerce_good_values [ <NUM_LIT:0> : <NUM_LIT:1> ] <EOL> self . from_primitive_values = self . coerce_good_values [ <NUM_LIT:0> : <NUM_LIT:1> ] <EOL> class TestNonNegativeInteger ( TestInteger ) : <EOL> def setUp ( self ) : <EOL> super ( TestNonNegativeInteger , self ) . setUp ( ) <EOL> self . field = fields . Field ( fields . NonNegativeInteger ( ) ) <EOL> self . coerce_bad_values . extend ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> class TestFloat ( TestField ) : <EOL> def setUp ( self ) : <EOL> super ( TestFloat , self ) . setUp ( ) <EOL> self . field = fields . FloatField ( ) <EOL> self . coerce_good_values = [ ( <NUM_LIT> , <NUM_LIT> ) , ( '<STR_LIT>' , <NUM_LIT> ) ] <EOL> self . coerce_bad_values = [ '<STR_LIT:foo>' , None ] <EOL> self . to_primitive_values = self . coerce_good_values [ <NUM_LIT:0> : <NUM_LIT:1> ] <EOL> self . from_primitive_values = self . coerce_good_values [ <NUM_LIT:0> : <NUM_LIT:1> ] <EOL> class TestNonNegativeFloat ( TestFloat ) : <EOL> def setUp ( self ) : <EOL> super ( TestNonNegativeFloat , self ) . setUp ( ) <EOL> self . field = fields . Field ( fields . NonNegativeFloat ( ) ) <EOL> self . coerce_bad_values . extend ( [ '<STR_LIT>' ] ) <EOL> class TestBoolean ( TestField ) : <EOL> def setUp ( self ) : <EOL> super ( TestBoolean , self ) . setUp ( ) <EOL> self . field = fields . BooleanField ( ) <EOL> self . coerce_good_values = [ ( True , True ) , ( False , False ) , ( <NUM_LIT:1> , True ) , <EOL> ( '<STR_LIT:foo>' , True ) , ( <NUM_LIT:0> , False ) , ( '<STR_LIT>' , False ) ] <EOL> self . coerce_bad_values = [ ] <EOL> self . to_primitive_values = self . coerce_good_values [ <NUM_LIT:0> : <NUM_LIT:2> ] <EOL> self . from_primitive_values = self . coerce_good_values [ <NUM_LIT:0> : <NUM_LIT:2> ] <EOL> class TestDateTime ( TestField ) : <EOL> def setUp ( self ) : <EOL> super ( TestDateTime , self ) . setUp ( ) <EOL> self . dt = datetime . datetime ( <NUM_LIT> , <NUM_LIT:11> , <NUM_LIT:5> , tzinfo = iso8601 . iso8601 . Utc ( ) ) <EOL> self . field = fields . DateTimeField ( ) <EOL> self . coerce_good_values = [ ( self . dt , self . dt ) , <EOL> ( utils . isotime ( self . dt ) , self . dt ) ] <EOL> self . coerce_bad_values = [ <NUM_LIT:1> , '<STR_LIT:foo>' ] <EOL> self . to_primitive_values = [ ( self . dt , utils . isotime ( self . dt ) ) ] <EOL> self . from_primitive_values = [ ( utils . isotime ( self . dt ) , self . dt ) ] <EOL> def test_stringify ( self ) : <EOL> self . assertEqual ( <EOL> '<STR_LIT>' , <EOL> self . field . stringify ( <EOL> datetime . datetime ( <NUM_LIT> , <NUM_LIT:11> , <NUM_LIT:5> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> , <EOL> tzinfo = iso8601 . iso8601 . Utc ( ) ) ) ) <EOL> class TestDict ( TestField ) : <EOL> def setUp ( self ) : <EOL> super ( TestDict , self ) . setUp ( ) <EOL> self . field = fields . Field ( fields . Dict ( FakeFieldType ( ) ) ) <EOL> self . coerce_good_values = [ ( { '<STR_LIT:foo>' : '<STR_LIT:bar>' } , { '<STR_LIT:foo>' : '<STR_LIT>' } ) , <EOL> ( { '<STR_LIT:foo>' : <NUM_LIT:1> } , { '<STR_LIT:foo>' : '<STR_LIT>' } ) ] <EOL> self . coerce_bad_values = [ { <NUM_LIT:1> : '<STR_LIT:bar>' } , '<STR_LIT:foo>' ] <EOL> self . to_primitive_values = [ ( { '<STR_LIT:foo>' : '<STR_LIT:bar>' } , { '<STR_LIT:foo>' : '<STR_LIT>' } ) ] <EOL> self . from_primitive_values = [ ( { '<STR_LIT:foo>' : '<STR_LIT>' } , { '<STR_LIT:foo>' : '<STR_LIT:bar>' } ) ] <EOL> def test_stringify ( self ) : <EOL> self . assertEqual ( "<STR_LIT>" , self . field . stringify ( { '<STR_LIT:key>' : '<STR_LIT>' } ) ) <EOL> class TestDictOfStrings ( TestField ) : <EOL> def setUp ( self ) : <EOL> super ( TestDictOfStrings , self ) . setUp ( ) <EOL> self . field = fields . DictOfStringsField ( ) <EOL> self . coerce_good_values = [ ( { '<STR_LIT:foo>' : '<STR_LIT:bar>' } , { '<STR_LIT:foo>' : '<STR_LIT:bar>' } ) , <EOL> ( { '<STR_LIT:foo>' : <NUM_LIT:1> } , { '<STR_LIT:foo>' : '<STR_LIT:1>' } ) ] <EOL> self . coerce_bad_values = [ { <NUM_LIT:1> : '<STR_LIT:bar>' } , { '<STR_LIT:foo>' : None } , '<STR_LIT:foo>' ] <EOL> self . to_primitive_values = [ ( { '<STR_LIT:foo>' : '<STR_LIT:bar>' } , { '<STR_LIT:foo>' : '<STR_LIT:bar>' } ) ] <EOL> self . from_primitive_values = [ ( { '<STR_LIT:foo>' : '<STR_LIT:bar>' } , { '<STR_LIT:foo>' : '<STR_LIT:bar>' } ) ] <EOL> def test_stringify ( self ) : <EOL> self . assertEqual ( "<STR_LIT>" , self . field . stringify ( { '<STR_LIT:key>' : '<STR_LIT>' } ) ) <EOL> class TestDictOfIntegers ( TestField ) : <EOL> def setUp ( self ) : <EOL> super ( TestDictOfIntegers , self ) . setUp ( ) <EOL> self . field = fields . DictOfIntegersField ( ) <EOL> self . coerce_good_values = [ ( { '<STR_LIT:foo>' : '<STR_LIT>' } , { '<STR_LIT:foo>' : <NUM_LIT> } ) , <EOL> ( { '<STR_LIT:foo>' : <NUM_LIT> } , { '<STR_LIT:foo>' : <NUM_LIT:4> } ) ] <EOL> self . coerce_bad_values = [ { <NUM_LIT:1> : '<STR_LIT:bar>' } , { '<STR_LIT:foo>' : '<STR_LIT>' } , <EOL> '<STR_LIT:foo>' , { '<STR_LIT:foo>' : None } ] <EOL> self . to_primitive_values = [ ( { '<STR_LIT:foo>' : <NUM_LIT> } , { '<STR_LIT:foo>' : <NUM_LIT> } ) ] <EOL> self . from_primitive_values = [ ( { '<STR_LIT:foo>' : <NUM_LIT> } , { '<STR_LIT:foo>' : <NUM_LIT> } ) ] <EOL> def test_stringify ( self ) : <EOL> self . assertEqual ( "<STR_LIT>" , self . field . stringify ( { '<STR_LIT:key>' : <NUM_LIT> } ) ) <EOL> class TestDictOfStringsNone ( TestField ) : <EOL> def setUp ( self ) : <EOL> super ( TestDictOfStringsNone , self ) . setUp ( ) <EOL> self . field = fields . DictOfNullableStringsField ( ) <EOL> self . coerce_good_values = [ ( { '<STR_LIT:foo>' : '<STR_LIT:bar>' } , { '<STR_LIT:foo>' : '<STR_LIT:bar>' } ) , <EOL> ( { '<STR_LIT:foo>' : <NUM_LIT:1> } , { '<STR_LIT:foo>' : '<STR_LIT:1>' } ) , <EOL> ( { '<STR_LIT:foo>' : None } , { '<STR_LIT:foo>' : None } ) ] <EOL> self . coerce_bad_values = [ { <NUM_LIT:1> : '<STR_LIT:bar>' } , '<STR_LIT:foo>' ] <EOL> self . to_primitive_values = [ ( { '<STR_LIT:foo>' : '<STR_LIT:bar>' } , { '<STR_LIT:foo>' : '<STR_LIT:bar>' } ) ] <EOL> self . from_primitive_values = [ ( { '<STR_LIT:foo>' : '<STR_LIT:bar>' } , { '<STR_LIT:foo>' : '<STR_LIT:bar>' } ) ] <EOL> def test_stringify ( self ) : <EOL> self . assertEqual ( "<STR_LIT>" , <EOL> self . field . stringify ( { '<STR_LIT>' : None , <EOL> '<STR_LIT:key>' : '<STR_LIT>' } ) ) <EOL> class TestListOfDictOfNullableStringsField ( TestField ) : <EOL> def setUp ( self ) : <EOL> super ( TestListOfDictOfNullableStringsField , self ) . setUp ( ) <EOL> self . field = fields . ListOfDictOfNullableStringsField ( ) <EOL> self . coerce_good_values = [ ( [ { '<STR_LIT:f>' : '<STR_LIT:b>' , '<STR_LIT>' : '<STR_LIT>' } , { '<STR_LIT>' : '<STR_LIT>' } ] , <EOL> [ { '<STR_LIT:f>' : '<STR_LIT:b>' , '<STR_LIT>' : '<STR_LIT>' } , { '<STR_LIT>' : '<STR_LIT>' } ] ) , <EOL> ( [ { '<STR_LIT:f>' : <NUM_LIT:1> } , { '<STR_LIT>' : '<STR_LIT>' } ] , <EOL> [ { '<STR_LIT:f>' : '<STR_LIT:1>' } , { '<STR_LIT>' : '<STR_LIT>' } ] ) , <EOL> ( [ { '<STR_LIT:foo>' : None } ] , [ { '<STR_LIT:foo>' : None } ] ) ] <EOL> self . coerce_bad_values = [ [ { <NUM_LIT:1> : '<STR_LIT:a>' } ] , [ '<STR_LIT>' , <NUM_LIT:1> ] , [ '<STR_LIT>' ] ] <EOL> self . to_primitive_values = [ ( [ { '<STR_LIT:f>' : '<STR_LIT:b>' } , { '<STR_LIT>' : '<STR_LIT>' } , { '<STR_LIT>' : None } ] , <EOL> [ { '<STR_LIT:f>' : '<STR_LIT:b>' } , { '<STR_LIT>' : '<STR_LIT>' } , { '<STR_LIT>' : None } ] ) ] <EOL> self . from_primitive_values = [ ( [ { '<STR_LIT:f>' : '<STR_LIT:b>' } , { '<STR_LIT>' : '<STR_LIT>' } , <EOL> { '<STR_LIT>' : None } ] , <EOL> [ { '<STR_LIT:f>' : '<STR_LIT:b>' } , { '<STR_LIT>' : '<STR_LIT>' } , <EOL> { '<STR_LIT>' : None } ] ) ] <EOL> def test_stringify ( self ) : <EOL> self . assertEqual ( "<STR_LIT>" , <EOL> self . field . stringify ( <EOL> [ { '<STR_LIT:f>' : None , '<STR_LIT>' : '<STR_LIT>' } , { '<STR_LIT>' : '<STR_LIT>' } ] ) ) <EOL> class TestList ( TestField ) : <EOL> def setUp ( self ) : <EOL> super ( TestList , self ) . setUp ( ) <EOL> self . field = fields . Field ( fields . List ( FakeFieldType ( ) ) ) <EOL> self . coerce_good_values = [ ( [ '<STR_LIT:foo>' , '<STR_LIT:bar>' ] , [ '<STR_LIT>' , '<STR_LIT>' ] ) ] <EOL> self . coerce_bad_values = [ '<STR_LIT:foo>' ] <EOL> self . to_primitive_values = [ ( [ '<STR_LIT:foo>' ] , [ '<STR_LIT>' ] ) ] <EOL> self . from_primitive_values = [ ( [ '<STR_LIT>' ] , [ '<STR_LIT:foo>' ] ) ] <EOL> def test_stringify ( self ) : <EOL> self . assertEqual ( '<STR_LIT>' , self . field . stringify ( [ <NUM_LIT> ] ) ) <EOL> class TestListOfStrings ( TestField ) : <EOL> def setUp ( self ) : <EOL> super ( TestListOfStrings , self ) . setUp ( ) <EOL> self . field = fields . ListOfStringsField ( ) <EOL> self . coerce_good_values = [ ( [ '<STR_LIT:foo>' , '<STR_LIT:bar>' ] , [ '<STR_LIT:foo>' , '<STR_LIT:bar>' ] ) ] <EOL> self . coerce_bad_values = [ '<STR_LIT:foo>' ] <EOL> self . to_primitive_values = [ ( [ '<STR_LIT:foo>' ] , [ '<STR_LIT:foo>' ] ) ] <EOL> self . from_primitive_values = [ ( [ '<STR_LIT:foo>' ] , [ '<STR_LIT:foo>' ] ) ] <EOL> def test_stringify ( self ) : <EOL> self . assertEqual ( "<STR_LIT>" , self . field . stringify ( [ '<STR_LIT:abc>' ] ) ) <EOL> class TestSet ( TestField ) : <EOL> def setUp ( self ) : <EOL> super ( TestSet , self ) . setUp ( ) <EOL> self . field = fields . Field ( fields . Set ( FakeFieldType ( ) ) ) <EOL> self . coerce_good_values = [ ( set ( [ '<STR_LIT:foo>' , '<STR_LIT:bar>' ] ) , <EOL> set ( [ '<STR_LIT>' , '<STR_LIT>' ] ) ) ] <EOL> self . coerce_bad_values = [ [ '<STR_LIT:foo>' ] , { '<STR_LIT:foo>' : '<STR_LIT:bar>' } ] <EOL> self . to_primitive_values = [ ( set ( [ '<STR_LIT:foo>' ] ) , tuple ( [ '<STR_LIT>' ] ) ) ] <EOL> self . from_primitive_values = [ ( tuple ( [ '<STR_LIT>' ] ) , set ( [ '<STR_LIT:foo>' ] ) ) ] <EOL> def test_stringify ( self ) : <EOL> self . assertEqual ( '<STR_LIT>' , self . field . stringify ( set ( [ <NUM_LIT> ] ) ) ) <EOL> class TestSetOfIntegers ( TestField ) : <EOL> def setUp ( self ) : <EOL> super ( TestSetOfIntegers , self ) . setUp ( ) <EOL> self . field = fields . SetOfIntegersField ( ) <EOL> self . coerce_good_values = [ ( set ( [ '<STR_LIT:1>' , <NUM_LIT:2> ] ) , <EOL> set ( [ <NUM_LIT:1> , <NUM_LIT:2> ] ) ) ] <EOL> self . coerce_bad_values = [ set ( [ '<STR_LIT:foo>' ] ) ] <EOL> self . to_primitive_values = [ ( set ( [ <NUM_LIT:1> ] ) , tuple ( [ <NUM_LIT:1> ] ) ) ] <EOL> self . from_primitive_values = [ ( tuple ( [ <NUM_LIT:1> ] ) , set ( [ <NUM_LIT:1> ] ) ) ] <EOL> def test_stringify ( self ) : <EOL> self . assertEqual ( '<STR_LIT>' , self . field . stringify ( set ( [ <NUM_LIT:1> , <NUM_LIT:2> ] ) ) ) <EOL> class TestListOfSetsOfIntegers ( TestField ) : <EOL> def setUp ( self ) : <EOL> super ( TestListOfSetsOfIntegers , self ) . setUp ( ) <EOL> self . field = fields . ListOfSetsOfIntegersField ( ) <EOL> self . coerce_good_values = [ ( [ set ( [ '<STR_LIT:1>' , <NUM_LIT:2> ] ) , set ( [ <NUM_LIT:3> , '<STR_LIT:4>' ] ) ] , <EOL> [ set ( [ <NUM_LIT:1> , <NUM_LIT:2> ] ) , set ( [ <NUM_LIT:3> , <NUM_LIT:4> ] ) ] ) ] <EOL> self . coerce_bad_values = [ [ set ( [ '<STR_LIT:foo>' ] ) ] ] <EOL> self . to_primitive_values = [ ( [ set ( [ <NUM_LIT:1> ] ) ] , [ tuple ( [ <NUM_LIT:1> ] ) ] ) ] <EOL> self . from_primitive_values = [ ( [ tuple ( [ <NUM_LIT:1> ] ) ] , [ set ( [ <NUM_LIT:1> ] ) ] ) ] <EOL> def test_stringify ( self ) : <EOL> self . assertEqual ( '<STR_LIT>' , self . field . stringify ( [ set ( [ <NUM_LIT:1> , <NUM_LIT:2> ] ) ] ) ) <EOL> class TestNetworkModel ( TestField ) : <EOL> def setUp ( self ) : <EOL> super ( TestNetworkModel , self ) . setUp ( ) <EOL> model = network_model . NetworkInfo ( ) <EOL> self . field = fields . Field ( fields . NetworkModel ( ) ) <EOL> self . coerce_good_values = [ ( model , model ) , ( model . json ( ) , model ) ] <EOL> self . coerce_bad_values = [ [ ] , '<STR_LIT:foo>' ] <EOL> self . to_primitive_values = [ ( model , model . json ( ) ) ] <EOL> self . from_primitive_values = [ ( model . json ( ) , model ) ] <EOL> def test_stringify ( self ) : <EOL> networkinfo = network_model . NetworkInfo ( ) <EOL> networkinfo . append ( network_model . VIF ( id = <NUM_LIT> ) ) <EOL> networkinfo . append ( network_model . VIF ( id = <NUM_LIT> ) ) <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> self . field . stringify ( networkinfo ) ) <EOL> class TestNotificationPriority ( TestField ) : <EOL> def setUp ( self ) : <EOL> super ( TestNotificationPriority , self ) . setUp ( ) <EOL> self . field = fields . NotificationPriorityField ( ) <EOL> self . coerce_good_values = [ ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT:error>' , '<STR_LIT:error>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> self . coerce_bad_values = [ '<STR_LIT>' ] <EOL> self . to_primitive_values = self . coerce_good_values [ <NUM_LIT:0> : <NUM_LIT:1> ] <EOL> self . from_primitive_values = self . coerce_good_values [ <NUM_LIT:0> : <NUM_LIT:1> ] <EOL> def test_stringify ( self ) : <EOL> self . assertEqual ( "<STR_LIT>" , self . field . stringify ( '<STR_LIT>' ) ) <EOL> def test_stringify_invalid ( self ) : <EOL> self . assertRaises ( ValueError , self . field . stringify , '<STR_LIT>' ) <EOL> class TestNotificationPhase ( TestField ) : <EOL> def setUp ( self ) : <EOL> super ( TestNotificationPhase , self ) . setUp ( ) <EOL> self . field = fields . NotificationPhaseField ( ) <EOL> self . coerce_good_values = [ ( '<STR_LIT:start>' , '<STR_LIT:start>' ) , <EOL> ( '<STR_LIT:end>' , '<STR_LIT:end>' ) , <EOL> ( '<STR_LIT:error>' , '<STR_LIT:error>' ) ] <EOL> self . coerce_bad_values = [ '<STR_LIT>' ] <EOL> self . to_primitive_values = self . coerce_good_values [ <NUM_LIT:0> : <NUM_LIT:1> ] <EOL> self . from_primitive_values = self . coerce_good_values [ <NUM_LIT:0> : <NUM_LIT:1> ] <EOL> def test_stringify ( self ) : <EOL> self . assertEqual ( "<STR_LIT>" , self . field . stringify ( '<STR_LIT:error>' ) ) <EOL> def test_stringify_invalid ( self ) : <EOL> self . assertRaises ( ValueError , self . field . stringify , '<STR_LIT>' ) <EOL> class TestNotificationAction ( TestField ) : <EOL> def setUp ( self ) : <EOL> super ( TestNotificationAction , self ) . setUp ( ) <EOL> self . field = fields . NotificationActionField ( ) <EOL> self . coerce_good_values = [ ( '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> self . coerce_bad_values = [ '<STR_LIT>' ] <EOL> self . to_primitive_values = self . coerce_good_values [ <NUM_LIT:0> : <NUM_LIT:1> ] <EOL> self . from_primitive_values = self . coerce_good_values [ <NUM_LIT:0> : <NUM_LIT:1> ] <EOL> def test_stringify ( self ) : <EOL> self . assertEqual ( "<STR_LIT>" , self . field . stringify ( '<STR_LIT>' ) ) <EOL> def test_stringify_invalid ( self ) : <EOL> self . assertRaises ( ValueError , self . field . stringify , '<STR_LIT>' ) </s>
