<s> import mock <EOL> from sqlalchemy . orm import exc as orm_exception <EOL> from ec2api . api import validator <EOL> from ec2api . db import api as db_api <EOL> from ec2api import exception <EOL> from ec2api . tests . unit import base <EOL> from ec2api . tests . unit import fakes <EOL> from ec2api . tests . unit import matchers <EOL> class DbApiTestCase ( base . DbTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( DbApiTestCase , self ) . setUp ( ) <EOL> self . context = mock . NonCallableMock ( <EOL> project_id = fakes . random_os_id ( ) ) <EOL> self . other_context = mock . NonCallableMock ( <EOL> project_id = fakes . random_os_id ( ) ) <EOL> def test_add_item ( self ) : <EOL> new_item = { '<STR_LIT>' : fakes . random_os_id ( ) , <EOL> '<STR_LIT>' : fakes . random_ec2_id ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , <NUM_LIT> , True , { '<STR_LIT:key>' : '<STR_LIT>' } , [ ] ] } <EOL> item = db_api . add_item ( self . context , '<STR_LIT>' , new_item ) <EOL> self . assertIn ( '<STR_LIT:id>' , item ) <EOL> self . assertIsNotNone ( item [ '<STR_LIT:id>' ] ) <EOL> item_id = item . pop ( '<STR_LIT:id>' ) <EOL> self . assertTrue ( validator . validate_ec2_id ( item_id , '<STR_LIT>' , [ '<STR_LIT>' ] ) ) <EOL> self . assertThat ( item , matchers . DictMatches ( new_item , <EOL> orderless_lists = True ) ) <EOL> item = db_api . get_item_by_id ( self . context , item_id ) <EOL> new_item [ '<STR_LIT:id>' ] = item_id <EOL> self . assertThat ( item , matchers . DictMatches ( new_item , <EOL> orderless_lists = True ) ) <EOL> def test_add_item_defaults ( self ) : <EOL> def do_check ( new_item ) : <EOL> item = db_api . add_item ( self . context , '<STR_LIT>' , new_item ) <EOL> item_id = item . pop ( '<STR_LIT:id>' ) <EOL> if '<STR_LIT:id>' in new_item : <EOL> new_item_id = new_item . pop ( '<STR_LIT:id>' ) <EOL> self . assertNotEqual ( new_item_id , item_id ) <EOL> new_item . setdefault ( '<STR_LIT>' , None ) <EOL> new_item . setdefault ( '<STR_LIT>' , None ) <EOL> self . assertThat ( item , matchers . DictMatches ( new_item , <EOL> orderless_lists = True ) ) <EOL> do_check ( { } ) <EOL> do_check ( { '<STR_LIT>' : fakes . random_os_id ( ) } ) <EOL> do_check ( { '<STR_LIT>' : fakes . random_ec2_id ( '<STR_LIT>' ) } ) <EOL> do_check ( { '<STR_LIT:id>' : fakes . random_ec2_id ( '<STR_LIT>' ) } ) <EOL> def test_add_item_with_same_os_id ( self ) : <EOL> os_id = fakes . random_os_id ( ) <EOL> item1 = db_api . add_item ( self . context , '<STR_LIT>' , <EOL> { '<STR_LIT>' : os_id , <EOL> '<STR_LIT:key>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> item_id = item1 [ '<STR_LIT:id>' ] <EOL> item2 = db_api . add_item ( self . context , '<STR_LIT>' , <EOL> { '<STR_LIT>' : os_id , <EOL> '<STR_LIT:key>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> expected_item = { '<STR_LIT:id>' : item_id , <EOL> '<STR_LIT>' : os_id , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT:key>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> self . assertThat ( item2 , matchers . DictMatches ( expected_item ) ) <EOL> def test_add_item_isolation ( self ) : <EOL> os_id = fakes . random_os_id ( ) <EOL> db_api . add_item ( self . context , '<STR_LIT>' , { '<STR_LIT>' : os_id } ) <EOL> self . assertRaises ( <EOL> orm_exception . NoResultFound , <EOL> db_api . add_item , self . context , '<STR_LIT>' , { '<STR_LIT>' : os_id } ) <EOL> self . assertRaises ( <EOL> orm_exception . NoResultFound , <EOL> db_api . add_item , self . other_context , '<STR_LIT>' , { '<STR_LIT>' : os_id } ) <EOL> def test_add_item_id ( self ) : <EOL> os_id = fakes . random_os_id ( ) <EOL> item_id = db_api . add_item_id ( self . context , '<STR_LIT>' , os_id ) <EOL> self . assertTrue ( validator . validate_ec2_id ( item_id , '<STR_LIT>' , [ '<STR_LIT>' ] ) ) <EOL> item = db_api . get_item_by_id ( self . context , item_id ) <EOL> self . assertIsNone ( item ) <EOL> item = db_api . add_item ( self . context , '<STR_LIT>' , { '<STR_LIT>' : os_id } ) <EOL> self . assertThat ( item , matchers . DictMatches ( { '<STR_LIT:id>' : item_id , <EOL> '<STR_LIT>' : os_id , <EOL> '<STR_LIT>' : None } ) ) <EOL> item_id = db_api . add_item_id ( self . context , '<STR_LIT>' , os_id ) <EOL> self . assertEqual ( item_id , item [ '<STR_LIT:id>' ] ) <EOL> os_id = fakes . random_os_id ( ) <EOL> item_id1 = db_api . add_item_id ( self . context , '<STR_LIT>' , os_id ) <EOL> item_id2 = db_api . add_item_id ( self . context , '<STR_LIT>' , os_id ) <EOL> self . assertEqual ( item_id1 , item_id2 ) <EOL> def test_restore_item ( self ) : <EOL> os_id = fakes . random_os_id ( ) <EOL> item = { '<STR_LIT>' : os_id , '<STR_LIT:key>' : '<STR_LIT>' } <EOL> new_item = db_api . add_item ( self . context , '<STR_LIT>' , item ) <EOL> item [ '<STR_LIT:id>' ] = new_item [ '<STR_LIT:id>' ] <EOL> self . assertRaises ( <EOL> exception . EC2DBDuplicateEntry , <EOL> db_api . restore_item , self . context , '<STR_LIT>' , item ) <EOL> def test_update_item ( self ) : <EOL> item = db_api . add_item ( self . context , '<STR_LIT>' , { '<STR_LIT:key>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> item [ '<STR_LIT:key>' ] = '<STR_LIT>' <EOL> item . pop ( '<STR_LIT>' ) <EOL> item [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> item_id = item [ '<STR_LIT:id>' ] <EOL> db_api . update_item ( self . context , item ) <EOL> item = db_api . get_item_by_id ( self . context , item_id ) <EOL> self . assertThat ( item , matchers . DictMatches ( { '<STR_LIT:id>' : item_id , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT:key>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) ) <EOL> def test_update_item_invalid ( self ) : <EOL> self . assertRaises ( orm_exception . NoResultFound , <EOL> db_api . update_item , <EOL> self . context , <EOL> { '<STR_LIT:id>' : fakes . random_ec2_id ( '<STR_LIT>' ) , <EOL> '<STR_LIT:key>' : '<STR_LIT>' } ) <EOL> def test_update_item_os_id ( self ) : <EOL> item = db_api . add_item ( self . context , '<STR_LIT>' , { } ) <EOL> item [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> db_api . update_item ( self . context , item ) <EOL> item = db_api . get_item_by_id ( self . context , item [ '<STR_LIT:id>' ] ) <EOL> self . assertThat ( { '<STR_LIT>' : '<STR_LIT>' } , <EOL> matchers . IsSubDictOf ( item ) ) <EOL> item [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . assertRaises ( exception . EC2DBInvalidOsIdUpdate , <EOL> db_api . update_item , <EOL> self . context , item ) <EOL> item [ '<STR_LIT>' ] = None <EOL> self . assertRaises ( exception . EC2DBInvalidOsIdUpdate , <EOL> db_api . update_item , <EOL> self . context , item ) <EOL> def test_delete_item ( self ) : <EOL> item = db_api . add_item ( self . context , '<STR_LIT>' , { } ) <EOL> db_api . delete_item ( self . context , item [ '<STR_LIT:id>' ] ) <EOL> item = db_api . get_item_by_id ( self . context , item [ '<STR_LIT:id>' ] ) <EOL> self . assertIsNone ( item ) <EOL> db_api . delete_item ( self . context , fakes . random_ec2_id ( '<STR_LIT>' ) ) <EOL> item = db_api . add_item ( self . context , '<STR_LIT>' , { } ) <EOL> db_api . delete_item ( self . other_context , item [ '<STR_LIT:id>' ] ) <EOL> item = db_api . get_item_by_id ( self . context , item [ '<STR_LIT:id>' ] ) <EOL> self . assertIsNotNone ( item ) <EOL> def _setup_items ( self ) : <EOL> db_api . add_item ( self . context , '<STR_LIT>' , { } ) <EOL> db_api . add_item ( self . context , '<STR_LIT>' , { '<STR_LIT>' : True } ) <EOL> db_api . add_item ( self . context , '<STR_LIT>' , { '<STR_LIT>' : fakes . random_os_id ( ) } ) <EOL> db_api . add_item ( self . other_context , '<STR_LIT>' , { } ) <EOL> db_api . add_item ( self . other_context , '<STR_LIT>' , { '<STR_LIT>' : False } ) <EOL> db_api . add_item ( self . other_context , '<STR_LIT>' , { '<STR_LIT>' : True } ) <EOL> db_api . add_item ( self . other_context , '<STR_LIT>' , <EOL> { '<STR_LIT>' : False , <EOL> '<STR_LIT>' : fakes . random_os_id ( ) } ) <EOL> def test_get_items ( self ) : <EOL> self . _setup_items ( ) <EOL> items = db_api . get_items ( self . context , '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT:2> , len ( items ) ) <EOL> items = db_api . get_items ( self . context , '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( items ) ) <EOL> def test_get_item_by_id ( self ) : <EOL> self . _setup_items ( ) <EOL> item_id = db_api . get_items ( self . context , '<STR_LIT>' ) [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] <EOL> other_item_id = db_api . get_items ( self . other_context , '<STR_LIT>' ) [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] <EOL> item = db_api . get_item_by_id ( self . context , item_id ) <EOL> self . assertThat ( item , matchers . DictMatches ( { '<STR_LIT:id>' : item_id , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None } ) ) <EOL> item = db_api . get_item_by_id ( self . context , other_item_id ) <EOL> self . assertIsNone ( item ) <EOL> item = db_api . get_item_by_id ( self . context , fakes . random_ec2_id ( '<STR_LIT>' ) ) <EOL> self . assertIsNone ( item ) <EOL> def test_get_items_by_ids ( self ) : <EOL> self . _setup_items ( ) <EOL> fake_kind_items = db_api . get_items ( self . context , '<STR_LIT>' ) <EOL> fake1_kind_items = db_api . get_items ( self . context , '<STR_LIT>' ) <EOL> item_id = fake_kind_items [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] <EOL> other_item_id = db_api . get_items ( self . other_context , '<STR_LIT>' ) [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] <EOL> items = db_api . get_items_by_ids ( self . context , [ ] ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( items ) ) <EOL> items = db_api . get_items_by_ids ( self . context , set ( [ ] ) ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( items ) ) <EOL> items = db_api . get_items_by_ids ( self . context , <EOL> [ i [ '<STR_LIT:id>' ] for i in fake_kind_items ] ) <EOL> self . assertEqual ( <NUM_LIT:2> , len ( items ) ) <EOL> items = db_api . get_items_by_ids ( <EOL> self . context , ( fake_kind_items [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] , <EOL> fake1_kind_items [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] ) ) <EOL> self . assertEqual ( <NUM_LIT:2> , len ( items ) ) <EOL> items = db_api . get_items_by_ids ( self . context , ( item_id , ) ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( items ) ) <EOL> self . assertEqual ( item_id , items [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] ) <EOL> items = db_api . get_items_by_ids ( self . context , ( other_item_id , ) ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( items ) ) <EOL> items = db_api . get_items_by_ids ( self . context , <EOL> ( item_id , other_item_id ) ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( items ) ) <EOL> items = db_api . get_items_by_ids ( self . context , <EOL> ( fakes . random_ec2_id ( '<STR_LIT>' ) ) , ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( items ) ) <EOL> items = db_api . get_items_by_ids ( self . context , <EOL> ( item_id , fakes . random_ec2_id ( '<STR_LIT>' ) ) ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( items ) ) <EOL> def test_get_items_ids ( self ) : <EOL> self . _setup_items ( ) <EOL> item = db_api . get_items ( self . context , '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> other_item = db_api . get_items ( self . other_context , '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> items_ids = db_api . get_items_ids ( self . context , '<STR_LIT>' , <EOL> item_os_ids = [ item [ '<STR_LIT>' ] , <EOL> other_item [ '<STR_LIT>' ] ] ) <EOL> self . assertThat ( items_ids , <EOL> matchers . ListMatches ( <EOL> [ ( item [ '<STR_LIT:id>' ] , item [ '<STR_LIT>' ] ) , <EOL> ( other_item [ '<STR_LIT:id>' ] , other_item [ '<STR_LIT>' ] ) ] , <EOL> orderless_lists = True ) ) <EOL> items_ids = db_api . get_items_ids ( self . context , '<STR_LIT>' , <EOL> item_os_ids = [ item [ '<STR_LIT>' ] ] ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( items_ids ) ) <EOL> item_ids = db_api . get_items_ids ( self . context , '<STR_LIT>' , <EOL> item_ids = [ item [ '<STR_LIT:id>' ] , <EOL> other_item [ '<STR_LIT:id>' ] ] ) <EOL> self . assertThat ( item_ids , <EOL> matchers . ListMatches ( <EOL> [ ( item [ '<STR_LIT:id>' ] , item [ '<STR_LIT>' ] ) , <EOL> ( other_item [ '<STR_LIT:id>' ] , other_item [ '<STR_LIT>' ] ) ] , <EOL> orderless_lists = True ) ) <EOL> items_ids = db_api . get_items_ids ( self . context , '<STR_LIT>' , <EOL> item_ids = [ item [ '<STR_LIT:id>' ] ] ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( items_ids ) ) <EOL> def test_get_public_items ( self ) : <EOL> self . _setup_items ( ) <EOL> items = db_api . get_public_items ( self . context , '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT:2> , len ( items ) ) <EOL> public_item_ids = [ i [ '<STR_LIT:id>' ] for i in items ] <EOL> items = db_api . get_public_items ( self . context , '<STR_LIT>' , public_item_ids ) <EOL> self . assertEqual ( <NUM_LIT:2> , len ( items ) ) <EOL> items = db_api . get_public_items ( self . context , '<STR_LIT>' , <EOL> [ public_item_ids [ <NUM_LIT:0> ] ] ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( items ) ) <EOL> items = db_api . get_public_items ( self . context , '<STR_LIT>' , <EOL> ( public_item_ids [ <NUM_LIT:1> ] , ) ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( items ) ) <EOL> items = db_api . get_public_items ( self . context , '<STR_LIT>' , <EOL> [ public_item_ids [ <NUM_LIT:0> ] ] ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( items ) ) <EOL> items = db_api . get_public_items ( self . context , '<STR_LIT>' , <EOL> fakes . random_ec2_id ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( items ) ) <EOL> items = db_api . get_public_items ( self . context , '<STR_LIT>' , [ ] ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( items ) ) <EOL> def test_add_tags ( self ) : <EOL> item1_id = fakes . random_ec2_id ( '<STR_LIT>' ) <EOL> item2_id = fakes . random_ec2_id ( '<STR_LIT>' ) <EOL> item3_id = fakes . random_ec2_id ( '<STR_LIT>' ) <EOL> tag1_01 = { '<STR_LIT>' : item1_id , <EOL> '<STR_LIT:key>' : '<STR_LIT>' , <EOL> '<STR_LIT:value>' : None } <EOL> tag1_1 = { '<STR_LIT>' : item1_id , <EOL> '<STR_LIT:key>' : '<STR_LIT>' , <EOL> '<STR_LIT:value>' : '<STR_LIT>' } <EOL> tag1_2 = { '<STR_LIT>' : item1_id , <EOL> '<STR_LIT:key>' : '<STR_LIT>' , <EOL> '<STR_LIT:value>' : '<STR_LIT>' } <EOL> tag1_3 = { '<STR_LIT>' : item1_id , <EOL> '<STR_LIT:key>' : '<STR_LIT>' , <EOL> '<STR_LIT:value>' : '<STR_LIT>' } <EOL> tag2_1 = { '<STR_LIT>' : item2_id , <EOL> '<STR_LIT:key>' : '<STR_LIT>' , <EOL> '<STR_LIT:value>' : None } <EOL> tag2_2 = { '<STR_LIT>' : item2_id , <EOL> '<STR_LIT:key>' : '<STR_LIT>' , <EOL> '<STR_LIT:value>' : '<STR_LIT>' } <EOL> tag3_1 = { '<STR_LIT>' : item3_id , <EOL> '<STR_LIT:key>' : '<STR_LIT>' , <EOL> '<STR_LIT:value>' : '<STR_LIT>' } <EOL> tag3_3 = { '<STR_LIT>' : item3_id , <EOL> '<STR_LIT:key>' : '<STR_LIT>' , <EOL> '<STR_LIT:value>' : '<STR_LIT>' } <EOL> db_api . add_tags ( self . context , [ tag1_01 , tag2_1 , <EOL> tag1_2 , tag2_2 ] ) <EOL> db_api . add_tags ( self . context , [ tag1_1 , tag3_1 , <EOL> tag1_3 , tag3_3 ] ) <EOL> tags = db_api . get_tags ( self . context ) <EOL> self . assertThat ( tags , <EOL> matchers . ListMatches ( [ tag1_1 , tag1_2 , tag1_3 , <EOL> tag2_1 , tag2_2 , <EOL> tag3_1 , tag3_3 ] , <EOL> orderless_lists = True ) ) <EOL> def test_add_tags_isolation ( self ) : <EOL> item_id = fakes . random_ec2_id ( '<STR_LIT>' ) <EOL> tag1 = { '<STR_LIT>' : item_id , <EOL> '<STR_LIT:key>' : '<STR_LIT>' , <EOL> '<STR_LIT:value>' : '<STR_LIT>' } <EOL> tag2 = { '<STR_LIT>' : item_id , <EOL> '<STR_LIT:key>' : '<STR_LIT>' , <EOL> '<STR_LIT:value>' : '<STR_LIT>' } <EOL> db_api . add_tags ( self . context , [ tag1 , tag2 ] ) <EOL> db_api . add_tags ( self . other_context , [ { '<STR_LIT>' : item_id , <EOL> '<STR_LIT:key>' : '<STR_LIT>' , <EOL> '<STR_LIT:value>' : '<STR_LIT>' } , <EOL> { '<STR_LIT>' : item_id , <EOL> '<STR_LIT:key>' : '<STR_LIT>' , <EOL> '<STR_LIT:value>' : '<STR_LIT>' } ] ) <EOL> tags = db_api . get_tags ( self . context ) <EOL> self . assertThat ( tags , matchers . ListMatches ( [ tag1 , tag2 ] , <EOL> orderless_lists = True ) ) <EOL> def test_get_tags ( self ) : <EOL> item1_id = fakes . random_ec2_id ( '<STR_LIT>' ) <EOL> item2_id = fakes . random_ec2_id ( '<STR_LIT>' ) <EOL> item3_id = fakes . random_ec2_id ( '<STR_LIT>' ) <EOL> tag1 = { '<STR_LIT>' : item1_id , <EOL> '<STR_LIT:key>' : '<STR_LIT>' , <EOL> '<STR_LIT:value>' : '<STR_LIT>' } <EOL> tag2 = { '<STR_LIT>' : item2_id , <EOL> '<STR_LIT:key>' : '<STR_LIT>' , <EOL> '<STR_LIT:value>' : '<STR_LIT>' } <EOL> tag3 = { '<STR_LIT>' : item3_id , <EOL> '<STR_LIT:key>' : '<STR_LIT>' , <EOL> '<STR_LIT:value>' : '<STR_LIT>' } <EOL> db_api . add_tags ( self . context , [ tag1 , tag2 , tag3 ] ) <EOL> self . assertThat ( db_api . get_tags ( self . context ) , <EOL> matchers . ListMatches ( [ tag1 , tag2 , tag3 ] , <EOL> orderless_lists = True ) ) <EOL> self . assertThat ( db_api . get_tags ( self . context , ( '<STR_LIT>' , ) ) , <EOL> matchers . ListMatches ( [ tag1 , tag2 ] , <EOL> orderless_lists = True ) ) <EOL> self . assertThat ( db_api . get_tags ( self . context , ( '<STR_LIT>' , ) , <EOL> [ item1_id , item2_id ] ) , <EOL> matchers . ListMatches ( [ tag1 , tag2 ] , <EOL> orderless_lists = True ) ) <EOL> self . assertThat ( db_api . get_tags ( self . context , ( '<STR_LIT>' , ) , ( item1_id , ) ) , <EOL> matchers . ListMatches ( [ tag1 ] , <EOL> orderless_lists = True ) ) <EOL> self . assertThat ( db_api . get_tags ( self . context , ( '<STR_LIT>' , ) , ( item3_id , ) ) , <EOL> matchers . ListMatches ( [ ] ) ) <EOL> self . assertThat ( db_api . get_tags ( self . context , <EOL> item_ids = ( item1_id , item3_id ) ) , <EOL> matchers . ListMatches ( [ tag1 , tag3 ] , <EOL> orderless_lists = True ) ) <EOL> self . assertThat ( db_api . get_tags ( self . context , ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( item2_id , item3_id ) ) , <EOL> matchers . ListMatches ( [ tag2 , tag3 ] , <EOL> orderless_lists = True ) ) <EOL> def test_delete_tags ( self ) : <EOL> item1_id = fakes . random_ec2_id ( '<STR_LIT>' ) <EOL> item2_id = fakes . random_ec2_id ( '<STR_LIT>' ) <EOL> item3_id = fakes . random_ec2_id ( '<STR_LIT>' ) <EOL> tag1_1 = { '<STR_LIT>' : item1_id , <EOL> '<STR_LIT:key>' : '<STR_LIT>' , <EOL> '<STR_LIT:value>' : '<STR_LIT>' } <EOL> tag1_2 = { '<STR_LIT>' : item1_id , <EOL> '<STR_LIT:key>' : '<STR_LIT>' , <EOL> '<STR_LIT:value>' : '<STR_LIT>' } <EOL> tag2_1 = { '<STR_LIT>' : item2_id , <EOL> '<STR_LIT:key>' : '<STR_LIT>' , <EOL> '<STR_LIT:value>' : '<STR_LIT>' } <EOL> tag2_2 = { '<STR_LIT>' : item2_id , <EOL> '<STR_LIT:key>' : '<STR_LIT>' , <EOL> '<STR_LIT:value>' : '<STR_LIT>' } <EOL> tag3_1 = { '<STR_LIT>' : item3_id , <EOL> '<STR_LIT:key>' : '<STR_LIT>' , <EOL> '<STR_LIT:value>' : '<STR_LIT>' } <EOL> tag3_2 = { '<STR_LIT>' : item3_id , <EOL> '<STR_LIT:key>' : '<STR_LIT>' , <EOL> '<STR_LIT:value>' : '<STR_LIT>' } <EOL> db_api . add_tags ( self . context , [ tag1_1 , tag2_1 , tag3_1 , <EOL> tag1_2 , tag2_2 , tag3_2 ] ) <EOL> def do_check ( * tag_list ) : <EOL> self . assertThat ( db_api . get_tags ( self . context ) , <EOL> matchers . ListMatches ( tag_list , <EOL> orderless_lists = True ) ) <EOL> db_api . add_tags ( self . context , [ tag1_1 , tag2_1 , tag3_1 , <EOL> tag1_2 , tag2_2 , tag3_2 ] ) <EOL> db_api . delete_tags ( self . context , [ ] ) <EOL> do_check ( tag1_1 , tag1_2 , tag2_1 , tag2_2 , tag3_1 , tag3_2 ) <EOL> db_api . delete_tags ( self . context , [ item1_id ] ) <EOL> do_check ( tag2_1 , tag2_2 , tag3_1 , tag3_2 ) <EOL> db_api . delete_tags ( self . context , [ item1_id , item3_id ] ) <EOL> do_check ( tag2_1 , tag2_2 ) <EOL> db_api . delete_tags ( self . context , [ item1_id , item2_id , item3_id ] , <EOL> [ { '<STR_LIT:key>' : '<STR_LIT>' } , <EOL> { '<STR_LIT:value>' : '<STR_LIT>' } , <EOL> { '<STR_LIT:key>' : '<STR_LIT>' , <EOL> '<STR_LIT:value>' : '<STR_LIT>' } ] ) <EOL> do_check ( tag2_2 ) <EOL> def test_delete_tags_isolation ( self ) : <EOL> item_id = fakes . random_ec2_id ( '<STR_LIT>' ) <EOL> tag1 = { '<STR_LIT>' : item_id , <EOL> '<STR_LIT:key>' : '<STR_LIT:key>' , <EOL> '<STR_LIT:value>' : '<STR_LIT>' } <EOL> db_api . add_tags ( self . context , [ tag1 ] ) <EOL> tag2 = { '<STR_LIT>' : item_id , <EOL> '<STR_LIT:key>' : '<STR_LIT:key>' , <EOL> '<STR_LIT:value>' : '<STR_LIT>' } <EOL> db_api . add_tags ( self . other_context , [ tag2 ] ) <EOL> db_api . delete_tags ( self . context , item_id ) <EOL> self . assertThat ( db_api . get_tags ( self . other_context ) , <EOL> matchers . ListMatches ( [ tag2 ] ) ) </s>
