<s> import datetime <EOL> from glance . common import context <EOL> from glance . common import exception <EOL> from glance . common import utils <EOL> from glance . registry import context as rcontext <EOL> from glance . registry . db import api as db_api <EOL> from glance . registry . db import models as db_models <EOL> from glance . tests . unit import base <EOL> from glance . tests import utils as test_utils <EOL> _gen_uuid = utils . generate_uuid <EOL> UUID1 = _gen_uuid ( ) <EOL> UUID2 = _gen_uuid ( ) <EOL> CONF = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False } <EOL> FIXTURES = [ <EOL> { '<STR_LIT:id>' : UUID1 , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : datetime . datetime . utcnow ( ) , <EOL> '<STR_LIT>' : datetime . datetime . utcnow ( ) , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT:location>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : { '<STR_LIT:type>' : '<STR_LIT>' } } , <EOL> { '<STR_LIT:id>' : UUID2 , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : datetime . datetime . utcnow ( ) , <EOL> '<STR_LIT>' : datetime . datetime . utcnow ( ) , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : <NUM_LIT:5> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT:location>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : { } } ] <EOL> class TestRegistryDb ( base . IsolatedUnitTest ) : <EOL> def setUp ( self ) : <EOL> """<STR_LIT>""" <EOL> super ( TestRegistryDb , self ) . setUp ( ) <EOL> conf = test_utils . TestConfigOpts ( CONF ) <EOL> self . adm_context = rcontext . RequestContext ( is_admin = True ) <EOL> self . context = rcontext . RequestContext ( is_admin = False ) <EOL> db_api . configure_db ( conf ) <EOL> self . destroy_fixtures ( ) <EOL> self . create_fixtures ( ) <EOL> def create_fixtures ( self ) : <EOL> for fixture in FIXTURES : <EOL> db_api . image_create ( self . adm_context , fixture ) <EOL> def destroy_fixtures ( self ) : <EOL> db_models . unregister_models ( db_api . _ENGINE ) <EOL> db_models . register_models ( db_api . _ENGINE ) <EOL> def test_image_get ( self ) : <EOL> image = db_api . image_get ( self . context , UUID1 ) <EOL> self . assertEquals ( image [ '<STR_LIT:id>' ] , FIXTURES [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] ) <EOL> def test_image_get_disallow_deleted ( self ) : <EOL> db_api . image_destroy ( self . adm_context , UUID1 ) <EOL> self . assertRaises ( exception . NotFound , db_api . image_get , <EOL> self . context , UUID1 ) <EOL> def test_image_get_allow_deleted ( self ) : <EOL> db_api . image_destroy ( self . adm_context , UUID1 ) <EOL> image = db_api . image_get ( self . adm_context , UUID1 ) <EOL> self . assertEquals ( image [ '<STR_LIT:id>' ] , FIXTURES [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] ) <EOL> def test_image_get_force_allow_deleted ( self ) : <EOL> db_api . image_destroy ( self . adm_context , UUID1 ) <EOL> image = db_api . image_get ( self . context , UUID1 , force_show_deleted = True ) <EOL> self . assertEquals ( image [ '<STR_LIT:id>' ] , FIXTURES [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] ) <EOL> def test_image_get_all ( self ) : <EOL> images = db_api . image_get_all ( self . context ) <EOL> self . assertEquals ( len ( images ) , <NUM_LIT:2> ) <EOL> def test_image_get_all_marker ( self ) : <EOL> images = db_api . image_get_all ( self . context , marker = UUID2 ) <EOL> self . assertEquals ( len ( images ) , <NUM_LIT:1> ) <EOL> def test_image_get_all_marker_deleted ( self ) : <EOL> """<STR_LIT>""" <EOL> db_api . image_destroy ( self . adm_context , UUID1 ) <EOL> filters = { '<STR_LIT>' : False } <EOL> self . assertRaises ( exception . NotFound , db_api . image_get_all , <EOL> self . context , marker = UUID1 , filters = filters ) <EOL> def test_image_get_all_marker_deleted_showing_deleted_as_admin ( self ) : <EOL> """<STR_LIT>""" <EOL> db_api . image_destroy ( self . adm_context , UUID1 ) <EOL> images = db_api . image_get_all ( self . adm_context , marker = UUID1 ) <EOL> self . assertEquals ( len ( images ) , <NUM_LIT:0> ) <EOL> def test_image_get_all_marker_deleted_showing_deleted ( self ) : <EOL> """<STR_LIT>""" <EOL> db_api . image_destroy ( self . adm_context , UUID1 ) <EOL> filters = { '<STR_LIT>' : True } <EOL> images = db_api . image_get_all ( self . context , marker = UUID1 , <EOL> filters = filters ) <EOL> self . assertEquals ( len ( images ) , <NUM_LIT:0> ) </s>
