cc-4105: added testing support for api client and ApiController
This commit is contained in:
parent
531dfe2b5e
commit
25d3028fb1
|
@ -447,7 +447,6 @@ class ApiController extends Zend_Controller_Action
|
||||||
$this->view->watched_dirs = $watchedDirsPath;
|
$this->view->watched_dirs = $watchedDirsPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO : Remove this dry run bs after finishing testing
|
|
||||||
public function dispatchMetadataAction($md, $mode, $dry_run=false)
|
public function dispatchMetadataAction($md, $mode, $dry_run=false)
|
||||||
{
|
{
|
||||||
// Replace this compound result in a hash with proper error handling later on
|
// Replace this compound result in a hash with proper error handling later on
|
||||||
|
@ -542,6 +541,7 @@ class ApiController extends Zend_Controller_Action
|
||||||
// The key(mdXXX) does not have any meaning as of yet but it could potentially correspond
|
// The key(mdXXX) does not have any meaning as of yet but it could potentially correspond
|
||||||
// to some unique id.
|
// to some unique id.
|
||||||
$responses = array();
|
$responses = array();
|
||||||
|
$dry = $request->getParam('dry') || false;
|
||||||
$params = $request->getParams();
|
$params = $request->getParams();
|
||||||
$valid_modes = array('delete_dir', 'delete', 'moved', 'modify', 'create');
|
$valid_modes = array('delete_dir', 'delete', 'moved', 'modify', 'create');
|
||||||
foreach ($request->getParams() as $k => $raw_json) {
|
foreach ($request->getParams() as $k => $raw_json) {
|
||||||
|
@ -559,7 +559,8 @@ class ApiController extends Zend_Controller_Action
|
||||||
// A request still has a chance of being invalid even if it exists but it's validated
|
// A request still has a chance of being invalid even if it exists but it's validated
|
||||||
// by $valid_modes array
|
// by $valid_modes array
|
||||||
$mode = $info_json['mode'];
|
$mode = $info_json['mode'];
|
||||||
Logging::log("Received bad request(key=$k). 'mode' parameter was invalid with value: '$mode'");
|
Logging::log("Received bad request(key=$k). 'mode' parameter was invalid with value: '$mode'. Request:");
|
||||||
|
Logging::log( $info_json );
|
||||||
array_push( $responses, array(
|
array_push( $responses, array(
|
||||||
'error' => "Bad request. 'mode' parameter is invalid",
|
'error' => "Bad request. 'mode' parameter is invalid",
|
||||||
'key' => $k,
|
'key' => $k,
|
||||||
|
@ -570,16 +571,16 @@ class ApiController extends Zend_Controller_Action
|
||||||
$mode = $info_json['mode'];
|
$mode = $info_json['mode'];
|
||||||
unset( $info_json['mode'] );
|
unset( $info_json['mode'] );
|
||||||
// TODO : remove the $dry_run parameter after finished testing
|
// TODO : remove the $dry_run parameter after finished testing
|
||||||
$response = $this->dispatchMetadataAction($info_json, $mode, $dry_run=true);
|
$response = $this->dispatchMetadataAction($info_json, $mode, $dry_run=$dry);
|
||||||
// We attack the 'key' back to every request in case the would like to associate
|
// We attack the 'key' back to every request in case the would like to associate
|
||||||
// his requests with particular responses
|
// his requests with particular responses
|
||||||
$response['key'] = $k;
|
$response['key'] = $k;
|
||||||
array_push($responses, $response);
|
array_push($responses, $response);
|
||||||
// On recorded show requests we do some extra work here. Not sure what it actually is and it
|
// On recorded show requests we do some extra work here. Not sure what it actually is and it
|
||||||
// was usually called from the python api. Now we just call it straight from the controller to
|
// was usually called from the python api client. Now we just call it straight from the controller to
|
||||||
// save the http roundtrip
|
// save the http roundtrip
|
||||||
if( $info_json['is_record'] and !array_key_exists('error', $response) ) {
|
if( $info_json['is_record'] and !array_key_exists('error', $response) ) {
|
||||||
$this->uploadRecordedActionParam($info_json['showinstanceid'],$info_json['fileid']);
|
$this->uploadRecordedActionParam($info_json['showinstanceid'],$info_json['fileid'],$dry_run=$dry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
die( json_encode($responses) );
|
die( json_encode($responses) );
|
||||||
|
|
|
@ -41,7 +41,7 @@ def convert_dict_value_to_utf8(md):
|
||||||
|
|
||||||
class AirtimeApiClient():
|
class AirtimeApiClient():
|
||||||
|
|
||||||
def __init__(self, logger=None):
|
def __init__(self, logger=None,config_path='/etc/airtime/api_client.cfg'):
|
||||||
if logger is None:
|
if logger is None:
|
||||||
self.logger = logging
|
self.logger = logging
|
||||||
else:
|
else:
|
||||||
|
@ -49,7 +49,7 @@ class AirtimeApiClient():
|
||||||
|
|
||||||
# loading config file
|
# loading config file
|
||||||
try:
|
try:
|
||||||
self.config = ConfigObj('/etc/airtime/api_client.cfg')
|
self.config = ConfigObj(config_path)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
self.logger.error('Error loading config file: %s', e)
|
self.logger.error('Error loading config file: %s', e)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
@ -366,7 +366,7 @@ class AirtimeApiClient():
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def send_media_monitor_requests(self, action_list):
|
def send_media_monitor_requests(self, action_list, dry=False):
|
||||||
"""
|
"""
|
||||||
Send a gang of media monitor events at a time. actions_list is a list of dictionaries
|
Send a gang of media monitor events at a time. actions_list is a list of dictionaries
|
||||||
where every dictionary is representing an action. Every action dict must contain a 'mode'
|
where every dictionary is representing an action. Every action dict must contain a 'mode'
|
||||||
|
@ -402,6 +402,9 @@ class AirtimeApiClient():
|
||||||
# parenthesis make the code almost unreadable
|
# parenthesis make the code almost unreadable
|
||||||
md_list = dict((("md%d" % i), json.dumps(convert_dict_value_to_utf8(md))) \
|
md_list = dict((("md%d" % i), json.dumps(convert_dict_value_to_utf8(md))) \
|
||||||
for i,md in enumerate(valid_actions))
|
for i,md in enumerate(valid_actions))
|
||||||
|
# For testing we add the following "dry" parameter to tell the
|
||||||
|
# controller not to actually do any changes
|
||||||
|
if dry: md_list['dry'] = 1
|
||||||
self.logger.info("Pumping out %d requests..." % len(valid_actions))
|
self.logger.info("Pumping out %d requests..." % len(valid_actions))
|
||||||
data = urllib.urlencode(md_list)
|
data = urllib.urlencode(md_list)
|
||||||
req = urllib2.Request(url, data)
|
req = urllib2.Request(url, data)
|
||||||
|
|
Loading…
Reference in New Issue