<s> import pytest <EOL> import sys <EOL> import random <EOL> from . test_base_class import TestBaseClass <EOL> from aerospike import exception as e <EOL> aerospike = pytest . importorskip ( "<STR_LIT>" ) <EOL> try : <EOL> import aerospike <EOL> except : <EOL> print ( "<STR_LIT>" ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> class TestListInsert ( object ) : <EOL> def setup_class ( cls ) : <EOL> """<STR_LIT>""" <EOL> hostlist , user , password = TestBaseClass . get_hosts ( ) <EOL> config = { '<STR_LIT>' : hostlist } <EOL> if user is None and password is None : <EOL> TestListInsert . client = aerospike . client ( config ) . connect ( ) <EOL> else : <EOL> TestListInsert . client = aerospike . client ( <EOL> config ) . connect ( user , password ) <EOL> def teardown_class ( cls ) : <EOL> TestListInsert . client . close ( ) <EOL> def setup_method ( self , method ) : <EOL> for i in range ( <NUM_LIT:5> ) : <EOL> key = ( '<STR_LIT:test>' , '<STR_LIT>' , i ) <EOL> rec = { '<STR_LIT:name>' : '<STR_LIT>' % <EOL> ( str ( i ) ) , '<STR_LIT>' : [ i , i + <NUM_LIT:1> ] , '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] } <EOL> TestListInsert . client . put ( key , rec ) <EOL> key = ( '<STR_LIT:test>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> TestListInsert . client . put ( <EOL> key , { "<STR_LIT>" : bytearray ( "<STR_LIT>" , "<STR_LIT:utf-8>" ) } ) <EOL> def teardown_method ( self , method ) : <EOL> """<STR_LIT>""" <EOL> for i in range ( <NUM_LIT:5> ) : <EOL> key = ( '<STR_LIT:test>' , '<STR_LIT>' , i ) <EOL> TestListInsert . client . remove ( key ) <EOL> key = ( '<STR_LIT:test>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> TestListInsert . client . remove ( key ) <EOL> def test_list_insert_integer ( self ) : <EOL> """<STR_LIT>""" <EOL> key = ( '<STR_LIT:test>' , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> TestListInsert . client . list_insert ( key , "<STR_LIT>" , <NUM_LIT:0> , <NUM_LIT> ) <EOL> ( key , _ , bins ) = TestListInsert . client . get ( key ) <EOL> assert bins == { <EOL> '<STR_LIT>' : [ <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:2> ] , '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] } <EOL> def test_list_insert_string ( self ) : <EOL> """<STR_LIT>""" <EOL> key = ( '<STR_LIT:test>' , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> TestListInsert . client . list_insert ( key , "<STR_LIT>" , <NUM_LIT:0> , "<STR_LIT>" ) <EOL> ( key , _ , bins ) = TestListInsert . client . get ( key ) <EOL> assert bins == { <EOL> '<STR_LIT>' : [ <NUM_LIT:1> , <NUM_LIT:2> ] , '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] } <EOL> def test_list_insert_unicode_string ( self ) : <EOL> """<STR_LIT>""" <EOL> key = ( '<STR_LIT:test>' , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> TestListInsert . client . list_insert ( key , "<STR_LIT>" , <NUM_LIT:3> , u"<STR_LIT>" ) <EOL> key , _ , bins = TestListInsert . client . get ( key ) <EOL> assert bins == { <EOL> '<STR_LIT>' : [ <NUM_LIT:1> , <NUM_LIT:2> ] , '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' , None , u'<STR_LIT>' ] , <EOL> '<STR_LIT:name>' : '<STR_LIT>' } <EOL> def test_list_insert_list_with_correct_policy ( self ) : <EOL> """<STR_LIT>""" <EOL> key = ( '<STR_LIT:test>' , '<STR_LIT>' , <NUM_LIT:2> ) <EOL> policy = { <EOL> '<STR_LIT>' : <NUM_LIT:1000> , <EOL> '<STR_LIT>' : aerospike . POLICY_RETRY_ONCE , <EOL> '<STR_LIT>' : aerospike . POLICY_COMMIT_LEVEL_MASTER <EOL> } <EOL> TestListInsert . client . list_insert ( <EOL> key , "<STR_LIT>" , <NUM_LIT:5> , [ <NUM_LIT> , <NUM_LIT:50> , <NUM_LIT> ] , { } , policy ) <EOL> ( key , _ , bins ) = TestListInsert . client . get ( key ) <EOL> assert bins == { '<STR_LIT>' : [ <NUM_LIT:2> , <NUM_LIT:3> , None , None , None , [ <NUM_LIT> , <NUM_LIT:50> , <NUM_LIT> ] ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] , '<STR_LIT:name>' : '<STR_LIT>' } <EOL> def test_list_insert_float ( self ) : <EOL> """<STR_LIT>""" <EOL> key = ( '<STR_LIT:test>' , '<STR_LIT>' , <NUM_LIT:2> ) <EOL> TestListInsert . client . list_insert ( key , "<STR_LIT>" , <NUM_LIT:7> , <NUM_LIT> ) <EOL> ( key , _ , bins ) = TestListInsert . client . get ( key ) <EOL> assert bins == { '<STR_LIT>' : [ <NUM_LIT:2> , <NUM_LIT:3> , None , None , None , None , None , <NUM_LIT> ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] , '<STR_LIT:name>' : '<STR_LIT>' } <EOL> def test_list_insert_map ( self ) : <EOL> """<STR_LIT>""" <EOL> key = ( '<STR_LIT:test>' , '<STR_LIT>' , <NUM_LIT:3> ) <EOL> TestListInsert . client . list_insert ( key , "<STR_LIT>" , <NUM_LIT:1> , { '<STR_LIT>' : <NUM_LIT> } ) <EOL> ( key , _ , bins ) = TestListInsert . client . get ( key ) <EOL> assert bins == { <EOL> '<STR_LIT>' : [ <NUM_LIT:3> , { '<STR_LIT>' : <NUM_LIT> } , <NUM_LIT:4> ] , '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT:name>' : '<STR_LIT>' } <EOL> def test_list_insert_bytearray ( self ) : <EOL> """<STR_LIT>""" <EOL> key = ( '<STR_LIT:test>' , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> TestListInsert . client . list_insert ( <EOL> key , "<STR_LIT>" , <NUM_LIT:2> , bytearray ( "<STR_LIT>" , "<STR_LIT:utf-8>" ) ) <EOL> ( key , _ , bins ) = TestListInsert . client . get ( key ) <EOL> assert bins == { '<STR_LIT>' : [ <EOL> <NUM_LIT:1> , <NUM_LIT:2> , bytearray ( b"<STR_LIT>" ) ] , '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT:name>' : '<STR_LIT>' } <EOL> def test_list_insert_boolean ( self ) : <EOL> """<STR_LIT>""" <EOL> key = ( '<STR_LIT:test>' , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> TestListInsert . client . list_insert ( key , "<STR_LIT>" , <NUM_LIT:6> , False ) <EOL> ( key , _ , bins ) = TestListInsert . client . get ( key ) <EOL> assert bins == { '<STR_LIT>' : [ <NUM_LIT:1> , <NUM_LIT:2> , None , None , None , None , <NUM_LIT:0> ] , '<STR_LIT>' : [ <EOL> '<STR_LIT>' , '<STR_LIT>' ] , '<STR_LIT:name>' : '<STR_LIT>' } <EOL> def test_list_insert_with_nonexistent_key ( self ) : <EOL> """<STR_LIT>""" <EOL> charSet = '<STR_LIT>' <EOL> minLength = <NUM_LIT:5> <EOL> maxLength = <NUM_LIT:30> <EOL> length = random . randint ( minLength , maxLength ) <EOL> key = ( '<STR_LIT:test>' , '<STR_LIT>' , '<STR_LIT>' . join ( map ( lambda unused : <EOL> random . choice ( charSet ) , <EOL> range ( length ) ) ) + "<STR_LIT>" ) <EOL> status = TestListInsert . client . list_insert ( key , "<STR_LIT:abc>" , <NUM_LIT:2> , <NUM_LIT> ) <EOL> assert status == <NUM_LIT:0> <EOL> ( key , _ , bins ) = TestListInsert . client . get ( key ) <EOL> assert status == <NUM_LIT:0> <EOL> assert bins == { '<STR_LIT:abc>' : [ None , None , <NUM_LIT> ] } <EOL> TestListInsert . client . remove ( key ) <EOL> def test_list_insert_with_nonexistent_bin ( self ) : <EOL> """<STR_LIT>""" <EOL> key = ( '<STR_LIT:test>' , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> charSet = '<STR_LIT>' <EOL> minLength = <NUM_LIT:5> <EOL> maxLength = <NUM_LIT:10> <EOL> length = random . randint ( minLength , maxLength ) <EOL> bin = '<STR_LIT>' . join ( map ( lambda unused : <EOL> random . choice ( charSet ) , range ( length ) ) ) + "<STR_LIT>" <EOL> status = TestListInsert . client . list_insert ( key , bin , <NUM_LIT:3> , <NUM_LIT> ) <EOL> assert status == <NUM_LIT:0> <EOL> ( key , _ , bins ) = TestListInsert . client . get ( key ) <EOL> assert status == <NUM_LIT:0> <EOL> assert bins == { '<STR_LIT>' : [ <NUM_LIT:1> , <NUM_LIT:2> ] , '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> bin : [ None , None , None , <NUM_LIT> ] } <EOL> def test_list_insert_with_no_parameters ( self ) : <EOL> """<STR_LIT>""" <EOL> with pytest . raises ( TypeError ) as typeError : <EOL> TestListInsert . client . list_insert ( ) <EOL> assert "<STR_LIT>" in str ( <EOL> typeError . value ) <EOL> def test_list_insert_with_incorrect_policy ( self ) : <EOL> """<STR_LIT>""" <EOL> key = ( '<STR_LIT:test>' , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> policy = { <EOL> '<STR_LIT>' : <NUM_LIT:0.5> <EOL> } <EOL> try : <EOL> TestListInsert . client . list_insert ( key , "<STR_LIT>" , <NUM_LIT:6> , "<STR_LIT:str>" , { } , policy ) <EOL> except e . ParamError as exception : <EOL> assert exception . code == - <NUM_LIT:2> <EOL> assert exception . msg == "<STR_LIT>" <EOL> def test_list_insert_with_extra_parameter ( self ) : <EOL> """<STR_LIT>""" <EOL> key = ( '<STR_LIT:test>' , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> policy = { '<STR_LIT>' : <NUM_LIT:1000> } <EOL> with pytest . raises ( TypeError ) as typeError : <EOL> TestListInsert . client . list_insert ( <EOL> key , "<STR_LIT>" , <NUM_LIT:3> , <NUM_LIT> , { } , policy , "<STR_LIT>" ) <EOL> assert "<STR_LIT>" in str ( <EOL> typeError . value ) <EOL> def test_list_insert_policy_is_string ( self ) : <EOL> """<STR_LIT>""" <EOL> key = ( '<STR_LIT:test>' , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> try : <EOL> TestListInsert . client . list_insert ( key , "<STR_LIT>" , <NUM_LIT:1> , <NUM_LIT> , { } , "<STR_LIT>" ) <EOL> except e . ParamError as exception : <EOL> assert exception . code == - <NUM_LIT:2> <EOL> assert exception . msg == "<STR_LIT>" <EOL> def test_list_insert_key_is_none ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> TestListInsert . client . list_insert ( None , "<STR_LIT>" , <NUM_LIT:1> , <NUM_LIT> ) <EOL> except e . ParamError as exception : <EOL> assert exception . code == - <NUM_LIT:2> <EOL> assert exception . msg == "<STR_LIT>" <EOL> def test_list_insert_bin_is_none ( self ) : <EOL> """<STR_LIT>""" <EOL> key = ( '<STR_LIT:test>' , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> try : <EOL> TestListInsert . client . list_insert ( key , None , <NUM_LIT:2> , "<STR_LIT:str>" ) <EOL> except e . ParamError as exception : <EOL> assert exception . code == - <NUM_LIT:2> <EOL> assert exception . msg == "<STR_LIT>" <EOL> def test_list_insert_meta_type_integer ( self ) : <EOL> """<STR_LIT>""" <EOL> key = ( '<STR_LIT:test>' , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> try : <EOL> TestListInsert . client . list_insert ( key , "<STR_LIT>" , <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT> ) <EOL> except e . ParamError as exception : <EOL> assert exception . code == - <NUM_LIT:2> <EOL> assert exception . msg == "<STR_LIT>" <EOL> def test_list_insert_index_negative ( self ) : <EOL> """<STR_LIT>""" <EOL> key = ( '<STR_LIT:test>' , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> try : <EOL> TestListInsert . client . list_insert ( key , "<STR_LIT>" , - <NUM_LIT:6> , False ) <EOL> except e . InvalidRequest as exception : <EOL> assert exception . code == <NUM_LIT:4> <EOL> assert exception . msg == '<STR_LIT>' <EOL> def test_list_insert_index_type_string ( self ) : <EOL> """<STR_LIT>""" <EOL> key = ( '<STR_LIT:test>' , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> with pytest . raises ( TypeError ) as typeError : <EOL> TestListInsert . client . list_insert ( key , "<STR_LIT>" , "<STR_LIT>" , False ) <EOL> assert "<STR_LIT>" in str ( typeError . value ) </s>
