def test_list_switch_machines(self): switch.add_switch( ip='2887583784', user=self.user_object, ) switch.add_switch_machine( 2, mac='28:6e:d4:46:c4:25', port='1', user=self.user_object, ) list_switch_machines = switch.list_switch_machines( 2, user=self.user_object, ) expected = { 'switch_id': 2, 'id': 1, 'mac': '28:6e:d4:46:c4:25', 'switch_ip': '172.29.8.40', 'machine_id': 1, 'port': '1', 'switch_machine_id': 1 } self.assertIsNotNone(list_switch_machines) self.assertTrue( all(item in list_switch_machines[0].items() for item in expected.items()))
def test_update_switch_machine(self): switch.add_switch_machine( 1, mac='28:6e:d4:46:c4:25', port='1', user=self.user_object, ) switch.update_switch_machine( 1, 1, tag='test_tag', user=self.user_object, ) update_switch_machine = switch.list_switch_machines( 1, user=self.user_object, ) expected = { 'switch_id': 1, 'id': 1, 'mac': '28:6e:d4:46:c4:25', 'tag': 'test_tag', 'switch_ip': '0.0.0.0', 'machine_id': 1, 'port': '1', 'switch_machine_id': 1 } self.assertTrue( all(item in update_switch_machine[0].items() for item in expected.items()))
def test_update_switch_machine(self): switch.add_switch_machine( 1, mac='28:6e:d4:46:c4:25', port='1', user=self.user_object, ) switch.update_switch_machine( 1, 1, tag='test_tag', user=self.user_object, ) update_switch_machine = switch.list_switch_machines( 1, user=self.user_object, ) expected = { 'switch_id': 1, 'id': 1, 'mac': '28:6e:d4:46:c4:25', 'tag': 'test_tag', 'switch_ip': '0.0.0.0', 'machine_id': 1, 'port': '1', 'switch_machine_id': 1 } self.assertTrue( all(item in update_switch_machine[0].items() for item in expected.items()) )
def test_patch_switch_machine(self): switch.add_switch_machine( 1, mac='28:6e:d4:46:c4:25', port='1', user=self.user_object, ) switch.patch_switch_machine( 1, 1, user=self.user_object, tag={ 'patched_tag': 'test_patched_tag' } ) switch_patch_switch_machine = switch.list_switch_machines( 1, user=self.user_object, ) expected = {'tag': { 'patched_tag': 'test_patched_tag'} } self.assertTrue( all(item in switch_patch_switch_machine[0].items() for item in expected.items()) )
def list_switch_machines(): """List switch machines.""" data = _get_request_args() _filter_ip(data) _filter_port(data) _filter_vlans(data) _filter_tag(data) _filter_location(data) return utils.make_json_response( 200, switch_api.list_switch_machines( current_user, **data ) )
def test_list_switch_machines(self): switch.add_switch( self.user_object, ip='2887583784' ) switch.add_switch_machine( self.user_object, 2, mac='28:6e:d4:46:c4:25', port='1' ) list_switch_machines = switch.list_switch_machines( self.user_object, 2 ) self.assertIsNotNone(list_switch_machines)
def test_del_switch_machine(self): switch.add_switch_machine( 1, mac='28:6e:d4:46:c4:25', port='1', user=self.user_object, ) switch.del_switch_machine( 1, 1, user=self.user_object, ) del_switch_machine = switch.list_switch_machines( 1, user=self.user_object, ) self.assertEqual([], del_switch_machine)
def test_patch_switch_machine(self): switch.add_switch_machine( 1, mac='28:6e:d4:46:c4:25', port='1', user=self.user_object, ) switch.patch_switch_machine(1, 1, user=self.user_object, tag={'patched_tag': 'test_patched_tag'}) switch_patch_switch_machine = switch.list_switch_machines( 1, user=self.user_object, ) expected = {'tag': {'patched_tag': 'test_patched_tag'}} self.assertTrue( all(item in switch_patch_switch_machine[0].items() for item in expected.items()))
def test_update_switch_machines_remove(self): switch.add_switch( ip='2887583784', user=self.user_object, ) switch.add_switch_machine( 2, mac='28:6e:d4:46:c4:25', port='1', user=self.user_object, ) switch.update_switch_machines( 2, remove_machines=1, user=self.user_object, ) update_remove = switch.list_switch_machines( 2, user=self.user_object, ) self.assertEqual([], update_remove)
def test_update_switch_machine(self): switch.add_switch_machine( self.user_object, 1, mac='28:6e:d4:46:c4:25', port='1' ) switch.update_switch_machine( self.user_object, 1, 1, tag='test_tag' ) update_switch_machine = switch.list_switch_machines( self.user_object, 1 ) expected = {'tag': 'test_tag'} self.assertTrue( item in update_switch_machine[0].items for item in expected.items() )
def test_pathc_switch_machine(self): switch.add_switch_machine( self.user_object, 1, mac='28:6e:d4:46:c4:25', port='1' ) switch.patch_switch_machine( self.user_object, 1, 1, patched_tag={ 'patched_tag': 'test_patched_tag' } ) switch_patch_switch_machine = switch.list_switch_machines( self.user_object, 1 ) expected = {'patched_tag': 'test_patched_tag'} self.assertTrue( item in switch_patch_switch_machine[0].items() for item in expected.items() )