<s> import datetime <EOL> import json <EOL> import os <EOL> import StringIO <EOL> import tempfile <EOL> import unittest <EOL> import stubout <EOL> import webob <EOL> from glance import client <EOL> from glance . common import context <EOL> from glance . common import exception <EOL> from glance . common import utils <EOL> from glance . registry . db import api as db_api <EOL> from glance . registry . db import models as db_models <EOL> from glance . registry import client as rclient <EOL> from glance . registry import context as rcontext <EOL> from glance . tests import stubs <EOL> from glance . tests import utils as test_utils <EOL> from glance . tests . unit import base <EOL> CONF = { '<STR_LIT>' : '<STR_LIT>' } <EOL> _gen_uuid = utils . generate_uuid <EOL> UUID1 = _gen_uuid ( ) <EOL> UUID2 = _gen_uuid ( ) <EOL> class TestBadClients ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_bad_address ( self ) : <EOL> """<STR_LIT>""" <EOL> c = client . Client ( "<STR_LIT>" ) <EOL> self . assertRaises ( exception . ClientConnectionError , <EOL> c . get_image , <EOL> <NUM_LIT:1> ) <EOL> def test_ssl_no_key_file ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> c = client . Client ( "<STR_LIT>" , use_ssl = True ) <EOL> except exception . ClientConnectionError : <EOL> return <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_ssl_non_existing_key_file ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> c = client . Client ( "<STR_LIT>" , use_ssl = True , <EOL> key_file = '<STR_LIT>' ) <EOL> except exception . ClientConnectionError : <EOL> return <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_ssl_no_cert_file ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> with tempfile . NamedTemporaryFile ( ) as key_file : <EOL> key_file . write ( "<STR_LIT>" ) <EOL> key_file . flush ( ) <EOL> c = client . Client ( "<STR_LIT>" , use_ssl = True , <EOL> key_file = key_file . name ) <EOL> except exception . ClientConnectionError : <EOL> return <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_ssl_non_existing_cert_file ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> with tempfile . NamedTemporaryFile ( ) as key_file : <EOL> key_file . write ( "<STR_LIT>" ) <EOL> key_file . flush ( ) <EOL> c = client . Client ( "<STR_LIT>" , use_ssl = True , <EOL> key_file = key_file . name , <EOL> cert_file = '<STR_LIT>' ) <EOL> except exception . ClientConnectionError : <EOL> return <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_ssl_optional_ca_file ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> with tempfile . NamedTemporaryFile ( ) as key_file : <EOL> key_file . write ( "<STR_LIT>" ) <EOL> key_file . flush ( ) <EOL> with tempfile . NamedTemporaryFile ( ) as cert_file : <EOL> cert_file . write ( "<STR_LIT>" ) <EOL> cert_file . flush ( ) <EOL> c = client . Client ( "<STR_LIT>" , use_ssl = True , <EOL> key_file = key_file . name , <EOL> cert_file = cert_file . name ) <EOL> except exception . ClientConnectionError : <EOL> self . fail ( "<STR_LIT>" ) <EOL> class TestRegistryClient ( base . IsolatedUnitTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> """<STR_LIT>""" <EOL> super ( TestRegistryClient , self ) . setUp ( ) <EOL> db_api . configure_db ( self . conf ) <EOL> self . context = rcontext . RequestContext ( is_admin = True ) <EOL> self . 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: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:size>' : <NUM_LIT> , <EOL> '<STR_LIT:location>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : { } } ] <EOL> self . destroy_fixtures ( ) <EOL> self . create_fixtures ( ) <EOL> self . client = rclient . RegistryClient ( "<STR_LIT>" ) <EOL> def tearDown ( self ) : <EOL> """<STR_LIT>""" <EOL> super ( TestRegistryClient , self ) . tearDown ( ) <EOL> self . destroy_fixtures ( ) <EOL> def create_fixtures ( self ) : <EOL> for fixture in self . FIXTURES : <EOL> db_api . image_create ( self . 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_get_image_index ( self ) : <EOL> """<STR_LIT>""" <EOL> fixture = { <EOL> '<STR_LIT:id>' : UUID2 , <EOL> '<STR_LIT:name>' : '<STR_LIT>' <EOL> } <EOL> images = self . client . get_images ( ) <EOL> self . assertEquals ( len ( images ) , <NUM_LIT:1> ) <EOL> for k , v in fixture . items ( ) : <EOL> self . assertEquals ( v , images [ <NUM_LIT:0> ] [ k ] ) <EOL> def test_create_image_with_null_min_disk_min_ram ( self ) : <EOL> UUID3 = _gen_uuid ( ) <EOL> extra_fixture = { <EOL> '<STR_LIT:id>' : UUID3 , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> image = self . client . get_image ( UUID3 ) <EOL> self . assertEqual ( <NUM_LIT:0> , image [ "<STR_LIT>" ] ) <EOL> self . assertEqual ( <NUM_LIT:0> , image [ "<STR_LIT>" ] ) <EOL> def test_get_index_sort_name_asc ( self ) : <EOL> """<STR_LIT>""" <EOL> UUID3 = _gen_uuid ( ) <EOL> extra_fixture = { '<STR_LIT:id>' : UUID3 , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : None } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> UUID4 = _gen_uuid ( ) <EOL> extra_fixture = { '<STR_LIT:id>' : UUID4 , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT:20> , <EOL> '<STR_LIT>' : None } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> images = self . client . get_images ( sort_key = '<STR_LIT:name>' , sort_dir = '<STR_LIT>' ) <EOL> self . assertEquals ( len ( images ) , <NUM_LIT:3> ) <EOL> self . assertEquals ( images [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] , UUID3 ) <EOL> self . assertEquals ( images [ <NUM_LIT:1> ] [ '<STR_LIT:id>' ] , UUID2 ) <EOL> self . assertEquals ( images [ <NUM_LIT:2> ] [ '<STR_LIT:id>' ] , UUID4 ) <EOL> def test_get_index_sort_status_desc ( self ) : <EOL> """<STR_LIT>""" <EOL> UUID3 = _gen_uuid ( ) <EOL> extra_fixture = { '<STR_LIT:id>' : UUID3 , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : None } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> UUID4 = _gen_uuid ( ) <EOL> extra_fixture = { '<STR_LIT:id>' : UUID4 , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT:20> , <EOL> '<STR_LIT>' : None } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> images = self . client . get_images ( sort_key = '<STR_LIT:status>' , sort_dir = '<STR_LIT>' ) <EOL> self . assertEquals ( len ( images ) , <NUM_LIT:3> ) <EOL> self . assertEquals ( images [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] , UUID3 ) <EOL> self . assertEquals ( images [ <NUM_LIT:1> ] [ '<STR_LIT:id>' ] , UUID4 ) <EOL> self . assertEquals ( images [ <NUM_LIT:2> ] [ '<STR_LIT:id>' ] , UUID2 ) <EOL> def test_get_index_sort_disk_format_asc ( self ) : <EOL> """<STR_LIT>""" <EOL> UUID3 = _gen_uuid ( ) <EOL> extra_fixture = { '<STR_LIT:id>' : UUID3 , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : None } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> UUID4 = _gen_uuid ( ) <EOL> extra_fixture = { '<STR_LIT:id>' : UUID4 , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT:20> , <EOL> '<STR_LIT>' : None } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> images = self . client . get_images ( sort_key = '<STR_LIT>' , <EOL> sort_dir = '<STR_LIT>' ) <EOL> self . assertEquals ( len ( images ) , <NUM_LIT:3> ) <EOL> self . assertEquals ( images [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] , UUID3 ) <EOL> self . assertEquals ( images [ <NUM_LIT:1> ] [ '<STR_LIT:id>' ] , UUID4 ) <EOL> self . assertEquals ( images [ <NUM_LIT:2> ] [ '<STR_LIT:id>' ] , UUID2 ) <EOL> def test_get_index_sort_container_format_desc ( self ) : <EOL> """<STR_LIT>""" <EOL> UUID3 = _gen_uuid ( ) <EOL> extra_fixture = { '<STR_LIT:id>' : UUID3 , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : None } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> UUID4 = _gen_uuid ( ) <EOL> extra_fixture = { '<STR_LIT:id>' : UUID4 , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT:20> , <EOL> '<STR_LIT>' : None } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> images = self . client . get_images ( sort_key = '<STR_LIT>' , <EOL> sort_dir = '<STR_LIT>' ) <EOL> self . assertEquals ( len ( images ) , <NUM_LIT:3> ) <EOL> self . assertEquals ( images [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] , UUID2 ) <EOL> self . assertEquals ( images [ <NUM_LIT:1> ] [ '<STR_LIT:id>' ] , UUID4 ) <EOL> self . assertEquals ( images [ <NUM_LIT:2> ] [ '<STR_LIT:id>' ] , UUID3 ) <EOL> def test_get_index_sort_size_asc ( self ) : <EOL> """<STR_LIT>""" <EOL> UUID3 = _gen_uuid ( ) <EOL> extra_fixture = { '<STR_LIT:id>' : UUID3 , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT:100> , <EOL> '<STR_LIT>' : None } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> UUID4 = _gen_uuid ( ) <EOL> extra_fixture = { '<STR_LIT:id>' : UUID4 , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT:2> , <EOL> '<STR_LIT>' : None } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> images = self . client . get_images ( sort_key = '<STR_LIT:size>' , sort_dir = '<STR_LIT>' ) <EOL> self . assertEquals ( len ( images ) , <NUM_LIT:3> ) <EOL> self . assertEquals ( images [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] , UUID4 ) <EOL> self . assertEquals ( images [ <NUM_LIT:1> ] [ '<STR_LIT:id>' ] , UUID2 ) <EOL> self . assertEquals ( images [ <NUM_LIT:2> ] [ '<STR_LIT:id>' ] , UUID3 ) <EOL> def test_get_index_sort_created_at_asc ( self ) : <EOL> """<STR_LIT>""" <EOL> now = datetime . datetime . utcnow ( ) <EOL> time1 = now + datetime . timedelta ( seconds = <NUM_LIT:5> ) <EOL> time2 = now <EOL> UUID3 = _gen_uuid ( ) <EOL> extra_fixture = { '<STR_LIT:id>' : UUID3 , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : time1 } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> UUID4 = _gen_uuid ( ) <EOL> extra_fixture = { '<STR_LIT:id>' : UUID4 , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT:20> , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : time2 } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> images = self . client . get_images ( sort_key = '<STR_LIT>' , sort_dir = '<STR_LIT>' ) <EOL> self . assertEquals ( len ( images ) , <NUM_LIT:3> ) <EOL> self . assertEquals ( images [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] , UUID2 ) <EOL> self . assertEquals ( images [ <NUM_LIT:1> ] [ '<STR_LIT:id>' ] , UUID4 ) <EOL> self . assertEquals ( images [ <NUM_LIT:2> ] [ '<STR_LIT:id>' ] , UUID3 ) <EOL> def test_get_index_sort_updated_at_desc ( self ) : <EOL> """<STR_LIT>""" <EOL> now = datetime . datetime . utcnow ( ) <EOL> time1 = now + datetime . timedelta ( seconds = <NUM_LIT:5> ) <EOL> time2 = now <EOL> UUID3 = _gen_uuid ( ) <EOL> extra_fixture = { '<STR_LIT:id>' : UUID3 , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : time1 } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> UUID4 = _gen_uuid ( ) <EOL> extra_fixture = { '<STR_LIT:id>' : UUID4 , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT:20> , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : time2 } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> images = self . client . get_images ( sort_key = '<STR_LIT>' , sort_dir = '<STR_LIT>' ) <EOL> self . assertEquals ( len ( images ) , <NUM_LIT:3> ) <EOL> self . assertEquals ( images [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] , UUID3 ) <EOL> self . assertEquals ( images [ <NUM_LIT:1> ] [ '<STR_LIT:id>' ] , UUID4 ) <EOL> self . assertEquals ( images [ <NUM_LIT:2> ] [ '<STR_LIT:id>' ] , UUID2 ) <EOL> def test_get_image_index_marker ( self ) : <EOL> """<STR_LIT>""" <EOL> UUID3 = _gen_uuid ( ) <EOL> extra_fixture = { '<STR_LIT:id>' : UUID3 , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : None } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> UUID4 = _gen_uuid ( ) <EOL> extra_fixture = { '<STR_LIT:id>' : UUID4 , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : None } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> images = self . client . get_images ( marker = UUID4 ) <EOL> self . assertEquals ( len ( images ) , <NUM_LIT:2> ) <EOL> self . assertEquals ( images [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] , UUID3 ) <EOL> self . assertEquals ( images [ <NUM_LIT:1> ] [ '<STR_LIT:id>' ] , UUID2 ) <EOL> def test_get_image_index_invalid_marker ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertRaises ( exception . Invalid , <EOL> self . client . get_images , <EOL> marker = _gen_uuid ( ) ) <EOL> def test_get_image_index_limit ( self ) : <EOL> """<STR_LIT>""" <EOL> extra_fixture = { '<STR_LIT:id>' : _gen_uuid ( ) , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : None } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> extra_fixture = { '<STR_LIT:id>' : _gen_uuid ( ) , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : None } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> images = self . client . get_images ( limit = <NUM_LIT:2> ) <EOL> self . assertEquals ( len ( images ) , <NUM_LIT:2> ) <EOL> def test_get_image_index_marker_limit ( self ) : <EOL> """<STR_LIT>""" <EOL> UUID3 = _gen_uuid ( ) <EOL> extra_fixture = { '<STR_LIT:id>' : UUID3 , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : None } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> UUID4 = _gen_uuid ( ) <EOL> extra_fixture = { '<STR_LIT:id>' : UUID4 , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : None } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> images = self . client . get_images ( marker = UUID3 , limit = <NUM_LIT:1> ) <EOL> self . assertEquals ( len ( images ) , <NUM_LIT:1> ) <EOL> self . assertEquals ( images [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] , UUID2 ) <EOL> def test_get_image_index_limit_None ( self ) : <EOL> """<STR_LIT>""" <EOL> extra_fixture = { '<STR_LIT:id>' : _gen_uuid ( ) , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : None } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> extra_fixture = { '<STR_LIT:id>' : _gen_uuid ( ) , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : None } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> images = self . client . get_images ( limit = None ) <EOL> self . assertEquals ( len ( images ) , <NUM_LIT:3> ) <EOL> def test_get_image_index_by_name ( self ) : <EOL> """<STR_LIT>""" <EOL> extra_fixture = { '<STR_LIT:id>' : _gen_uuid ( ) , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : None } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> images = self . client . get_images ( filters = { '<STR_LIT:name>' : '<STR_LIT>' } ) <EOL> self . assertEquals ( len ( images ) , <NUM_LIT:1> ) <EOL> for image in images : <EOL> self . assertEquals ( '<STR_LIT>' , image [ '<STR_LIT:name>' ] ) <EOL> def test_get_image_details ( self ) : <EOL> """<STR_LIT>""" <EOL> fixture = { '<STR_LIT:id>' : UUID2 , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : { } } <EOL> images = self . client . get_images_detailed ( ) <EOL> self . assertEquals ( len ( images ) , <NUM_LIT:1> ) <EOL> for k , v in fixture . items ( ) : <EOL> self . assertEquals ( v , images [ <NUM_LIT:0> ] [ k ] ) <EOL> def test_get_image_details_marker_limit ( self ) : <EOL> """<STR_LIT>""" <EOL> UUID3 = _gen_uuid ( ) <EOL> extra_fixture = { '<STR_LIT:id>' : UUID3 , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : None } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> extra_fixture = { '<STR_LIT:id>' : _gen_uuid ( ) , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : None } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> images = self . client . get_images_detailed ( marker = UUID3 , limit = <NUM_LIT:1> ) <EOL> self . assertEquals ( len ( images ) , <NUM_LIT:1> ) <EOL> self . assertEquals ( images [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] , UUID2 ) <EOL> def test_get_image_details_invalid_marker ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertRaises ( exception . Invalid , <EOL> self . client . get_images_detailed , <EOL> marker = _gen_uuid ( ) ) <EOL> def test_get_image_details_by_name ( self ) : <EOL> """<STR_LIT>""" <EOL> extra_fixture = { '<STR_LIT:id>' : _gen_uuid ( ) , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : None } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> filters = { '<STR_LIT:name>' : '<STR_LIT>' } <EOL> images = self . client . get_images_detailed ( filters = filters ) <EOL> self . assertEquals ( len ( images ) , <NUM_LIT:1> ) <EOL> for image in images : <EOL> self . assertEquals ( '<STR_LIT>' , image [ '<STR_LIT:name>' ] ) <EOL> def test_get_image_details_by_status ( self ) : <EOL> """<STR_LIT>""" <EOL> extra_fixture = { '<STR_LIT:id>' : _gen_uuid ( ) , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : None } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> images = self . client . get_images_detailed ( filters = { '<STR_LIT:status>' : '<STR_LIT>' } ) <EOL> self . assertEquals ( len ( images ) , <NUM_LIT:1> ) <EOL> for image in images : <EOL> self . assertEquals ( '<STR_LIT>' , image [ '<STR_LIT:status>' ] ) <EOL> def test_get_image_details_by_container_format ( self ) : <EOL> """<STR_LIT>""" <EOL> extra_fixture = { '<STR_LIT:id>' : _gen_uuid ( ) , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : None } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> filters = { '<STR_LIT>' : '<STR_LIT>' } <EOL> images = self . client . get_images_detailed ( filters = filters ) <EOL> self . assertEquals ( len ( images ) , <NUM_LIT:2> ) <EOL> for image in images : <EOL> self . assertEquals ( '<STR_LIT>' , image [ '<STR_LIT>' ] ) <EOL> def test_get_image_details_by_disk_format ( self ) : <EOL> """<STR_LIT>""" <EOL> extra_fixture = { '<STR_LIT:id>' : _gen_uuid ( ) , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : None } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> filters = { '<STR_LIT>' : '<STR_LIT>' } <EOL> images = self . client . get_images_detailed ( filters = filters ) <EOL> self . assertEquals ( len ( images ) , <NUM_LIT:2> ) <EOL> for image in images : <EOL> self . assertEquals ( '<STR_LIT>' , image [ '<STR_LIT>' ] ) <EOL> def test_get_image_details_with_maximum_size ( self ) : <EOL> """<STR_LIT>""" <EOL> extra_fixture = { '<STR_LIT:id>' : _gen_uuid ( ) , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : None } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> images = self . client . get_images_detailed ( filters = { '<STR_LIT>' : <NUM_LIT:20> } ) <EOL> self . assertEquals ( len ( images ) , <NUM_LIT:1> ) <EOL> for image in images : <EOL> self . assertTrue ( image [ '<STR_LIT:size>' ] <= <NUM_LIT:20> ) <EOL> def test_get_image_details_with_minimum_size ( self ) : <EOL> """<STR_LIT>""" <EOL> extra_fixture = { '<STR_LIT:id>' : _gen_uuid ( ) , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT:20> , <EOL> '<STR_LIT>' : None } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> images = self . client . get_images_detailed ( filters = { '<STR_LIT>' : <NUM_LIT:20> } ) <EOL> self . assertEquals ( len ( images ) , <NUM_LIT:1> ) <EOL> for image in images : <EOL> self . assertTrue ( image [ '<STR_LIT:size>' ] >= <NUM_LIT:20> ) <EOL> def test_get_image_details_with_changes_since ( self ) : <EOL> """<STR_LIT>""" <EOL> dt1 = datetime . datetime . utcnow ( ) - datetime . timedelta ( <NUM_LIT:1> ) <EOL> iso1 = utils . isotime ( dt1 ) <EOL> dt2 = datetime . datetime . utcnow ( ) + datetime . timedelta ( <NUM_LIT:1> ) <EOL> iso2 = utils . isotime ( dt2 ) <EOL> dt3 = datetime . datetime . utcnow ( ) + datetime . timedelta ( <NUM_LIT:2> ) <EOL> iso3 = utils . isotime ( dt3 ) <EOL> dt4 = datetime . datetime . utcnow ( ) + datetime . timedelta ( <NUM_LIT:3> ) <EOL> iso4 = utils . isotime ( dt4 ) <EOL> UUID3 = _gen_uuid ( ) <EOL> extra_fixture = { '<STR_LIT:id>' : UUID3 , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : None } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> db_api . image_destroy ( self . context , <NUM_LIT:3> ) <EOL> UUID4 = _gen_uuid ( ) <EOL> extra_fixture = { '<STR_LIT:id>' : UUID4 , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT:20> , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : dt3 , <EOL> '<STR_LIT>' : dt3 } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> images = self . client . get_images_detailed ( filters = { } ) <EOL> self . assertEquals ( len ( images ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( images [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] , UUID4 ) <EOL> self . assertEqual ( images [ <NUM_LIT:1> ] [ '<STR_LIT:id>' ] , UUID2 ) <EOL> filters = { '<STR_LIT>' : iso1 } <EOL> images = self . client . get_images ( filters = filters ) <EOL> self . assertEquals ( len ( images ) , <NUM_LIT:3> ) <EOL> self . assertEqual ( images [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] , UUID4 ) <EOL> self . assertEqual ( images [ <NUM_LIT:1> ] [ '<STR_LIT:id>' ] , UUID3 ) <EOL> self . assertEqual ( images [ <NUM_LIT:2> ] [ '<STR_LIT:id>' ] , UUID2 ) <EOL> filters = { '<STR_LIT>' : iso2 } <EOL> images = self . client . get_images_detailed ( filters = filters ) <EOL> self . assertEquals ( len ( images ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( images [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] , UUID4 ) <EOL> filters = { '<STR_LIT>' : iso4 } <EOL> images = self . client . get_images ( filters = filters ) <EOL> self . assertEquals ( len ( images ) , <NUM_LIT:0> ) <EOL> def test_get_image_details_with_changes_since ( self ) : <EOL> """<STR_LIT>""" <EOL> extra_fixture = { '<STR_LIT:id>' : _gen_uuid ( ) , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT:20> , <EOL> '<STR_LIT>' : None } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> images = self . client . get_images_detailed ( filters = { '<STR_LIT>' : <NUM_LIT:20> } ) <EOL> self . assertEquals ( len ( images ) , <NUM_LIT:1> ) <EOL> for image in images : <EOL> self . assertTrue ( image [ '<STR_LIT:size>' ] >= <NUM_LIT:20> ) <EOL> def test_get_image_details_by_property ( self ) : <EOL> """<STR_LIT>""" <EOL> extra_fixture = { '<STR_LIT:id>' : _gen_uuid ( ) , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> filters = { '<STR_LIT>' : '<STR_LIT>' } <EOL> images = self . client . get_images_detailed ( filters = filters ) <EOL> self . assertEquals ( len ( images ) , <NUM_LIT:1> ) <EOL> for image in images : <EOL> self . assertEquals ( '<STR_LIT>' , image [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> def test_get_image_details_sort_disk_format_asc ( self ) : <EOL> """<STR_LIT>""" <EOL> UUID3 = _gen_uuid ( ) <EOL> extra_fixture = { '<STR_LIT:id>' : UUID3 , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : None } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> UUID4 = _gen_uuid ( ) <EOL> extra_fixture = { '<STR_LIT:id>' : UUID4 , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT:20> , <EOL> '<STR_LIT>' : None } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> images = self . client . get_images_detailed ( sort_key = '<STR_LIT>' , <EOL> sort_dir = '<STR_LIT>' ) <EOL> self . assertEquals ( len ( images ) , <NUM_LIT:3> ) <EOL> self . assertEquals ( images [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] , UUID3 ) <EOL> self . assertEquals ( images [ <NUM_LIT:1> ] [ '<STR_LIT:id>' ] , UUID4 ) <EOL> self . assertEquals ( images [ <NUM_LIT:2> ] [ '<STR_LIT:id>' ] , UUID2 ) <EOL> def test_get_image ( self ) : <EOL> """<STR_LIT>""" <EOL> fixture = { '<STR_LIT:id>' : UUID1 , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : { '<STR_LIT:type>' : '<STR_LIT>' } } <EOL> data = self . client . get_image ( UUID1 ) <EOL> for k , v in fixture . items ( ) : <EOL> el = data [ k ] <EOL> self . assertEquals ( v , data [ k ] , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % locals ( ) ) <EOL> def test_get_image_non_existing ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertRaises ( exception . NotFound , <EOL> self . client . get_image , <EOL> _gen_uuid ( ) ) <EOL> def test_add_image_basic ( self ) : <EOL> """<STR_LIT>""" <EOL> fixture = { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> } <EOL> new_image = self . client . add_image ( fixture ) <EOL> data = self . client . get_image ( new_image [ '<STR_LIT:id>' ] ) <EOL> for k , v in fixture . items ( ) : <EOL> self . assertEquals ( v , data [ k ] ) <EOL> self . assertTrue ( '<STR_LIT:status>' in data . keys ( ) ) <EOL> self . assertEquals ( '<STR_LIT>' , data [ '<STR_LIT:status>' ] ) <EOL> def test_add_image_with_properties ( self ) : <EOL> """<STR_LIT>""" <EOL> fixture = { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT:location>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } } <EOL> new_image = self . client . add_image ( fixture ) <EOL> del fixture [ '<STR_LIT:location>' ] <EOL> for k , v in fixture . items ( ) : <EOL> self . assertEquals ( v , new_image [ k ] ) <EOL> self . assertTrue ( '<STR_LIT:status>' in new_image . keys ( ) ) <EOL> self . assertEquals ( '<STR_LIT>' , new_image [ '<STR_LIT:status>' ] ) <EOL> def test_add_image_already_exists ( self ) : <EOL> """<STR_LIT>""" <EOL> fixture = { '<STR_LIT:id>' : UUID2 , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT:location>' : "<STR_LIT>" , <EOL> } <EOL> self . assertRaises ( exception . Duplicate , <EOL> self . client . add_image , <EOL> fixture ) <EOL> def test_add_image_with_bad_status ( self ) : <EOL> """<STR_LIT>""" <EOL> fixture = { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT:location>' : "<STR_LIT>" , <EOL> } <EOL> self . assertRaises ( exception . Invalid , <EOL> self . client . add_image , <EOL> fixture ) <EOL> def test_update_image ( self ) : <EOL> """<STR_LIT>""" <EOL> fixture = { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> self . assertTrue ( self . client . update_image ( UUID2 , fixture ) ) <EOL> data = self . client . get_image ( UUID2 ) <EOL> for k , v in fixture . items ( ) : <EOL> self . assertEquals ( v , data [ k ] ) <EOL> def test_update_image_not_existing ( self ) : <EOL> """<STR_LIT>""" <EOL> fixture = { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> } <EOL> self . assertRaises ( exception . NotFound , <EOL> self . client . update_image , <EOL> _gen_uuid ( ) , <EOL> fixture ) <EOL> def test_delete_image ( self ) : <EOL> """<STR_LIT>""" <EOL> orig_num_images = len ( self . client . get_images ( ) ) <EOL> self . assertTrue ( self . client . delete_image ( UUID2 ) ) <EOL> new_num_images = len ( self . client . get_images ( ) ) <EOL> self . assertEquals ( new_num_images , orig_num_images - <NUM_LIT:1> ) <EOL> def test_delete_image_not_existing ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertRaises ( exception . NotFound , <EOL> self . client . delete_image , <EOL> _gen_uuid ( ) ) <EOL> def test_get_image_members ( self ) : <EOL> """<STR_LIT>""" <EOL> memb_list = self . client . get_image_members ( UUID2 ) <EOL> num_members = len ( memb_list ) <EOL> self . assertEquals ( num_members , <NUM_LIT:0> ) <EOL> def test_get_image_members_not_existing ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertRaises ( exception . NotFound , <EOL> self . client . get_image_members , <EOL> _gen_uuid ( ) ) <EOL> def test_get_member_images ( self ) : <EOL> """<STR_LIT>""" <EOL> memb_list = self . client . get_member_images ( '<STR_LIT>' ) <EOL> num_members = len ( memb_list ) <EOL> self . assertEquals ( num_members , <NUM_LIT:0> ) <EOL> def test_replace_members ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertRaises ( exception . NotAuthorized , <EOL> self . client . replace_members , UUID2 , <EOL> dict ( member_id = '<STR_LIT>' ) ) <EOL> def test_add_member ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertRaises ( exception . NotAuthorized , <EOL> self . client . add_member , UUID2 , '<STR_LIT>' ) <EOL> def test_delete_member ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertRaises ( exception . NotAuthorized , <EOL> self . client . delete_member , UUID2 , '<STR_LIT>' ) <EOL> class TestClient ( base . IsolatedUnitTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> """<STR_LIT>""" <EOL> super ( TestClient , self ) . setUp ( ) <EOL> db_api . configure_db ( self . conf ) <EOL> self . client = client . Client ( "<STR_LIT>" ) <EOL> self . 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:size>' : <NUM_LIT> , <EOL> '<STR_LIT:location>' : "<STR_LIT>" % ( self . test_dir , UUID1 ) , <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:size>' : <NUM_LIT> , <EOL> '<STR_LIT:location>' : "<STR_LIT>" % ( self . test_dir , UUID2 ) , <EOL> '<STR_LIT>' : { } } ] <EOL> self . context = rcontext . RequestContext ( is_admin = True ) <EOL> self . destroy_fixtures ( ) <EOL> self . create_fixtures ( ) <EOL> def tearDown ( self ) : <EOL> """<STR_LIT>""" <EOL> super ( TestClient , self ) . tearDown ( ) <EOL> self . destroy_fixtures ( ) <EOL> def create_fixtures ( self ) : <EOL> for fixture in self . FIXTURES : <EOL> db_api . image_create ( self . context , fixture ) <EOL> with open ( "<STR_LIT>" % ( self . test_dir , fixture [ '<STR_LIT:id>' ] ) , '<STR_LIT:wb>' ) as image : <EOL> image . write ( "<STR_LIT>" ) <EOL> image . flush ( ) <EOL> def destroy_fixtures ( self ) : <EOL> db_models . unregister_models ( db_api . _ENGINE ) <EOL> db_models . register_models ( db_api . _ENGINE ) <EOL> def test_get_image ( self ) : <EOL> """<STR_LIT>""" <EOL> expected_image = '<STR_LIT>' <EOL> expected_meta = { '<STR_LIT:id>' : UUID2 , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : { } } <EOL> meta , image_chunks = self . client . get_image ( UUID2 ) <EOL> image_data = "<STR_LIT>" <EOL> for image_chunk in image_chunks : <EOL> image_data += image_chunk <EOL> self . assertEquals ( expected_image , image_data ) <EOL> for k , v in expected_meta . items ( ) : <EOL> self . assertEquals ( v , meta [ k ] ) <EOL> def test_get_image_not_existing ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertRaises ( exception . NotFound , <EOL> self . client . get_image , <EOL> _gen_uuid ( ) ) <EOL> def test_get_image_index_sort_container_format_desc ( self ) : <EOL> """<STR_LIT>""" <EOL> UUID3 = _gen_uuid ( ) <EOL> extra_fixture = { '<STR_LIT:id>' : UUID3 , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : None } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> UUID4 = _gen_uuid ( ) <EOL> extra_fixture = { '<STR_LIT:id>' : UUID4 , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT:20> , <EOL> '<STR_LIT>' : None } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> images = self . client . get_images ( sort_key = '<STR_LIT>' , <EOL> sort_dir = '<STR_LIT>' ) <EOL> self . assertEquals ( len ( images ) , <NUM_LIT:3> ) <EOL> self . assertEquals ( images [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] , UUID2 ) <EOL> self . assertEquals ( images [ <NUM_LIT:1> ] [ '<STR_LIT:id>' ] , UUID4 ) <EOL> self . assertEquals ( images [ <NUM_LIT:2> ] [ '<STR_LIT:id>' ] , UUID3 ) <EOL> def test_get_image_index ( self ) : <EOL> """<STR_LIT>""" <EOL> fixture = { '<STR_LIT:id>' : UUID2 , <EOL> '<STR_LIT:name>' : '<STR_LIT>' } <EOL> images = self . client . get_images ( ) <EOL> self . assertEquals ( len ( images ) , <NUM_LIT:1> ) <EOL> for k , v in fixture . items ( ) : <EOL> self . assertEquals ( v , images [ <NUM_LIT:0> ] [ k ] ) <EOL> def test_get_image_index_marker ( self ) : <EOL> """<STR_LIT>""" <EOL> UUID3 = _gen_uuid ( ) <EOL> extra_fixture = { '<STR_LIT:id>' : UUID3 , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : None } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> UUID4 = _gen_uuid ( ) <EOL> extra_fixture = { '<STR_LIT:id>' : UUID4 , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : None } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> images = self . client . get_images ( marker = UUID4 ) <EOL> self . assertEquals ( len ( images ) , <NUM_LIT:2> ) <EOL> self . assertEquals ( images [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] , UUID3 ) <EOL> self . assertEquals ( images [ <NUM_LIT:1> ] [ '<STR_LIT:id>' ] , UUID2 ) <EOL> def test_get_image_index_invalid_marker ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertRaises ( exception . Invalid , <EOL> self . client . get_images , <EOL> marker = _gen_uuid ( ) ) <EOL> def test_get_image_index_limit ( self ) : <EOL> """<STR_LIT>""" <EOL> extra_fixture = { '<STR_LIT:id>' : _gen_uuid ( ) , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : None } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> extra_fixture = { '<STR_LIT:id>' : _gen_uuid ( ) , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : None } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> images = self . client . get_images ( limit = <NUM_LIT:2> ) <EOL> self . assertEquals ( len ( images ) , <NUM_LIT:2> ) <EOL> def test_get_image_index_marker_limit ( self ) : <EOL> """<STR_LIT>""" <EOL> UUID3 = _gen_uuid ( ) <EOL> extra_fixture = { '<STR_LIT:id>' : UUID3 , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : None } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> extra_fixture = { '<STR_LIT:id>' : _gen_uuid ( ) , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : None } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> images = self . client . get_images ( marker = UUID3 , limit = <NUM_LIT:1> ) <EOL> self . assertEquals ( len ( images ) , <NUM_LIT:1> ) <EOL> self . assertEquals ( images [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] , UUID2 ) <EOL> def test_get_image_index_by_base_attribute ( self ) : <EOL> """<STR_LIT>""" <EOL> extra_fixture = { '<STR_LIT:id>' : _gen_uuid ( ) , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : None } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> filters = { '<STR_LIT:name>' : '<STR_LIT>' } <EOL> images = self . client . get_images ( filters = filters ) <EOL> self . assertEquals ( len ( images ) , <NUM_LIT:1> ) <EOL> self . assertEquals ( '<STR_LIT>' , images [ <NUM_LIT:0> ] [ '<STR_LIT:name>' ] ) <EOL> def test_get_image_index_by_property ( self ) : <EOL> """<STR_LIT>""" <EOL> UUID3 = _gen_uuid ( ) <EOL> extra_fixture = { '<STR_LIT:id>' : UUID3 , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> filters = { '<STR_LIT>' : '<STR_LIT>' } <EOL> images = self . client . get_images ( filters = filters ) <EOL> self . assertEquals ( len ( images ) , <NUM_LIT:1> ) <EOL> self . assertEquals ( images [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] , UUID3 ) <EOL> def test_get_image_details ( self ) : <EOL> """<STR_LIT>""" <EOL> expected = { '<STR_LIT:id>' : UUID2 , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : { } } <EOL> images = self . client . get_images_detailed ( ) <EOL> self . assertEquals ( len ( images ) , <NUM_LIT:1> ) <EOL> for k , v in expected . items ( ) : <EOL> self . assertEquals ( v , images [ <NUM_LIT:0> ] [ k ] ) <EOL> def test_get_image_details_marker_limit ( self ) : <EOL> """<STR_LIT>""" <EOL> UUID3 = _gen_uuid ( ) <EOL> extra_fixture = { '<STR_LIT:id>' : UUID3 , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : None } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> extra_fixture = { '<STR_LIT:id>' : _gen_uuid ( ) , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : None } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> images = self . client . get_images_detailed ( marker = UUID3 , limit = <NUM_LIT:1> ) <EOL> self . assertEquals ( len ( images ) , <NUM_LIT:1> ) <EOL> self . assertEquals ( images [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] , UUID2 ) <EOL> def test_get_image_details_invalid_marker ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertRaises ( exception . Invalid , <EOL> self . client . get_images_detailed , <EOL> marker = _gen_uuid ( ) ) <EOL> def test_get_image_details_by_base_attribute ( self ) : <EOL> """<STR_LIT>""" <EOL> extra_fixture = { '<STR_LIT:id>' : _gen_uuid ( ) , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : None } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> filters = { '<STR_LIT:name>' : '<STR_LIT>' } <EOL> images = self . client . get_images_detailed ( filters = filters ) <EOL> self . assertEquals ( len ( images ) , <NUM_LIT:1> ) <EOL> for image in images : <EOL> self . assertEquals ( '<STR_LIT>' , image [ '<STR_LIT:name>' ] ) <EOL> def test_get_image_details_with_changes_since ( self ) : <EOL> """<STR_LIT>""" <EOL> dt1 = datetime . datetime . utcnow ( ) - datetime . timedelta ( <NUM_LIT:1> ) <EOL> iso1 = utils . isotime ( dt1 ) <EOL> dt2 = datetime . datetime . utcnow ( ) + datetime . timedelta ( <NUM_LIT:1> ) <EOL> iso2 = utils . isotime ( dt2 ) <EOL> dt3 = datetime . datetime . utcnow ( ) + datetime . timedelta ( <NUM_LIT:2> ) <EOL> iso3 = utils . isotime ( dt3 ) <EOL> dt4 = datetime . datetime . utcnow ( ) + datetime . timedelta ( <NUM_LIT:3> ) <EOL> iso4 = utils . isotime ( dt4 ) <EOL> UUID3 = _gen_uuid ( ) <EOL> extra_fixture = { '<STR_LIT:id>' : UUID3 , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : None } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> db_api . image_destroy ( self . context , UUID3 ) <EOL> UUID4 = _gen_uuid ( ) <EOL> extra_fixture = { '<STR_LIT:id>' : UUID4 , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT:20> , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : dt3 , <EOL> '<STR_LIT>' : dt3 } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> images = self . client . get_images_detailed ( filters = { } ) <EOL> self . assertEquals ( len ( images ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( images [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] , UUID4 ) <EOL> self . assertEqual ( images [ <NUM_LIT:1> ] [ '<STR_LIT:id>' ] , UUID2 ) <EOL> filters = { '<STR_LIT>' : iso1 } <EOL> images = self . client . get_images ( filters = filters ) <EOL> self . assertEquals ( len ( images ) , <NUM_LIT:3> ) <EOL> self . assertEqual ( images [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] , UUID4 ) <EOL> self . assertEqual ( images [ <NUM_LIT:1> ] [ '<STR_LIT:id>' ] , UUID3 ) <EOL> self . assertEqual ( images [ <NUM_LIT:2> ] [ '<STR_LIT:id>' ] , UUID2 ) <EOL> filters = { '<STR_LIT>' : iso2 } <EOL> images = self . client . get_images_detailed ( filters = filters ) <EOL> self . assertEquals ( len ( images ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( images [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] , UUID4 ) <EOL> filters = { '<STR_LIT>' : iso4 } <EOL> images = self . client . get_images ( filters = filters ) <EOL> self . assertEquals ( len ( images ) , <NUM_LIT:0> ) <EOL> def test_get_image_details_by_property ( self ) : <EOL> """<STR_LIT>""" <EOL> extra_fixture = { '<STR_LIT:id>' : _gen_uuid ( ) , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> filters = { '<STR_LIT>' : '<STR_LIT>' } <EOL> images = self . client . get_images_detailed ( filters = filters ) <EOL> self . assertEquals ( len ( images ) , <NUM_LIT:1> ) <EOL> for image in images : <EOL> self . assertEquals ( '<STR_LIT>' , image [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> def test_get_image_bad_filters_with_other_params ( self ) : <EOL> """<STR_LIT>""" <EOL> extra_fixture = { '<STR_LIT:id>' : _gen_uuid ( ) , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } } <EOL> db_api . image_create ( self . context , extra_fixture ) <EOL> images = self . client . get_images_detailed ( filters = None , limit = <NUM_LIT:1> ) <EOL> self . assertEquals ( len ( images ) , <NUM_LIT:1> ) <EOL> def test_get_image_meta ( self ) : <EOL> """<STR_LIT>""" <EOL> fixture = { '<STR_LIT:id>' : UUID2 , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : { } } <EOL> data = self . client . get_image_meta ( UUID2 ) <EOL> for k , v in fixture . items ( ) : <EOL> self . assertEquals ( v , data [ k ] ) <EOL> def test_get_image_iso_meta ( self ) : <EOL> """<STR_LIT>""" <EOL> fixture = { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT:location>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : { } } <EOL> new_image = self . client . add_image ( fixture ) <EOL> new_image_id = new_image [ '<STR_LIT:id>' ] <EOL> data = self . client . get_image_meta ( new_image_id ) <EOL> del fixture [ '<STR_LIT:location>' ] <EOL> for k , v in fixture . items ( ) : <EOL> self . assertEquals ( v , data [ k ] ) <EOL> def test_get_image_non_existing ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertRaises ( exception . NotFound , <EOL> self . client . get_image , <EOL> _gen_uuid ( ) ) <EOL> def test_add_image_without_location_or_raw_data ( self ) : <EOL> """<STR_LIT>""" <EOL> fixture = { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> image_meta = self . client . add_image ( fixture ) <EOL> self . assertEquals ( '<STR_LIT>' , image_meta [ '<STR_LIT:status>' ] ) <EOL> self . assertEquals ( <NUM_LIT:0> , image_meta [ '<STR_LIT:size>' ] ) <EOL> def test_add_image_basic ( self ) : <EOL> """<STR_LIT>""" <EOL> fixture = { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT:location>' : "<STR_LIT>" , <EOL> } <EOL> new_image = self . client . add_image ( fixture ) <EOL> new_image_id = new_image [ '<STR_LIT:id>' ] <EOL> data = self . client . get_image_meta ( new_image_id ) <EOL> del fixture [ '<STR_LIT:location>' ] <EOL> for k , v in fixture . items ( ) : <EOL> self . assertEquals ( v , data [ k ] ) <EOL> self . assertTrue ( '<STR_LIT:status>' in data . keys ( ) ) <EOL> self . assertEquals ( '<STR_LIT>' , data [ '<STR_LIT:status>' ] ) <EOL> def test_add_image_with_properties ( self ) : <EOL> """<STR_LIT>""" <EOL> fixture = { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT:location>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } , <EOL> } <EOL> new_image = self . client . add_image ( fixture ) <EOL> new_image_id = new_image [ '<STR_LIT:id>' ] <EOL> data = self . client . get_image_meta ( new_image_id ) <EOL> del fixture [ '<STR_LIT:location>' ] <EOL> for k , v in fixture . items ( ) : <EOL> self . assertEquals ( v , data [ k ] ) <EOL> self . assertTrue ( '<STR_LIT:status>' in data ) <EOL> self . assertEquals ( '<STR_LIT>' , data [ '<STR_LIT:status>' ] ) <EOL> def test_add_image_with_iso_properties ( self ) : <EOL> """<STR_LIT>""" <EOL> fixture = { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT:location>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } , <EOL> } <EOL> new_image = self . client . add_image ( fixture ) <EOL> new_image_id = new_image [ '<STR_LIT:id>' ] <EOL> data = self . client . get_image_meta ( new_image_id ) <EOL> del fixture [ '<STR_LIT:location>' ] <EOL> for k , v in fixture . items ( ) : <EOL> self . assertEquals ( v , data [ k ] ) <EOL> self . assertTrue ( '<STR_LIT:status>' in data ) <EOL> self . assertEquals ( '<STR_LIT>' , data [ '<STR_LIT:status>' ] ) <EOL> def test_add_image_with_bad_iso_properties ( self ) : <EOL> """<STR_LIT>""" <EOL> fixture = { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT:location>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } , <EOL> } <EOL> self . assertRaises ( exception . Invalid , <EOL> self . client . add_image , <EOL> fixture ) <EOL> def test_add_image_already_exists ( self ) : <EOL> """<STR_LIT>""" <EOL> fixture = { '<STR_LIT:id>' : UUID2 , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT:location>' : "<STR_LIT>" , <EOL> } <EOL> self . assertRaises ( exception . Duplicate , <EOL> self . client . add_image , <EOL> fixture ) <EOL> def test_add_image_with_bad_status ( self ) : <EOL> """<STR_LIT>""" <EOL> fixture = { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT:location>' : "<STR_LIT>" , <EOL> } <EOL> new_image = self . client . add_image ( fixture ) <EOL> self . assertEquals ( new_image [ '<STR_LIT:status>' ] , '<STR_LIT>' ) <EOL> def test_add_image_with_image_data_as_string ( self ) : <EOL> """<STR_LIT>""" <EOL> fixture = { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } , <EOL> } <EOL> image_data_fixture = r"<STR_LIT>" <EOL> new_image = self . client . add_image ( fixture , image_data_fixture ) <EOL> new_image_id = new_image [ '<STR_LIT:id>' ] <EOL> new_meta , new_image_chunks = self . client . get_image ( new_image_id ) <EOL> new_image_data = "<STR_LIT>" <EOL> for image_chunk in new_image_chunks : <EOL> new_image_data += image_chunk <EOL> self . assertEquals ( image_data_fixture , new_image_data ) <EOL> for k , v in fixture . items ( ) : <EOL> self . assertEquals ( v , new_meta [ k ] ) <EOL> def test_add_image_with_image_data_as_file ( self ) : <EOL> """<STR_LIT>""" <EOL> fixture = { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } , <EOL> } <EOL> image_data_fixture = r"<STR_LIT>" <EOL> tmp_image_filepath = '<STR_LIT>' <EOL> if os . path . exists ( tmp_image_filepath ) : <EOL> os . unlink ( tmp_image_filepath ) <EOL> tmp_file = open ( tmp_image_filepath , '<STR_LIT:wb>' ) <EOL> tmp_file . write ( image_data_fixture ) <EOL> tmp_file . close ( ) <EOL> new_image = self . client . add_image ( fixture , open ( tmp_image_filepath ) ) <EOL> new_image_id = new_image [ '<STR_LIT:id>' ] <EOL> if os . path . exists ( tmp_image_filepath ) : <EOL> os . unlink ( tmp_image_filepath ) <EOL> new_meta , new_image_chunks = self . client . get_image ( new_image_id ) <EOL> new_image_data = "<STR_LIT>" <EOL> for image_chunk in new_image_chunks : <EOL> new_image_data += image_chunk <EOL> self . assertEquals ( image_data_fixture , new_image_data ) <EOL> for k , v in fixture . items ( ) : <EOL> self . assertEquals ( v , new_meta [ k ] ) <EOL> def _add_image_as_iterable ( self ) : <EOL> fixture = { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT:10> * <NUM_LIT> , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } , <EOL> } <EOL> class Zeros : <EOL> def __init__ ( self , chunks ) : <EOL> self . chunks = chunks <EOL> self . zeros = open ( '<STR_LIT>' , '<STR_LIT:rb>' ) <EOL> def __iter__ ( self ) : <EOL> while self . chunks > <NUM_LIT:0> : <EOL> self . chunks -= <NUM_LIT:1> <EOL> chunk = self . zeros . read ( <NUM_LIT> ) <EOL> yield chunk <EOL> new_image = self . client . add_image ( fixture , Zeros ( <NUM_LIT:10> ) ) <EOL> new_image_id = new_image [ '<STR_LIT:id>' ] <EOL> new_meta , new_image_chunks = self . client . get_image ( new_image_id ) <EOL> return ( fixture , new_meta , new_image_chunks ) <EOL> def _verify_image_iterable ( self , fixture , meta , chunks ) : <EOL> image_data_len = <NUM_LIT:0> <EOL> for image_chunk in chunks : <EOL> image_data_len += len ( image_chunk ) <EOL> self . assertEquals ( <NUM_LIT:10> * <NUM_LIT> , image_data_len ) <EOL> for k , v in fixture . items ( ) : <EOL> self . assertEquals ( v , meta [ k ] ) <EOL> def test_add_image_with_image_data_as_iterable ( self ) : <EOL> """<STR_LIT>""" <EOL> fixture , new_meta , new_chunks = self . _add_image_as_iterable ( ) <EOL> self . _verify_image_iterable ( fixture , new_meta , new_chunks ) <EOL> def test_roundtrip_image_with_image_data_as_iterable ( self ) : <EOL> """<STR_LIT>""" <EOL> fixture , new_meta , new_chunks = self . _add_image_as_iterable ( ) <EOL> dup_image = self . client . add_image ( fixture , new_chunks ) <EOL> dup_image_id = dup_image [ '<STR_LIT:id>' ] <EOL> roundtrip_meta , roundtrip_chunks = self . client . get_image ( dup_image_id ) <EOL> self . _verify_image_iterable ( fixture , roundtrip_meta , roundtrip_chunks ) <EOL> def test_add_image_with_image_data_as_string_and_no_size ( self ) : <EOL> """<STR_LIT>""" <EOL> fixture = { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } , <EOL> } <EOL> image_data_fixture = r"<STR_LIT>" <EOL> new_image = self . client . add_image ( fixture , image_data_fixture ) <EOL> new_image_id = new_image [ '<STR_LIT:id>' ] <EOL> new_meta , new_image_chunks = self . client . get_image ( new_image_id ) <EOL> new_image_data = "<STR_LIT>" <EOL> for image_chunk in new_image_chunks : <EOL> new_image_data += image_chunk <EOL> self . assertEquals ( image_data_fixture , new_image_data ) <EOL> for k , v in fixture . items ( ) : <EOL> self . assertEquals ( v , new_meta [ k ] ) <EOL> self . assertEquals ( <NUM_LIT> , new_meta [ '<STR_LIT:size>' ] ) <EOL> def test_add_image_with_bad_store ( self ) : <EOL> """<STR_LIT>""" <EOL> fixture = { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT:store>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } , <EOL> } <EOL> image_data_fixture = r"<STR_LIT>" <EOL> self . assertRaises ( exception . Invalid , <EOL> self . client . add_image , <EOL> fixture , <EOL> image_data_fixture ) <EOL> def test_update_image ( self ) : <EOL> """<STR_LIT>""" <EOL> fixture = { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> self . assertTrue ( self . client . update_image ( UUID2 , fixture ) ) <EOL> data = self . client . get_image_meta ( UUID2 ) <EOL> for k , v in fixture . items ( ) : <EOL> self . assertEquals ( v , data [ k ] ) <EOL> def test_update_image_not_existing ( self ) : <EOL> """<STR_LIT>""" <EOL> fixture = { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> } <EOL> self . assertRaises ( exception . NotFound , <EOL> self . client . update_image , <EOL> _gen_uuid ( ) , <EOL> fixture ) <EOL> def test_delete_image ( self ) : <EOL> """<STR_LIT>""" <EOL> orig_num_images = len ( self . client . get_images ( ) ) <EOL> self . assertTrue ( self . client . delete_image ( UUID2 ) ) <EOL> new_num_images = len ( self . client . get_images ( ) ) <EOL> self . assertEquals ( new_num_images , orig_num_images - <NUM_LIT:1> ) <EOL> def test_delete_image_not_existing ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertRaises ( exception . NotFound , <EOL> self . client . delete_image , <EOL> _gen_uuid ( ) ) <EOL> def test_get_member_images ( self ) : <EOL> """<STR_LIT>""" <EOL> memb_list = self . client . get_image_members ( UUID2 ) <EOL> num_members = len ( memb_list ) <EOL> self . assertEquals ( num_members , <NUM_LIT:0> ) <EOL> def test_get_image_members_not_existing ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertRaises ( exception . NotFound , <EOL> self . client . get_image_members , <EOL> _gen_uuid ( ) ) <EOL> def test_get_member_images ( self ) : <EOL> """<STR_LIT>""" <EOL> memb_list = self . client . get_member_images ( '<STR_LIT>' ) <EOL> num_members = len ( memb_list ) <EOL> self . assertEquals ( num_members , <NUM_LIT:0> ) <EOL> def test_replace_members ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertRaises ( exception . NotAuthorized , <EOL> self . client . replace_members , UUID2 , <EOL> dict ( member_id = '<STR_LIT>' ) ) <EOL> def test_add_member ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertRaises ( exception . NotAuthorized , <EOL> self . client . add_member , UUID2 , '<STR_LIT>' ) <EOL> def test_delete_member ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertRaises ( exception . NotAuthorized , <EOL> self . client . delete_member , UUID2 , '<STR_LIT>' ) <EOL> class TestConfigureClientFromURL ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . client = client . Client ( "<STR_LIT>" , doc_root = "<STR_LIT>" ) <EOL> def assertConfiguration ( self , url , host , port , use_ssl , doc_root ) : <EOL> self . client . configure_from_url ( url ) <EOL> self . assertEquals ( host , self . client . host ) <EOL> self . assertEquals ( port , self . client . port ) <EOL> self . assertEquals ( use_ssl , self . client . use_ssl ) <EOL> self . assertEquals ( doc_root , self . client . doc_root ) <EOL> def test_no_port_no_ssl_no_doc_root ( self ) : <EOL> self . assertConfiguration ( <EOL> url = '<STR_LIT>' , <EOL> host = '<STR_LIT>' , <EOL> port = <NUM_LIT> , <EOL> use_ssl = False , <EOL> doc_root = '<STR_LIT>' <EOL> ) <EOL> def test_port_ssl_doc_root ( self ) : <EOL> self . assertConfiguration ( <EOL> url = '<STR_LIT>' , <EOL> host = '<STR_LIT>' , <EOL> port = <NUM_LIT> , <EOL> use_ssl = True , <EOL> doc_root = '<STR_LIT>' <EOL> ) </s>
