<s> """<STR_LIT>""" <EOL> import os <EOL> import simplejson as json <EOL> import unittest2 <EOL> os . environ [ '<STR_LIT>' ] = '<STR_LIT:true>' <EOL> from compass . utils import setting_wrapper as setting <EOL> reload ( setting ) <EOL> from test_api import ApiTestCase <EOL> from compass . db . api import cluster as cluster_db <EOL> from compass . db . api import health_check_report as health_check_db <EOL> from compass . utils import flags <EOL> from compass . utils import logsetting <EOL> report_sample = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:data>" : [ <NUM_LIT> , <NUM_LIT> ] , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT:success>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : <NUM_LIT:2> <EOL> } <EOL> } <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:data>" : [ <NUM_LIT> , <NUM_LIT> ] , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT:success>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : <NUM_LIT:2> <EOL> } <EOL> } <EOL> } <EOL> } , <EOL> "<STR_LIT>" : [ ] <EOL> } , <EOL> "<STR_LIT>" : { } <EOL> } <EOL> api_resp_tpml = { <EOL> "<STR_LIT>" : <NUM_LIT:1> , <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { } , <EOL> "<STR_LIT:state>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> class TestHealthCheckAPI ( ApiTestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( TestHealthCheckAPI , self ) . setUp ( ) <EOL> self . cluster_id = <NUM_LIT:1> <EOL> self . url = '<STR_LIT>' % self . cluster_id <EOL> def tearDown ( self ) : <EOL> super ( TestHealthCheckAPI , self ) . tearDown ( ) <EOL> def test_add_and_list_reports ( self ) : <EOL> reports_list = [ <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } , <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } , <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> ] <EOL> request_data = json . dumps ( { "<STR_LIT>" : reports_list } ) <EOL> return_value = self . test_client . post ( self . url , data = request_data ) <EOL> resp = json . loads ( return_value . get_data ( ) ) <EOL> self . assertEqual ( <NUM_LIT:200> , return_value . status_code ) <EOL> self . assertEqual ( <NUM_LIT:3> , len ( resp ) ) <EOL> request_data = json . dumps ( { '<STR_LIT:name>' : '<STR_LIT>' } ) <EOL> return_value = self . test_client . post ( self . url , data = request_data ) <EOL> resp = json . loads ( return_value . get_data ( ) ) <EOL> self . assertEqual ( <NUM_LIT:200> , return_value . status_code ) <EOL> self . assertEqual ( '<STR_LIT>' , resp [ '<STR_LIT:name>' ] ) <EOL> return_value = self . test_client . post ( self . url , data = request_data ) <EOL> self . assertEqual ( <NUM_LIT> , return_value . status_code ) <EOL> return_value = self . test_client . get ( self . url ) <EOL> resp = json . loads ( return_value . get_data ( ) ) <EOL> self . assertEqual ( <NUM_LIT:200> , return_value . status_code ) <EOL> self . assertEqual ( <NUM_LIT:4> , len ( resp ) ) <EOL> def test_update_and_get_health_report ( self ) : <EOL> report_name = '<STR_LIT>' <EOL> health_check_db . add_report_record ( self . cluster_id , name = report_name ) <EOL> url = '<STR_LIT:/>' . join ( ( self . url , report_name ) ) <EOL> request_data = json . dumps ( <EOL> { "<STR_LIT>" : report_sample , "<STR_LIT:state>" : "<STR_LIT>" } <EOL> ) <EOL> return_value = self . test_client . put ( url , data = request_data ) <EOL> resp = json . loads ( return_value . get_data ( ) ) <EOL> self . maxDiff = None <EOL> self . assertEqual ( <NUM_LIT:200> , return_value . status_code ) <EOL> self . assertDictEqual ( report_sample , resp [ '<STR_LIT>' ] ) <EOL> return_value = self . test_client . put ( url , data = request_data ) <EOL> self . assertEqual ( <NUM_LIT> , return_value . status_code ) <EOL> return_value = self . test_client . get ( url ) <EOL> self . assertEqual ( <NUM_LIT:200> , return_value . status_code ) <EOL> self . assertDictEqual ( report_sample , resp [ '<STR_LIT>' ] ) <EOL> def test_action_start_check_health ( self ) : <EOL> url = '<STR_LIT>' % self . cluster_id <EOL> request_data = json . dumps ( { '<STR_LIT>' : None } ) <EOL> return_value = self . test_client . post ( url , data = request_data ) <EOL> self . assertEqual ( <NUM_LIT> , return_value . status_code ) <EOL> cluster_db . update_cluster_state ( <EOL> self . cluster_id , state = '<STR_LIT>' <EOL> ) <EOL> return_value = self . test_client . post ( url , data = request_data ) <EOL> self . assertEqual ( <NUM_LIT> , return_value . status_code ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> flags . init ( ) <EOL> logsetting . init ( ) <EOL> unittest2 . main ( ) </s>
