<s> import datetime <EOL> import logging <EOL> import os <EOL> import unittest2 <EOL> os . environ [ '<STR_LIT>' ] = '<STR_LIT:true>' <EOL> from compass . utils import setting_wrapper as setting <EOL> reload ( setting ) <EOL> from base import BaseTest <EOL> from compass . db . api import database <EOL> from compass . db . api import switch <EOL> from compass . db . api import user as user_api <EOL> from compass . db import exception <EOL> from compass . utils import flags <EOL> from compass . utils import logsetting <EOL> class TestGetSwitch ( BaseTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( TestGetSwitch , self ) . setUp ( ) <EOL> def tearDown ( self ) : <EOL> super ( TestGetSwitch , self ) . tearDown ( ) <EOL> def test_get_switch ( self ) : <EOL> get_switch = switch . get_switch ( <EOL> <NUM_LIT:1> , <EOL> user = self . user_object , <EOL> ) <EOL> self . assertIsNotNone ( get_switch ) <EOL> self . assertEqual ( get_switch [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> class TestAddSwitch ( BaseTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( TestAddSwitch , self ) . setUp ( ) <EOL> def tearDown ( self ) : <EOL> super ( TestAddSwitch , self ) . tearDown ( ) <EOL> def test_add_switch ( self ) : <EOL> add_switch = switch . add_switch ( <EOL> ip = '<STR_LIT>' , <EOL> user = self . user_object , <EOL> ) <EOL> expected = '<STR_LIT>' <EOL> self . assertEqual ( expected , add_switch [ '<STR_LIT>' ] ) <EOL> def test_add_switch_position_args ( self ) : <EOL> add_switch = switch . add_switch ( <EOL> True , <EOL> '<STR_LIT>' , <EOL> user = self . user_object , <EOL> ) <EOL> expected = '<STR_LIT>' <EOL> self . assertEqual ( expected , add_switch [ '<STR_LIT>' ] ) <EOL> def test_add_switch_session ( self ) : <EOL> with database . session ( ) as session : <EOL> add_switch = switch . add_switch ( <EOL> ip = '<STR_LIT>' , <EOL> user = self . user_object , <EOL> session = session <EOL> ) <EOL> expected = '<STR_LIT>' <EOL> self . assertEqual ( expected , add_switch [ '<STR_LIT>' ] ) <EOL> class TestAddSwitches ( BaseTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( TestAddSwitches , self ) . setUp ( ) <EOL> def tearDown ( self ) : <EOL> super ( TestAddSwitches , self ) . tearDown ( ) <EOL> def test_add_switches ( self ) : <EOL> data = [ <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> "<STR_LIT:version>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> } , { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } , { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> ] <EOL> switches = switch . add_switches ( <EOL> data = data , <EOL> user = self . user_object <EOL> ) <EOL> ip = [ ] <EOL> for item in switches [ '<STR_LIT>' ] : <EOL> ip . append ( item [ '<STR_LIT>' ] ) <EOL> fail_ip = [ ] <EOL> for item in switches [ '<STR_LIT>' ] : <EOL> fail_ip . append ( item [ '<STR_LIT>' ] ) <EOL> expected = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> expected_fail = [ '<STR_LIT>' ] <EOL> for expect in expected : <EOL> self . assertIn ( expect , ip ) <EOL> for expect_fail in expected_fail : <EOL> self . assertIn ( expect_fail , fail_ip ) <EOL> class TestListSwitches ( BaseTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( TestListSwitches , self ) . setUp ( ) <EOL> def tearDown ( self ) : <EOL> super ( TestListSwitches , self ) . tearDown ( ) <EOL> def test_list_switches_ip_int_invalid ( self ) : <EOL> switch . add_switch ( <EOL> ip = '<STR_LIT>' , <EOL> user = self . user_object , <EOL> ) <EOL> list_switches = switch . list_switches ( <EOL> ip_int = '<STR_LIT:test>' , <EOL> user = self . user_object , <EOL> ) <EOL> self . assertEqual ( list_switches , [ ] ) <EOL> def test_list_switches_with_ip_int ( self ) : <EOL> switch . add_switch ( <EOL> ip = '<STR_LIT>' , <EOL> user = self . user_object , <EOL> ) <EOL> list_switches = switch . list_switches ( <EOL> ip_int = '<STR_LIT>' , <EOL> user = self . user_object , <EOL> ) <EOL> expected = '<STR_LIT>' <EOL> self . assertIsNotNone ( list_switches ) <EOL> self . assertEqual ( expected , list_switches [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) <EOL> def test_list_switches ( self ) : <EOL> switch . add_switch ( <EOL> ip = '<STR_LIT>' , <EOL> user = self . user_object , <EOL> ) <EOL> list_switches = switch . list_switches ( <EOL> user = self . user_object <EOL> ) <EOL> expected = '<STR_LIT>' <EOL> self . assertIsNotNone ( list_switches ) <EOL> self . assertEqual ( expected , list_switches [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) <EOL> class TestDelSwitch ( BaseTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( TestDelSwitch , self ) . setUp ( ) <EOL> def tearDown ( self ) : <EOL> super ( TestDelSwitch , self ) . tearDown ( ) <EOL> def test_del_switch ( self ) : <EOL> switch . del_switch ( <EOL> <NUM_LIT:1> , <EOL> user = self . user_object , <EOL> ) <EOL> del_switch = switch . list_switches ( <EOL> user = self . user_object <EOL> ) <EOL> self . assertEqual ( [ ] , del_switch ) <EOL> class TestUpdateSwitch ( BaseTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( TestUpdateSwitch , self ) . setUp ( ) <EOL> def tearDown ( self ) : <EOL> super ( TestUpdateSwitch , self ) . tearDown ( ) <EOL> def test_update_switch ( self ) : <EOL> switch . update_switch ( <EOL> <NUM_LIT:1> , <EOL> user = self . user_object , <EOL> vendor = '<STR_LIT>' <EOL> ) <EOL> update_switch = switch . get_switch ( <EOL> <NUM_LIT:1> , <EOL> user = self . user_object , <EOL> ) <EOL> expected = '<STR_LIT>' <EOL> self . assertEqual ( expected , update_switch [ '<STR_LIT>' ] ) <EOL> class TestPatchSwitch ( BaseTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( TestPatchSwitch , self ) . setUp ( ) <EOL> def tearDown ( self ) : <EOL> super ( TestPatchSwitch , self ) . tearDown ( ) <EOL> def test_patch_switch ( self ) : <EOL> switch . patch_switch ( <EOL> <NUM_LIT:1> , <EOL> user = self . user_object , <EOL> credentials = { <EOL> '<STR_LIT:version>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> ) <EOL> patch_switch = switch . get_switch ( <EOL> <NUM_LIT:1> , <EOL> user = self . user_object , <EOL> ) <EOL> expected = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:version>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> self . assertTrue ( <EOL> all ( item in patch_switch . items ( ) for item in expected . items ( ) ) <EOL> ) <EOL> class TestListSwitchFilters ( BaseTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( TestListSwitchFilters , self ) . setUp ( ) <EOL> def tearDown ( self ) : <EOL> super ( TestListSwitchFilters , self ) . tearDown ( ) <EOL> def test_list_switch_filters ( self ) : <EOL> list_switch_filters = switch . list_switch_filters ( <EOL> user = self . user_object <EOL> ) <EOL> expected = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> self . assertIsNotNone ( list_switch_filters ) <EOL> self . assertTrue ( <EOL> all ( item in list_switch_filters [ <NUM_LIT:0> ] . items ( ) <EOL> for item in expected . items ( ) ) ) <EOL> class TestGetSwitchFilters ( BaseTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( TestGetSwitchFilters , self ) . setUp ( ) <EOL> def tearDown ( self ) : <EOL> super ( TestGetSwitchFilters , self ) . tearDown ( ) <EOL> def test_get_swtich_filters ( self ) : <EOL> get_switch_filter = switch . get_switch_filters ( <EOL> <NUM_LIT:1> , <EOL> user = self . user_object , <EOL> ) <EOL> expected = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> self . assertIsNotNone ( get_switch_filter ) <EOL> self . assertTrue ( <EOL> all ( item in get_switch_filter . items ( ) <EOL> for item in expected . items ( ) ) ) <EOL> class TestUpdateSwitchFilters ( BaseTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( TestUpdateSwitchFilters , self ) . setUp ( ) <EOL> def tearDown ( self ) : <EOL> super ( TestUpdateSwitchFilters , self ) . tearDown ( ) <EOL> def test_update_switch_filters ( self ) : <EOL> switch . update_switch_filters ( <EOL> <NUM_LIT:1> , <EOL> user = self . user_object , <EOL> machine_filters = [ <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> ] <EOL> ) <EOL> update_switch_filters = switch . get_switch_filters ( <EOL> <NUM_LIT:1> , <EOL> user = self . user_object , <EOL> ) <EOL> expected = { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> self . assertTrue ( <EOL> all ( item in update_switch_filters . items ( ) <EOL> for item in expected . items ( ) ) <EOL> ) <EOL> class TestPatchSwitchFilter ( BaseTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( TestPatchSwitchFilter , self ) . setUp ( ) <EOL> def tearDown ( self ) : <EOL> super ( TestPatchSwitchFilter , self ) . tearDown ( ) <EOL> def test_patch_switch_filter ( self ) : <EOL> switch . add_switch ( <EOL> ip = '<STR_LIT>' , <EOL> user = self . user_object , <EOL> ) <EOL> switch . patch_switch_filter ( <EOL> <NUM_LIT:2> , <EOL> user = self . user_object , <EOL> machine_filters = [ <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> ] <EOL> ) <EOL> patch_switch_filter = switch . get_switch_filters ( <EOL> <NUM_LIT:2> , <EOL> user = self . user_object , <EOL> ) <EOL> expected = { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> self . assertTrue ( <EOL> all ( item in patch_switch_filter . items ( ) <EOL> for item in expected . items ( ) ) <EOL> ) <EOL> class TestAddSwitchMachine ( BaseTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( TestAddSwitchMachine , self ) . setUp ( ) <EOL> def tearDown ( self ) : <EOL> super ( TestAddSwitchMachine , self ) . tearDown ( ) <EOL> def test_add_switch_machine ( self ) : <EOL> add_switch_machine = switch . add_switch_machine ( <EOL> <NUM_LIT:1> , <EOL> mac = '<STR_LIT>' , <EOL> port = '<STR_LIT:1>' , <EOL> user = self . user_object , <EOL> ) <EOL> expected = '<STR_LIT>' <EOL> self . assertEqual ( expected , add_switch_machine [ '<STR_LIT>' ] ) <EOL> def test_add_switch_machine_position_args ( self ) : <EOL> add_switch_machine = switch . add_switch_machine ( <EOL> <NUM_LIT:1> , <EOL> True , <EOL> '<STR_LIT>' , <EOL> port = '<STR_LIT:1>' , <EOL> user = self . user_object , <EOL> ) <EOL> expected = '<STR_LIT>' <EOL> self . assertEqual ( expected , add_switch_machine [ '<STR_LIT>' ] ) <EOL> def test_add_switch_machine_session ( self ) : <EOL> with database . session ( ) as session : <EOL> add_switch_machine = switch . add_switch_machine ( <EOL> <NUM_LIT:1> , <EOL> mac = '<STR_LIT>' , <EOL> user = self . user_object , <EOL> session = session , <EOL> port = '<STR_LIT:1>' <EOL> ) <EOL> expected = '<STR_LIT>' <EOL> self . assertEqual ( expected , add_switch_machine [ '<STR_LIT>' ] ) <EOL> class TestAddSwitchMachines ( BaseTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( TestAddSwitchMachines , self ) . setUp ( ) <EOL> def tearDown ( self ) : <EOL> super ( TestAddSwitchMachines , self ) . tearDown ( ) <EOL> def test_add_switch_machines ( self ) : <EOL> data = [ { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:port>' : '<STR_LIT:100>' <EOL> } , { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:port>' : '<STR_LIT>' <EOL> } , { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:port>' : '<STR_LIT>' <EOL> } , { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:port>' : '<STR_LIT>' <EOL> } ] <EOL> add_switch_machines = switch . add_switch_machines ( <EOL> data = data , user = self . user_object <EOL> ) <EOL> mac = [ ] <EOL> failed_mac = [ ] <EOL> for switch_machine in add_switch_machines [ '<STR_LIT>' ] : <EOL> mac . append ( switch_machine [ '<STR_LIT>' ] ) <EOL> for failed_switch in add_switch_machines [ '<STR_LIT>' ] : <EOL> failed_mac . append ( failed_switch [ '<STR_LIT>' ] ) <EOL> expect = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> expect_fail = [ '<STR_LIT>' ] <EOL> for item in expect : <EOL> self . assertIn ( item , mac ) <EOL> for item in expect_fail : <EOL> self . assertIn ( item , failed_mac ) <EOL> class TestListSwitchMachines ( BaseTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( TestListSwitchMachines , self ) . setUp ( ) <EOL> def tearDown ( self ) : <EOL> super ( TestListSwitchMachines , self ) . tearDown ( ) <EOL> def test_list_switch_machines ( self ) : <EOL> switch . add_switch ( <EOL> ip = '<STR_LIT>' , <EOL> user = self . user_object , <EOL> ) <EOL> switch . add_switch_machine ( <EOL> <NUM_LIT:2> , <EOL> mac = '<STR_LIT>' , <EOL> port = '<STR_LIT:1>' , <EOL> user = self . user_object , <EOL> ) <EOL> list_switch_machines = switch . list_switch_machines ( <EOL> <NUM_LIT:2> , <EOL> user = self . user_object , <EOL> ) <EOL> expected = { <EOL> '<STR_LIT>' : <NUM_LIT:2> , <EOL> '<STR_LIT:id>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT:port>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : <NUM_LIT:1> <EOL> } <EOL> self . assertIsNotNone ( list_switch_machines ) <EOL> self . assertTrue ( <EOL> all ( item in list_switch_machines [ <NUM_LIT:0> ] . items ( ) <EOL> for item in expected . items ( ) ) ) <EOL> class TestListSwitchmachines ( BaseTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( TestListSwitchmachines , self ) . setUp ( ) <EOL> def tearDown ( self ) : <EOL> super ( TestListSwitchmachines , self ) . tearDown ( ) <EOL> def test_list_switch_machines_with_ip_int ( self ) : <EOL> switch . add_switch ( <EOL> ip = '<STR_LIT>' , <EOL> user = self . user_object , <EOL> ) <EOL> switch . add_switch_machine ( <EOL> <NUM_LIT:2> , <EOL> mac = '<STR_LIT>' , <EOL> port = '<STR_LIT:1>' , <EOL> user = self . user_object , <EOL> ) <EOL> list_switch_machines = switch . list_switchmachines ( <EOL> switch_ip_int = '<STR_LIT>' , <EOL> user = self . user_object , <EOL> ) <EOL> expected = { '<STR_LIT>' : '<STR_LIT>' } <EOL> self . assertTrue ( <EOL> all ( item in list_switch_machines [ <NUM_LIT:0> ] . items ( ) <EOL> for item in expected . items ( ) ) ) <EOL> def test_list_switch_machines_ip_invalid ( self ) : <EOL> switch . add_switch ( <EOL> ip = '<STR_LIT>' , <EOL> user = self . user_object , <EOL> ) <EOL> switch . add_switch_machine ( <EOL> <NUM_LIT:2> , <EOL> mac = '<STR_LIT>' , <EOL> port = '<STR_LIT:1>' , <EOL> user = self . user_object , <EOL> ) <EOL> list_switch_machines = switch . list_switchmachines ( <EOL> switch_ip_int = '<STR_LIT:test>' , <EOL> user = self . user_object , <EOL> ) <EOL> self . assertEqual ( list_switch_machines , [ ] ) <EOL> def test_list_switch_machines_without_ip ( self ) : <EOL> switch . add_switch ( <EOL> ip = '<STR_LIT>' , <EOL> user = self . user_object , <EOL> ) <EOL> switch . add_switch_machine ( <EOL> <NUM_LIT:2> , <EOL> mac = '<STR_LIT>' , <EOL> port = '<STR_LIT:1>' , <EOL> user = self . user_object , <EOL> ) <EOL> list_switch_machines = switch . list_switchmachines ( <EOL> user = self . user_object <EOL> ) <EOL> expected = { '<STR_LIT>' : '<STR_LIT>' } <EOL> self . assertTrue ( <EOL> all ( item in list_switch_machines [ <NUM_LIT:0> ] . items ( ) <EOL> for item in expected . items ( ) ) ) <EOL> class TestListSwitchMachinesHosts ( BaseTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( TestListSwitchMachinesHosts , self ) . setUp ( ) <EOL> def tearDown ( self ) : <EOL> super ( TestListSwitchMachinesHosts , self ) . tearDown ( ) <EOL> def test_list_hosts ( self ) : <EOL> switch . add_switch ( <EOL> ip = '<STR_LIT>' , <EOL> user = self . user_object , <EOL> ) <EOL> switch . add_switch_machine ( <EOL> <NUM_LIT:2> , <EOL> mac = '<STR_LIT>' , <EOL> port = '<STR_LIT:1>' , <EOL> user = self . user_object , <EOL> ) <EOL> list_hosts = switch . list_switch_machines_hosts ( <EOL> <NUM_LIT:2> , <EOL> user = self . user_object , <EOL> ) <EOL> expected = { <EOL> '<STR_LIT>' : <NUM_LIT:2> , <EOL> '<STR_LIT:id>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT:port>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : <NUM_LIT:1> <EOL> } <EOL> self . assertTrue ( <EOL> all ( item in list_hosts [ <NUM_LIT:0> ] . items ( ) <EOL> for item in expected . items ( ) ) ) <EOL> class TestListSwitchmachinesHosts ( BaseTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( TestListSwitchmachinesHosts , self ) . setUp ( ) <EOL> def tearDown ( self ) : <EOL> super ( TestListSwitchmachinesHosts , self ) . tearDown ( ) <EOL> def test_list_hosts_with_ip_int ( self ) : <EOL> switch . add_switch ( <EOL> ip = '<STR_LIT>' , <EOL> user = self . user_object , <EOL> ) <EOL> switch . add_switch_machine ( <EOL> <NUM_LIT:2> , <EOL> mac = '<STR_LIT>' , <EOL> port = '<STR_LIT:1>' , <EOL> user = self . user_object , <EOL> ) <EOL> list_hosts = switch . list_switchmachines_hosts ( <EOL> switch_ip_int = '<STR_LIT>' , <EOL> user = self . user_object , <EOL> ) <EOL> expected = { '<STR_LIT>' : '<STR_LIT>' } <EOL> self . assertTrue ( <EOL> all ( item in list_hosts [ <NUM_LIT:0> ] . items ( ) <EOL> for item in expected . items ( ) ) ) <EOL> def test_list_hosts_ip_invalid ( self ) : <EOL> switch . add_switch ( <EOL> ip = '<STR_LIT>' , <EOL> user = self . user_object , <EOL> ) <EOL> switch . add_switch_machine ( <EOL> <NUM_LIT:2> , <EOL> mac = '<STR_LIT>' , <EOL> port = '<STR_LIT:1>' , <EOL> user = self . user_object , <EOL> ) <EOL> list_hosts = switch . list_switchmachines_hosts ( <EOL> switch_ip_int = '<STR_LIT:test>' , <EOL> user = self . user_object , <EOL> ) <EOL> self . assertEqual ( list_hosts , [ ] ) <EOL> def test_list_hosts_without_ip ( self ) : <EOL> switch . add_switch ( <EOL> ip = '<STR_LIT>' , <EOL> user = self . user_object , <EOL> ) <EOL> switch . add_switch_machine ( <EOL> <NUM_LIT:2> , <EOL> mac = '<STR_LIT>' , <EOL> port = '<STR_LIT:1>' , <EOL> user = self . user_object , <EOL> ) <EOL> list_hosts = switch . list_switchmachines_hosts ( <EOL> user = self . user_object <EOL> ) <EOL> expected = { '<STR_LIT>' : '<STR_LIT>' } <EOL> self . assertTrue ( <EOL> all ( item in list_hosts [ <NUM_LIT:0> ] . items ( ) <EOL> for item in expected . items ( ) ) ) <EOL> self . assertIsNotNone ( list_hosts ) <EOL> class TestGetSwitchMachine ( BaseTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( TestGetSwitchMachine , self ) . setUp ( ) <EOL> def tearDown ( self ) : <EOL> super ( TestGetSwitchMachine , self ) . tearDown ( ) <EOL> def test_get_switch_machine ( self ) : <EOL> switch . add_switch ( <EOL> ip = '<STR_LIT>' , <EOL> user = self . user_object , <EOL> ) <EOL> switch . add_switch_machine ( <EOL> <NUM_LIT:2> , <EOL> mac = '<STR_LIT>' , <EOL> port = '<STR_LIT:1>' , <EOL> user = self . user_object , <EOL> ) <EOL> get_switch_machine = switch . get_switch_machine ( <EOL> <NUM_LIT:2> , <EOL> <NUM_LIT:1> , <EOL> user = self . user_object , <EOL> ) <EOL> self . assertIsNotNone ( get_switch_machine ) <EOL> self . assertEqual ( get_switch_machine [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> class TestGetSwitchmachine ( BaseTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( TestGetSwitchmachine , self ) . setUp ( ) <EOL> def tearDown ( self ) : <EOL> super ( TestGetSwitchmachine , self ) . tearDown ( ) <EOL> def test_get_switchmachine ( self ) : <EOL> switch . add_switch_machine ( <EOL> <NUM_LIT:1> , <EOL> mac = '<STR_LIT>' , <EOL> port = '<STR_LIT:1>' , <EOL> user = self . user_object , <EOL> ) <EOL> get_switchmachine = switch . get_switchmachine ( <EOL> <NUM_LIT:1> , <EOL> user = self . user_object , <EOL> ) <EOL> self . assertIsNotNone ( get_switchmachine ) <EOL> self . assertEqual ( get_switchmachine [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> class TestUpdateSwitchMachine ( BaseTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( TestUpdateSwitchMachine , self ) . setUp ( ) <EOL> def tearDown ( self ) : <EOL> super ( TestUpdateSwitchMachine , self ) . tearDown ( ) <EOL> def test_update_switch_machine ( self ) : <EOL> switch . add_switch_machine ( <EOL> <NUM_LIT:1> , <EOL> mac = '<STR_LIT>' , <EOL> port = '<STR_LIT:1>' , <EOL> user = self . user_object , <EOL> ) <EOL> switch . update_switch_machine ( <EOL> <NUM_LIT:1> , <EOL> <NUM_LIT:1> , <EOL> tag = '<STR_LIT>' , <EOL> user = self . user_object , <EOL> ) <EOL> update_switch_machine = switch . list_switch_machines ( <EOL> <NUM_LIT:1> , <EOL> user = self . user_object , <EOL> ) <EOL> expected = { <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT:id>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT:port>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : <NUM_LIT:1> <EOL> } <EOL> self . assertTrue ( <EOL> all ( item in update_switch_machine [ <NUM_LIT:0> ] . items ( ) <EOL> for item in expected . items ( ) ) <EOL> ) <EOL> class TestUpdateSwitchmachine ( BaseTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( TestUpdateSwitchmachine , self ) . setUp ( ) <EOL> def tearDown ( self ) : <EOL> super ( TestUpdateSwitchmachine , self ) . tearDown ( ) <EOL> def test_update_switchmachine ( self ) : <EOL> switch . add_switch_machine ( <EOL> <NUM_LIT:1> , <EOL> mac = '<STR_LIT>' , <EOL> port = '<STR_LIT:1>' , <EOL> user = self . user_object , <EOL> ) <EOL> switch . update_switchmachine ( <EOL> <NUM_LIT:1> , <EOL> location = '<STR_LIT>' , <EOL> user = self . user_object , <EOL> ) <EOL> update_switchmachine = switch . list_switchmachines ( <EOL> user = self . user_object , <EOL> ) <EOL> expected = { <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT:id>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:location>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT:port>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : <NUM_LIT:1> <EOL> } <EOL> self . assertTrue ( <EOL> all ( item in update_switchmachine [ <NUM_LIT:0> ] . items ( ) <EOL> for item in expected . items ( ) ) <EOL> ) <EOL> class TestPatchSwitchMachine ( BaseTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( TestPatchSwitchMachine , self ) . setUp ( ) <EOL> def tearDown ( self ) : <EOL> super ( TestPatchSwitchMachine , self ) . tearDown ( ) <EOL> def test_patch_switch_machine ( self ) : <EOL> switch . add_switch_machine ( <EOL> <NUM_LIT:1> , <EOL> mac = '<STR_LIT>' , <EOL> port = '<STR_LIT:1>' , <EOL> user = self . user_object , <EOL> ) <EOL> switch . patch_switch_machine ( <EOL> <NUM_LIT:1> , <EOL> <NUM_LIT:1> , <EOL> user = self . user_object , <EOL> tag = { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> ) <EOL> switch_patch_switch_machine = switch . list_switch_machines ( <EOL> <NUM_LIT:1> , <EOL> user = self . user_object , <EOL> ) <EOL> expected = { '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> } <EOL> self . assertTrue ( <EOL> all ( item in switch_patch_switch_machine [ <NUM_LIT:0> ] . items ( ) <EOL> for item in expected . items ( ) ) <EOL> ) <EOL> class TestPatchSwitchmachine ( BaseTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( TestPatchSwitchmachine , self ) . setUp ( ) <EOL> def tearDown ( self ) : <EOL> super ( TestPatchSwitchmachine , self ) . tearDown ( ) <EOL> def test_patch_switchmachine ( self ) : <EOL> switch . add_switch_machine ( <EOL> <NUM_LIT:1> , <EOL> mac = '<STR_LIT>' , <EOL> port = '<STR_LIT:1>' , <EOL> user = self . user_object , <EOL> ) <EOL> switch . patch_switchmachine ( <EOL> <NUM_LIT:1> , <EOL> user = self . user_object , <EOL> location = { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> ) <EOL> patch_switchmachine = switch . list_switchmachines ( <EOL> user = self . user_object <EOL> ) <EOL> expected = { '<STR_LIT:location>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> } <EOL> self . assertTrue ( <EOL> all ( item in patch_switchmachine [ <NUM_LIT:0> ] . items ( ) <EOL> for item in expected . items ( ) ) <EOL> ) <EOL> class TestDelSwitchMachine ( BaseTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( TestDelSwitchMachine , self ) . setUp ( ) <EOL> def tearDown ( self ) : <EOL> super ( TestDelSwitchMachine , self ) . tearDown ( ) <EOL> def test_del_switch_machine ( self ) : <EOL> switch . add_switch_machine ( <EOL> <NUM_LIT:1> , <EOL> mac = '<STR_LIT>' , <EOL> port = '<STR_LIT:1>' , <EOL> user = self . user_object , <EOL> ) <EOL> switch . del_switch_machine ( <EOL> <NUM_LIT:1> , <EOL> <NUM_LIT:1> , <EOL> user = self . user_object , <EOL> ) <EOL> del_switch_machine = switch . list_switch_machines ( <EOL> <NUM_LIT:1> , <EOL> user = self . user_object , <EOL> ) <EOL> self . assertEqual ( [ ] , del_switch_machine ) <EOL> class TestDelSwitchmachine ( BaseTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( TestDelSwitchmachine , self ) . setUp ( ) <EOL> def tearDown ( self ) : <EOL> super ( TestDelSwitchmachine , self ) . tearDown ( ) <EOL> def test_switchmachine ( self ) : <EOL> switch . add_switch_machine ( <EOL> <NUM_LIT:1> , <EOL> mac = '<STR_LIT>' , <EOL> port = '<STR_LIT:1>' , <EOL> user = self . user_object , <EOL> ) <EOL> switch . del_switchmachine ( <EOL> <NUM_LIT:1> , <EOL> user = self . user_object , <EOL> ) <EOL> del_switchmachine = switch . list_switchmachines ( <EOL> user = self . user_object <EOL> ) <EOL> self . assertEqual ( [ ] , del_switchmachine ) <EOL> class TestUpdateSwitchMachines ( BaseTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( TestUpdateSwitchMachines , self ) . setUp ( ) <EOL> def tearDown ( self ) : <EOL> super ( TestUpdateSwitchMachines , self ) . tearDown ( ) <EOL> def test_update_switch_machines_remove ( self ) : <EOL> switch . add_switch ( <EOL> ip = '<STR_LIT>' , <EOL> user = self . user_object , <EOL> ) <EOL> switch . add_switch_machine ( <EOL> <NUM_LIT:2> , <EOL> mac = '<STR_LIT>' , <EOL> port = '<STR_LIT:1>' , <EOL> user = self . user_object , <EOL> ) <EOL> switch . update_switch_machines ( <EOL> <NUM_LIT:2> , <EOL> remove_machines = <NUM_LIT:1> , <EOL> user = self . user_object , <EOL> ) <EOL> update_remove = switch . list_switch_machines ( <EOL> <NUM_LIT:2> , <EOL> user = self . user_object , <EOL> ) <EOL> self . assertEqual ( [ ] , update_remove ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> flags . init ( ) <EOL> logsetting . init ( ) <EOL> unittest2 . main ( ) </s>
