<s> """<STR_LIT>""" <EOL> from ironic . common import exception <EOL> from ironic . tests . unit . db import base <EOL> from ironic . tests . unit . db import utils as db_utils <EOL> class DbNodeTagTestCase ( base . DbTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( DbNodeTagTestCase , self ) . setUp ( ) <EOL> self . node = db_utils . create_test_node ( ) <EOL> def test_set_node_tags ( self ) : <EOL> tags = self . dbapi . set_node_tags ( self . node . id , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( self . node . id , tags [ <NUM_LIT:0> ] . node_id ) <EOL> self . assertItemsEqual ( [ '<STR_LIT>' , '<STR_LIT>' ] , [ tag . tag for tag in tags ] ) <EOL> tags = self . dbapi . set_node_tags ( self . node . id , [ ] ) <EOL> self . assertEqual ( [ ] , tags ) <EOL> def test_set_node_tags_duplicate ( self ) : <EOL> tags = self . dbapi . set_node_tags ( self . node . id , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( self . node . id , tags [ <NUM_LIT:0> ] . node_id ) <EOL> self . assertItemsEqual ( [ '<STR_LIT>' , '<STR_LIT>' ] , [ tag . tag for tag in tags ] ) <EOL> def test_set_node_tags_node_not_exist ( self ) : <EOL> self . assertRaises ( exception . NodeNotFound , <EOL> self . dbapi . set_node_tags , '<STR_LIT>' , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_get_node_tags_by_node_id ( self ) : <EOL> self . dbapi . set_node_tags ( self . node . id , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> tags = self . dbapi . get_node_tags_by_node_id ( self . node . id ) <EOL> self . assertEqual ( self . node . id , tags [ <NUM_LIT:0> ] . node_id ) <EOL> self . assertItemsEqual ( [ '<STR_LIT>' , '<STR_LIT>' ] , [ tag . tag for tag in tags ] ) <EOL> def test_get_node_tags_empty ( self ) : <EOL> tags = self . dbapi . get_node_tags_by_node_id ( self . node . id ) <EOL> self . assertEqual ( [ ] , tags ) <EOL> def test_get_node_tags_node_not_exist ( self ) : <EOL> self . assertRaises ( exception . NodeNotFound , <EOL> self . dbapi . get_node_tags_by_node_id , '<STR_LIT>' ) <EOL> def test_unset_node_tags ( self ) : <EOL> self . dbapi . set_node_tags ( self . node . id , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . dbapi . unset_node_tags ( self . node . id ) <EOL> tags = self . dbapi . get_node_tags_by_node_id ( self . node . id ) <EOL> self . assertEqual ( [ ] , tags ) <EOL> def test_unset_empty_node_tags ( self ) : <EOL> self . dbapi . unset_node_tags ( self . node . id ) <EOL> tags = self . dbapi . get_node_tags_by_node_id ( self . node . id ) <EOL> self . assertEqual ( [ ] , tags ) <EOL> def test_unset_node_tags_node_not_exist ( self ) : <EOL> self . assertRaises ( exception . NodeNotFound , <EOL> self . dbapi . unset_node_tags , '<STR_LIT>' ) <EOL> def test_add_node_tag ( self ) : <EOL> tag = self . dbapi . add_node_tag ( self . node . id , '<STR_LIT>' ) <EOL> self . assertEqual ( self . node . id , tag . node_id ) <EOL> self . assertEqual ( '<STR_LIT>' , tag . tag ) <EOL> def test_add_node_tag_duplicate ( self ) : <EOL> tag = self . dbapi . add_node_tag ( self . node . id , '<STR_LIT>' ) <EOL> tag = self . dbapi . add_node_tag ( self . node . id , '<STR_LIT>' ) <EOL> self . assertEqual ( self . node . id , tag . node_id ) <EOL> self . assertEqual ( '<STR_LIT>' , tag . tag ) <EOL> def test_add_node_tag_node_not_exist ( self ) : <EOL> self . assertRaises ( exception . NodeNotFound , <EOL> self . dbapi . add_node_tag , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def test_delete_node_tag ( self ) : <EOL> self . dbapi . set_node_tags ( self . node . id , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . dbapi . delete_node_tag ( self . node . id , '<STR_LIT>' ) <EOL> tags = self . dbapi . get_node_tags_by_node_id ( self . node . id ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( tags ) ) <EOL> self . assertEqual ( '<STR_LIT>' , tags [ <NUM_LIT:0> ] . tag ) <EOL> def test_delete_node_tag_not_found ( self ) : <EOL> self . assertRaises ( exception . NodeTagNotFound , <EOL> self . dbapi . delete_node_tag , self . node . id , '<STR_LIT>' ) <EOL> def test_delete_node_tag_node_not_found ( self ) : <EOL> self . assertRaises ( exception . NodeNotFound , <EOL> self . dbapi . delete_node_tag , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def test_node_tag_exists ( self ) : <EOL> self . dbapi . set_node_tags ( self . node . id , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> ret = self . dbapi . node_tag_exists ( self . node . id , '<STR_LIT>' ) <EOL> self . assertTrue ( ret ) <EOL> def test_node_tag_not_exists ( self ) : <EOL> ret = self . dbapi . node_tag_exists ( self . node . id , '<STR_LIT>' ) <EOL> self . assertFalse ( ret ) </s>
