<s> import mock <EOL> import requests_mock <EOL> import unittest2 <EOL> from bareon . drivers . data import simple <EOL> from bareon import objects <EOL> from bareon . tests import base <EOL> @ mock . patch . multiple ( <EOL> simple . NailgunSimpleDriver , <EOL> parse_operating_system = lambda x : objects . OperatingSystem ( None , None ) , <EOL> parse_image_meta = lambda x : { } , <EOL> parse_grub = lambda x : objects . Grub ( ) , <EOL> parse_configdrive_scheme = lambda x : objects . ConfigDriveScheme ( ) , <EOL> parse_image_scheme = lambda x : objects . ImageScheme ( ) ) <EOL> class TestObjectDeserialization ( unittest2 . TestCase ) : <EOL> def test_driver_always_has_correct_objects ( self ) : <EOL> driver = simple . NailgunSimpleDriver ( { } ) <EOL> assert isinstance ( driver . partition_scheme , objects . PartitionScheme ) <EOL> def test_lv_data_is_loaded ( self ) : <EOL> lv_data = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ <EOL> { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> ] <EOL> } <EOL> } <EOL> driver = simple . NailgunSimpleDriver ( lv_data ) <EOL> lv = driver . partition_scheme . lvs [ <NUM_LIT:0> ] <EOL> assert len ( driver . partition_scheme . lvs ) == <NUM_LIT:1> <EOL> assert isinstance ( lv , objects . LV ) <EOL> assert lv . name == '<STR_LIT>' <EOL> assert lv . size == <NUM_LIT> <EOL> assert lv . vgname == '<STR_LIT>' <EOL> def test_pv_data_is_loaded ( self ) : <EOL> pv_data = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ <EOL> { <EOL> '<STR_LIT>' : <NUM_LIT:2> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT:name>' : '<STR_LIT>' <EOL> } , <EOL> ] <EOL> } <EOL> } <EOL> driver = simple . NailgunSimpleDriver ( pv_data ) <EOL> pv = driver . partition_scheme . pvs [ <NUM_LIT:0> ] <EOL> assert len ( driver . partition_scheme . pvs ) == <NUM_LIT:1> <EOL> assert isinstance ( pv , objects . PV ) <EOL> assert pv . name == '<STR_LIT>' <EOL> assert pv . metadatacopies == <NUM_LIT:2> <EOL> assert pv . metadatasize == <NUM_LIT> <EOL> def test_vg_data_is_loaded ( self ) : <EOL> vg_data = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ <EOL> { <EOL> '<STR_LIT:name>' : '<STR_LIT:image>' , <EOL> '<STR_LIT>' : [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> } , <EOL> ] <EOL> } <EOL> } <EOL> driver = simple . NailgunSimpleDriver ( vg_data ) <EOL> vg = driver . partition_scheme . vgs [ <NUM_LIT:0> ] <EOL> assert len ( driver . partition_scheme . vgs ) == <NUM_LIT:1> <EOL> assert isinstance ( vg , objects . VG ) <EOL> assert vg . name == '<STR_LIT:image>' <EOL> self . assertItemsEqual ( <EOL> vg . pvnames , <EOL> ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) <EOL> ) <EOL> def test_fs_data_is_loaded ( self ) : <EOL> fs_data = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ <EOL> { <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> ] <EOL> } <EOL> } <EOL> driver = simple . NailgunSimpleDriver ( fs_data ) <EOL> fs = driver . partition_scheme . fss [ <NUM_LIT:0> ] <EOL> assert len ( driver . partition_scheme . fss ) == <NUM_LIT:1> <EOL> assert isinstance ( fs , objects . FS ) <EOL> assert fs . device == '<STR_LIT>' <EOL> assert fs . label == '<STR_LIT>' <EOL> assert fs . options == '<STR_LIT>' <EOL> assert fs . type == '<STR_LIT>' <EOL> assert fs . mount == '<STR_LIT>' <EOL> def test_parted_data_is_loaded ( self ) : <EOL> parted_data = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ <EOL> { <EOL> '<STR_LIT:label>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ <EOL> { <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:count>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:end>' : <NUM_LIT> , <EOL> '<STR_LIT>' : [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } , <EOL> ] <EOL> } , <EOL> ] <EOL> } <EOL> } <EOL> driver = simple . NailgunSimpleDriver ( parted_data ) <EOL> parted = driver . partition_scheme . parteds [ <NUM_LIT:0> ] <EOL> partition = parted . partitions [ <NUM_LIT:0> ] <EOL> assert len ( driver . partition_scheme . parteds ) == <NUM_LIT:1> <EOL> assert isinstance ( parted , objects . Parted ) <EOL> assert parted . label == '<STR_LIT>' <EOL> assert parted . name == '<STR_LIT>' <EOL> assert len ( parted . partitions ) == <NUM_LIT:1> <EOL> assert partition . begin == <NUM_LIT:1> <EOL> assert partition . configdrive is False <EOL> assert partition . count == <NUM_LIT:1> <EOL> assert partition . device == '<STR_LIT>' <EOL> assert partition . end == <NUM_LIT> <EOL> self . assertItemsEqual ( partition . flags , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> assert partition . guid is None <EOL> assert partition . name == '<STR_LIT>' <EOL> assert partition . type == '<STR_LIT>' <EOL> def test_md_data_is_loaded ( self ) : <EOL> md_data = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ <EOL> { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] , <EOL> '<STR_LIT>' : [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> } , <EOL> ] <EOL> } <EOL> } <EOL> driver = simple . NailgunSimpleDriver ( md_data ) <EOL> md = driver . partition_scheme . mds [ <NUM_LIT:0> ] <EOL> assert len ( driver . partition_scheme . mds ) == <NUM_LIT:1> <EOL> assert isinstance ( md , objects . MD ) <EOL> assert md . name == '<STR_LIT>' <EOL> assert md . level == <NUM_LIT:1> <EOL> self . assertItemsEqual ( md . devices , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertItemsEqual ( md . spares , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> @ requests_mock . mock ( ) <EOL> class TestFullDataRead ( unittest2 . TestCase ) : <EOL> PROVISION_DATA = base . load_fixture ( '<STR_LIT>' ) <EOL> def test_read_with_no_error ( self , mock_requests ) : <EOL> mock_requests . get ( '<STR_LIT>' , <EOL> text = '<STR_LIT:{}>' ) <EOL> driver = simple . NailgunSimpleDriver ( self . PROVISION_DATA ) <EOL> scheme = driver . partition_scheme <EOL> assert len ( scheme . fss ) == <NUM_LIT:5> <EOL> assert len ( scheme . lvs ) == <NUM_LIT:3> <EOL> assert len ( scheme . mds ) == <NUM_LIT:0> <EOL> assert len ( scheme . parteds ) == <NUM_LIT:2> <EOL> assert len ( scheme . pvs ) == <NUM_LIT:4> <EOL> assert len ( scheme . vgs ) == <NUM_LIT:2> </s>
