<s> from django import http <EOL> from mox3 . mox import IsA <EOL> from openstack_dashboard import api <EOL> from openstack_dashboard . test import helpers as test <EOL> class CeilometerApiTests ( test . APITestCase ) : <EOL> def test_sample_list ( self ) : <EOL> samples = self . samples . list ( ) <EOL> meter_name = "<STR_LIT>" <EOL> ceilometerclient = self . stub_ceilometerclient ( ) <EOL> ceilometerclient . samples = self . mox . CreateMockAnything ( ) <EOL> ceilometerclient . samples . list ( meter_name = meter_name , <EOL> q = [ ] , <EOL> limit = None ) . AndReturn ( samples ) <EOL> self . mox . ReplayAll ( ) <EOL> ret_list = api . ceilometer . sample_list ( self . request , <EOL> meter_name , <EOL> query = [ ] ) <EOL> self . assertEqual ( len ( samples ) , len ( ret_list ) ) <EOL> for c in ret_list : <EOL> self . assertIsInstance ( c , api . ceilometer . Sample ) <EOL> def test_alarm_list ( self ) : <EOL> alarms = self . alarms . list ( ) <EOL> ceilometerclient = self . stub_ceilometerclient ( ) <EOL> ceilometerclient . alarms = self . mox . CreateMockAnything ( ) <EOL> ceilometerclient . alarms . list ( q = [ ] ) . AndReturn ( alarms ) <EOL> self . mox . ReplayAll ( ) <EOL> ret_list = api . ceilometer . alarm_list ( self . request , query = [ ] ) <EOL> self . assertEqual ( len ( alarms ) , len ( ret_list ) ) <EOL> for c in ret_list : <EOL> self . assertIsInstance ( c , api . ceilometer . Alarm ) <EOL> def test_alarm_get ( self ) : <EOL> alarm = self . alarms . first ( ) <EOL> ceilometerclient = self . stub_ceilometerclient ( ) <EOL> ceilometerclient . alarms = self . mox . CreateMockAnything ( ) <EOL> ceilometerclient . alarms . get ( alarm . id ) . AndReturn ( alarm ) <EOL> self . mox . ReplayAll ( ) <EOL> ret_alarm = api . ceilometer . alarm_get ( self . request , <EOL> alarm_id = '<STR_LIT>' ) <EOL> self . assertEqual ( alarm . alarm_id , ret_alarm . alarm_id ) <EOL> def test_alarm_create ( self ) : <EOL> alarm = self . alarms . first ( ) <EOL> new_alarm = { '<STR_LIT>' : alarm } <EOL> ceilometerclient = self . stub_ceilometerclient ( ) <EOL> ceilometerclient . alarms = self . mox . CreateMockAnything ( ) <EOL> ceilometerclient . alarms . create ( ** new_alarm ) . AndReturn ( alarm ) <EOL> self . mox . ReplayAll ( ) <EOL> test_alarm = api . ceilometer . alarm_create ( self . request , <EOL> ** new_alarm ) <EOL> self . assertEqual ( alarm . alarm_id , test_alarm . alarm_id ) <EOL> def test_alarm_update ( self ) : <EOL> """<STR_LIT>""" <EOL> alarm1 = self . alarms . first ( ) <EOL> alarm2 = self . alarms . list ( ) [ <NUM_LIT:1> ] <EOL> ceilometerclient = self . stub_ceilometerclient ( ) <EOL> ceilometerclient . alarms = self . mox . CreateMockAnything ( ) <EOL> ceilometerclient . alarms . update ( alarm1 . id , <EOL> description = '<STR_LIT>' ) . AndReturn ( alarm2 ) <EOL> self . mox . ReplayAll ( ) <EOL> test_alarm = api . ceilometer . alarm_update ( self . request , <EOL> alarm1 . id , <EOL> description = '<STR_LIT>' ) <EOL> self . assertEqual ( alarm2 . description , test_alarm . description ) <EOL> def test_meter_list ( self ) : <EOL> meters = self . meters . list ( ) <EOL> ceilometerclient = self . stub_ceilometerclient ( ) <EOL> ceilometerclient . meters = self . mox . CreateMockAnything ( ) <EOL> ceilometerclient . meters . list ( [ ] ) . AndReturn ( meters ) <EOL> self . mox . ReplayAll ( ) <EOL> ret_list = api . ceilometer . meter_list ( self . request , [ ] ) <EOL> self . assertEqual ( len ( meters ) , len ( ret_list ) ) <EOL> for m in ret_list : <EOL> self . assertIsInstance ( m , api . ceilometer . Meter ) <EOL> def test_resource_list ( self ) : <EOL> resources = self . resources . list ( ) <EOL> ceilometerclient = self . stub_ceilometerclient ( ) <EOL> ceilometerclient . resources = self . mox . CreateMockAnything ( ) <EOL> ceilometerclient . resources . list ( q = [ ] ) . AndReturn ( resources ) <EOL> self . mox . ReplayAll ( ) <EOL> ret_list = api . ceilometer . resource_list ( self . request , query = [ ] ) <EOL> self . assertEqual ( len ( resources ) , len ( ret_list ) ) <EOL> for r in ret_list : <EOL> self . assertIsInstance ( r , api . ceilometer . Resource ) <EOL> def test_statistic_list ( self ) : <EOL> statistics = self . statistics . list ( ) <EOL> meter_name = "<STR_LIT>" <EOL> ceilometerclient = self . stub_ceilometerclient ( ) <EOL> ceilometerclient . statistics = self . mox . CreateMockAnything ( ) <EOL> ceilometerclient . statistics . list ( meter_name = meter_name , <EOL> period = None , q = [ ] ) . AndReturn ( statistics ) <EOL> self . mox . ReplayAll ( ) <EOL> ret_list = api . ceilometer . statistic_list ( self . request , <EOL> meter_name , <EOL> period = None , <EOL> query = [ ] ) <EOL> self . assertEqual ( len ( statistics ) , len ( ret_list ) ) <EOL> for s in ret_list : <EOL> self . assertIsInstance ( s , api . ceilometer . Statistic ) <EOL> def test_meters_list_all ( self ) : <EOL> meters = self . meters . list ( ) <EOL> ceilometerclient = self . stub_ceilometerclient ( ) <EOL> ceilometerclient . meters = self . mox . CreateMockAnything ( ) <EOL> ceilometerclient . meters . list ( None ) . AndReturn ( meters ) <EOL> self . mox . ReplayAll ( ) <EOL> meters_object = api . ceilometer . Meters ( self . request ) <EOL> ret_list = meters_object . list_all ( ) <EOL> for m in ret_list : <EOL> self . assertIsInstance ( m , api . ceilometer . Meter ) <EOL> self . assertEqual ( <NUM_LIT:3> , len ( ret_list ) ) <EOL> names = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> for ret in ret_list : <EOL> self . assertIn ( ret . name , names ) <EOL> names . remove ( ret . name ) <EOL> def test_meters_list_all_only ( self ) : <EOL> meters = self . meters . list ( ) <EOL> ceilometerclient = self . stub_ceilometerclient ( ) <EOL> ceilometerclient . meters = self . mox . CreateMockAnything ( ) <EOL> ceilometerclient . meters . list ( None ) . AndReturn ( meters ) <EOL> self . mox . ReplayAll ( ) <EOL> meters_object = api . ceilometer . Meters ( self . request ) <EOL> ret_list = meters_object . list_all ( only_meters = [ "<STR_LIT>" ] ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( ret_list ) ) <EOL> self . assertEqual ( "<STR_LIT>" , ret_list [ <NUM_LIT:0> ] . name ) <EOL> ret_list = meters_object . list_all ( only_meters = [ "<STR_LIT>" , <EOL> "<STR_LIT>" ] ) <EOL> self . assertEqual ( <NUM_LIT:2> , len ( ret_list ) ) <EOL> self . assertEqual ( "<STR_LIT>" , ret_list [ <NUM_LIT:0> ] . name ) <EOL> self . assertEqual ( "<STR_LIT>" , ret_list [ <NUM_LIT:1> ] . name ) <EOL> def test_meters_list_all_except ( self ) : <EOL> meters = self . meters . list ( ) <EOL> ceilometerclient = self . stub_ceilometerclient ( ) <EOL> ceilometerclient . meters = self . mox . CreateMockAnything ( ) <EOL> ceilometerclient . meters . list ( None ) . AndReturn ( meters ) <EOL> self . mox . ReplayAll ( ) <EOL> meters_object = api . ceilometer . Meters ( self . request ) <EOL> ret_list = meters_object . list_all ( except_meters = [ "<STR_LIT>" , <EOL> "<STR_LIT>" ] ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( ret_list ) ) <EOL> self . assertEqual ( "<STR_LIT>" , ret_list [ <NUM_LIT:0> ] . name ) <EOL> ret_list = meters_object . list_all ( except_meters = [ "<STR_LIT>" ] ) <EOL> self . assertEqual ( len ( ret_list ) , <NUM_LIT:2> ) <EOL> names = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> for ret in ret_list : <EOL> self . assertIn ( ret . name , names ) <EOL> names . remove ( ret . name ) <EOL> @ test . create_stubs ( { api . ceilometer . CeilometerUsage : ( "<STR_LIT>" , <EOL> "<STR_LIT>" ) } ) <EOL> def test_global_data_get ( self ) : <EOL> class TempUsage ( api . base . APIResourceWrapper ) : <EOL> _attrs = [ "<STR_LIT:id>" , "<STR_LIT>" , "<STR_LIT:user>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> meters = [ "<STR_LIT>" , <EOL> "<STR_LIT>" ] <EOL> default_query = [ "<STR_LIT>" ] <EOL> stats_attr = "<STR_LIT>" <EOL> resources = self . resources . list ( ) <EOL> statistics = self . statistics . list ( ) <EOL> user = self . ceilometer_users . list ( ) [ <NUM_LIT:0> ] <EOL> tenant = self . ceilometer_tenants . list ( ) [ <NUM_LIT:0> ] <EOL> ceilometerclient = self . stub_ceilometerclient ( ) <EOL> ceilometerclient . resources = self . mox . CreateMockAnything ( ) <EOL> ceilometerclient . resources . list ( q = IsA ( list ) ) . AndReturn ( resources [ : <NUM_LIT:1> ] ) <EOL> ceilometerclient . statistics = self . mox . CreateMockAnything ( ) <EOL> ceilometerclient . statistics . list ( meter_name = IsA ( str ) , <EOL> period = None , q = IsA ( list ) ) . AndReturn ( statistics ) <EOL> ceilometerclient . statistics . list ( meter_name = IsA ( str ) , <EOL> period = None , q = IsA ( list ) ) . AndReturn ( statistics ) <EOL> api . ceilometer . CeilometerUsage . get_user ( IsA ( str ) ) . AndReturn ( user ) <EOL> api . ceilometer . CeilometerUsage . get_tenant ( IsA ( str ) ) . AndReturn ( tenant ) <EOL> self . mox . ReplayAll ( ) <EOL> ceilometer_usage = api . ceilometer . CeilometerUsage ( http . HttpRequest ) <EOL> data = ceilometer_usage . global_data_get ( <EOL> used_cls = TempUsage , query = [ "<STR_LIT>" ] , with_statistics = True ) <EOL> first = data [ <NUM_LIT:0> ] <EOL> self . assertEqual ( '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> first . id ) <EOL> self . assertEqual ( '<STR_LIT:user>' , first . user . name ) <EOL> self . assertEqual ( '<STR_LIT>' , first . tenant . name ) <EOL> self . assertEqual ( '<STR_LIT>' , first . resource ) <EOL> self . assertEqual ( <NUM_LIT:9> , first . get_meter ( '<STR_LIT>' ) , ) <EOL> self . assertEqual ( <NUM_LIT:9> , first . get_meter ( '<STR_LIT>' ) , ) <EOL> self . assertEqual ( <NUM_LIT:2> , len ( first . meters ) ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( data ) ) <EOL> @ test . create_stubs ( { api . ceilometer . CeilometerUsage : ( "<STR_LIT>" , <EOL> "<STR_LIT>" ) } ) <EOL> def test_global_data_get_without_statistic_data ( self ) : <EOL> class TempUsage ( api . base . APIResourceWrapper ) : <EOL> _attrs = [ "<STR_LIT:id>" , "<STR_LIT>" , "<STR_LIT:user>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" ] <EOL> meters = [ "<STR_LIT>" , <EOL> "<STR_LIT>" ] <EOL> default_query = [ "<STR_LIT>" ] <EOL> stats_attr = "<STR_LIT>" <EOL> resources = self . resources . list ( ) <EOL> user = self . ceilometer_users . list ( ) [ <NUM_LIT:0> ] <EOL> tenant = self . ceilometer_tenants . list ( ) [ <NUM_LIT:0> ] <EOL> ceilometerclient = self . stub_ceilometerclient ( ) <EOL> ceilometerclient . resources = self . mox . CreateMockAnything ( ) <EOL> ceilometerclient . resources . list ( q = IsA ( list ) ) . AndReturn ( resources ) <EOL> api . ceilometer . CeilometerUsage . get_user ( IsA ( str ) ) . MultipleTimes ( ) . AndReturn ( user ) <EOL> api . ceilometer . CeilometerUsage . get_tenant ( IsA ( str ) ) . MultipleTimes ( ) . AndReturn ( tenant ) <EOL> self . mox . ReplayAll ( ) <EOL> ceilometer_usage = api . ceilometer . CeilometerUsage ( http . HttpRequest ) <EOL> data = ceilometer_usage . global_data_get ( <EOL> used_cls = TempUsage , query = [ "<STR_LIT>" ] , with_statistics = False ) <EOL> first = data [ <NUM_LIT:0> ] <EOL> self . assertEqual ( '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> first . id ) <EOL> self . assertEqual ( '<STR_LIT:user>' , first . user . name ) <EOL> self . assertEqual ( '<STR_LIT>' , first . tenant . name ) <EOL> self . assertEqual ( '<STR_LIT>' , first . resource ) <EOL> self . assertRaises ( AttributeError , getattr , first , '<STR_LIT>' ) <EOL> self . assertRaises ( AttributeError , getattr , first , '<STR_LIT>' ) <EOL> self . assertEqual ( len ( resources ) , len ( data ) ) <EOL> @ test . create_stubs ( { api . ceilometer . CeilometerUsage : ( "<STR_LIT>" , <EOL> "<STR_LIT>" ) } ) <EOL> def test_global_data_get_all_statistic_data ( self ) : <EOL> class TempUsage ( api . base . APIResourceWrapper ) : <EOL> _attrs = [ "<STR_LIT:id>" , "<STR_LIT>" , "<STR_LIT:user>" , "<STR_LIT>" , "<STR_LIT>" , ] <EOL> meters = [ "<STR_LIT>" , <EOL> "<STR_LIT>" ] <EOL> default_query = [ "<STR_LIT>" ] <EOL> stats_attr = None <EOL> resources = self . resources . list ( ) <EOL> statistics = self . statistics . list ( ) <EOL> user = self . ceilometer_users . list ( ) [ <NUM_LIT:0> ] <EOL> tenant = self . ceilometer_tenants . list ( ) [ <NUM_LIT:0> ] <EOL> ceilometerclient = self . stub_ceilometerclient ( ) <EOL> ceilometerclient . resources = self . mox . CreateMockAnything ( ) <EOL> ceilometerclient . resources . list ( q = IsA ( list ) ) . AndReturn ( resources ) <EOL> ceilometerclient . statistics = self . mox . CreateMockAnything ( ) <EOL> ceilometerclient . statistics . list ( meter_name = IsA ( str ) , <EOL> period = None , q = IsA ( list ) ) . MultipleTimes ( ) . AndReturn ( statistics ) <EOL> api . ceilometer . CeilometerUsage . get_user ( IsA ( str ) ) . MultipleTimes ( ) . AndReturn ( user ) <EOL> api . ceilometer . CeilometerUsage . get_tenant ( IsA ( str ) ) . MultipleTimes ( ) . AndReturn ( tenant ) <EOL> self . mox . ReplayAll ( ) <EOL> ceilometer_usage = api . ceilometer . CeilometerUsage ( http . HttpRequest ) <EOL> data = ceilometer_usage . global_data_get ( <EOL> used_cls = TempUsage , query = [ "<STR_LIT>" ] , with_statistics = True ) <EOL> first = data [ <NUM_LIT:0> ] <EOL> self . assertEqual ( '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> first . id ) <EOL> self . assertEqual ( '<STR_LIT:user>' , first . user . name ) <EOL> self . assertEqual ( '<STR_LIT>' , first . tenant . name ) <EOL> self . assertEqual ( '<STR_LIT>' , first . resource ) <EOL> statistic_obj = api . ceilometer . Statistic ( statistics [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( vars ( first . get_meter ( '<STR_LIT>' ) [ <NUM_LIT:0> ] ) , <EOL> vars ( statistic_obj ) ) <EOL> self . assertEqual ( vars ( first . get_meter ( '<STR_LIT>' ) [ <NUM_LIT:0> ] ) , <EOL> vars ( statistic_obj ) ) <EOL> self . assertEqual ( len ( resources ) , len ( data ) ) </s>
