<s> import mock <EOL> from unittest import TestCase <EOL> from kingpin . manageddata . managed_datastructures import ManagedMappedList <EOL> import mock_zk_config_manager <EOL> TEST_ZK_HOSTS = [ '<STR_LIT>' ] <EOL> TEST_AWS_KEYFILE = "<STR_LIT>" <EOL> TEST_S3_BUCKET = "<STR_LIT>" <EOL> class ManagedMappedListTestCase ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . mock_zk_config_manager = mock . patch ( <EOL> '<STR_LIT>' , mock_zk_config_manager . MockZkConfigManager ) <EOL> self . mock_zk_config_manager . start ( ) <EOL> def tearDown ( self ) : <EOL> self . mock_zk_config_manager . stop ( ) <EOL> def test_get ( self ) : <EOL> managed_mapped_list = ManagedMappedList ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> TEST_ZK_HOSTS , TEST_AWS_KEYFILE , TEST_S3_BUCKET ) <EOL> self . assertEqual ( { } , managed_mapped_list . get_all ( ) ) <EOL> self . assertEqual ( [ ] , managed_mapped_list . get_list ( '<STR_LIT:key>' ) ) <EOL> def test_empty_remove ( self ) : <EOL> managed_mapped_list = ManagedMappedList ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> TEST_ZK_HOSTS , TEST_AWS_KEYFILE , TEST_S3_BUCKET ) <EOL> self . assertTrue ( managed_mapped_list . remove_list ( '<STR_LIT:key>' ) ) <EOL> self . assertTrue ( managed_mapped_list . remove_item ( '<STR_LIT:key>' , '<STR_LIT>' ) ) <EOL> self . assertTrue ( managed_mapped_list . remove_items ( '<STR_LIT:key>' , [ '<STR_LIT>' ] ) ) <EOL> def test_set_dedup ( self ) : <EOL> managed_mapped_list = ManagedMappedList ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> TEST_ZK_HOSTS , TEST_AWS_KEYFILE , TEST_S3_BUCKET ) <EOL> self . assertTrue ( managed_mapped_list . set_list ( '<STR_LIT:key>' , [ <NUM_LIT:1> , <NUM_LIT:2> ] ) ) <EOL> self . assertEqual ( [ <NUM_LIT:1> , <NUM_LIT:2> ] , managed_mapped_list . get_list ( '<STR_LIT:key>' ) ) <EOL> def test_set ( self ) : <EOL> managed_mapped_list = ManagedMappedList ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> TEST_ZK_HOSTS , TEST_AWS_KEYFILE , TEST_S3_BUCKET , <EOL> dedup = False ) <EOL> self . assertTrue ( managed_mapped_list . set_list ( '<STR_LIT:key>' , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:2> ] ) ) <EOL> self . assertEqual ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:2> ] , managed_mapped_list . get_list ( '<STR_LIT:key>' ) ) <EOL> def test_add_item_dedup ( self ) : <EOL> managed_mapped_list = ManagedMappedList ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> TEST_ZK_HOSTS , TEST_AWS_KEYFILE , TEST_S3_BUCKET ) <EOL> self . assertTrue ( managed_mapped_list . add_item ( '<STR_LIT:key>' , <NUM_LIT:2> ) ) <EOL> self . assertEqual ( [ <NUM_LIT:2> ] , managed_mapped_list . get_list ( '<STR_LIT:key>' ) ) <EOL> self . assertTrue ( managed_mapped_list . add_item ( '<STR_LIT:key>' , <NUM_LIT:2> ) ) <EOL> self . assertEqual ( [ <NUM_LIT:2> ] , managed_mapped_list . get_list ( '<STR_LIT:key>' ) ) <EOL> self . assertTrue ( managed_mapped_list . add_item ( '<STR_LIT:key>' , <NUM_LIT:3> ) ) <EOL> self . assertEqual ( [ <NUM_LIT:2> , <NUM_LIT:3> ] , managed_mapped_list . get_list ( '<STR_LIT:key>' ) ) <EOL> def test_add_item ( self ) : <EOL> managed_mapped_list = ManagedMappedList ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> TEST_ZK_HOSTS , TEST_AWS_KEYFILE , TEST_S3_BUCKET , <EOL> dedup = False ) <EOL> self . assertTrue ( managed_mapped_list . add_item ( '<STR_LIT:key>' , <NUM_LIT:2> ) ) <EOL> self . assertEqual ( [ <NUM_LIT:2> ] , managed_mapped_list . get_list ( '<STR_LIT:key>' ) ) <EOL> self . assertTrue ( managed_mapped_list . add_item ( '<STR_LIT:key>' , <NUM_LIT:2> ) ) <EOL> self . assertEqual ( [ <NUM_LIT:2> , <NUM_LIT:2> ] , managed_mapped_list . get_list ( '<STR_LIT:key>' ) ) <EOL> def test_add_items_dedup ( self ) : <EOL> managed_mapped_list = ManagedMappedList ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> TEST_ZK_HOSTS , TEST_AWS_KEYFILE , TEST_S3_BUCKET ) <EOL> self . assertTrue ( managed_mapped_list . add_items ( '<STR_LIT:key>' , [ <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:3> ] ) ) <EOL> self . assertEqual ( [ <NUM_LIT:2> , <NUM_LIT:3> ] , managed_mapped_list . get_list ( '<STR_LIT:key>' ) ) <EOL> self . assertTrue ( managed_mapped_list . add_items ( '<STR_LIT:key>' , [ <NUM_LIT:3> ] ) ) <EOL> self . assertEqual ( [ <NUM_LIT:2> , <NUM_LIT:3> ] , managed_mapped_list . get_list ( '<STR_LIT:key>' ) ) <EOL> def test_add_items ( self ) : <EOL> managed_mapped_list = ManagedMappedList ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> TEST_ZK_HOSTS , TEST_AWS_KEYFILE , TEST_S3_BUCKET , <EOL> dedup = False ) <EOL> self . assertTrue ( managed_mapped_list . add_items ( '<STR_LIT:key>' , [ <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:3> ] ) ) <EOL> self . assertEqual ( [ <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:3> ] , managed_mapped_list . get_list ( '<STR_LIT:key>' ) ) <EOL> self . assertTrue ( managed_mapped_list . add_items ( '<STR_LIT:key>' , [ <NUM_LIT:2> , <NUM_LIT:3> ] ) ) <EOL> self . assertEqual ( [ <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:2> , <NUM_LIT:3> ] , managed_mapped_list . get_list ( '<STR_LIT:key>' ) ) <EOL> def test_set_and_remove_dedup ( self ) : <EOL> managed_mapped_list = ManagedMappedList ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> TEST_ZK_HOSTS , TEST_AWS_KEYFILE , TEST_S3_BUCKET ) <EOL> managed_mapped_list . set_list ( '<STR_LIT:key>' , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:2> ] ) <EOL> self . assertTrue ( managed_mapped_list . remove_list ( '<STR_LIT:key>' ) ) <EOL> self . assertEqual ( [ ] , managed_mapped_list . get_list ( '<STR_LIT:key>' ) ) <EOL> managed_mapped_list . set_list ( '<STR_LIT:key>' , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:2> ] ) <EOL> self . assertTrue ( managed_mapped_list . remove_item ( '<STR_LIT:key>' , <NUM_LIT:2> ) ) <EOL> self . assertEqual ( [ <NUM_LIT:1> , <NUM_LIT:3> ] , managed_mapped_list . get_list ( '<STR_LIT:key>' ) ) <EOL> managed_mapped_list . set_list ( '<STR_LIT:key>' , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:2> ] ) <EOL> self . assertTrue ( managed_mapped_list . remove_items ( '<STR_LIT:key>' , [ <NUM_LIT:2> , <NUM_LIT:3> ] ) ) <EOL> self . assertEqual ( [ <NUM_LIT:1> ] , managed_mapped_list . get_list ( '<STR_LIT:key>' ) ) <EOL> def test_set_and_remove ( self ) : <EOL> managed_mapped_list = ManagedMappedList ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> TEST_ZK_HOSTS , TEST_AWS_KEYFILE , TEST_S3_BUCKET , <EOL> dedup = False ) <EOL> managed_mapped_list . set_list ( '<STR_LIT:key>' , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:2> ] ) <EOL> self . assertTrue ( managed_mapped_list . remove_list ( '<STR_LIT:key>' ) ) <EOL> self . assertEqual ( [ ] , managed_mapped_list . get_list ( '<STR_LIT:key>' ) ) <EOL> managed_mapped_list . set_list ( '<STR_LIT:key>' , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:2> ] ) <EOL> self . assertTrue ( managed_mapped_list . remove_item ( '<STR_LIT:key>' , <NUM_LIT:2> ) ) <EOL> self . assertEqual ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:2> ] , managed_mapped_list . get_list ( '<STR_LIT:key>' ) ) <EOL> managed_mapped_list . set_list ( '<STR_LIT:key>' , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:2> ] ) <EOL> self . assertTrue ( managed_mapped_list . remove_items ( '<STR_LIT:key>' , [ <NUM_LIT:2> , <NUM_LIT:3> ] ) ) <EOL> self . assertEqual ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:2> ] , managed_mapped_list . get_list ( '<STR_LIT:key>' ) ) <EOL> def test_contains ( self ) : <EOL> managed_mapped_list = ManagedMappedList ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> TEST_ZK_HOSTS , TEST_AWS_KEYFILE , TEST_S3_BUCKET ) <EOL> managed_mapped_list . set_list ( '<STR_LIT:key>' , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:2> ] ) <EOL> self . assertTrue ( managed_mapped_list . contain_item ( '<STR_LIT:key>' , <NUM_LIT:2> ) ) <EOL> self . assertFalse ( managed_mapped_list . contain_item ( '<STR_LIT>' , <NUM_LIT:2> ) ) <EOL> self . assertFalse ( managed_mapped_list . contain_item ( '<STR_LIT:key>' , <NUM_LIT:4> ) ) <EOL> self . assertEqual ( [ <NUM_LIT:2> ] , managed_mapped_list . contain_items ( '<STR_LIT:key>' , [ <NUM_LIT:2> , <NUM_LIT:4> ] ) ) <EOL> self . assertEqual ( [ ] , managed_mapped_list . contain_items ( '<STR_LIT>' , [ <NUM_LIT:2> , <NUM_LIT:4> ] ) ) <EOL> self . assertEqual ( [ ] , managed_mapped_list . contain_items ( '<STR_LIT:key>' , [ <NUM_LIT:4> ] ) ) <EOL> def _update ( self ) : <EOL> pass <EOL> def test_callback ( self ) : <EOL> update_func = mock . Mock ( ) <EOL> _patch = mock . patch . object ( <EOL> self , '<STR_LIT>' , update_func ) <EOL> _patch . start ( ) <EOL> self . addCleanup ( _patch . stop ) <EOL> managed_mapped_list = ManagedMappedList ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> TEST_ZK_HOSTS , TEST_AWS_KEYFILE , TEST_S3_BUCKET , <EOL> update_callback = self . _update ) <EOL> self . assertTrue ( managed_mapped_list . zk_config_manager . update_zk ( '<STR_LIT:{}>' , '<STR_LIT>' ) ) <EOL> self . assertTrue ( update_func . is_called ) </s>
