cc-4105: added testing support for api client and ApiController

This commit is contained in:
Rudi Grinberg 2012-07-17 16:16:06 -04:00
parent 531dfe2b5e
commit 25d3028fb1
2 changed files with 12 additions and 8 deletions

View file

@ -447,7 +447,6 @@ class ApiController extends Zend_Controller_Action
$this->view->watched_dirs = $watchedDirsPath;
}
// TODO : Remove this dry run bs after finishing testing
public function dispatchMetadataAction($md, $mode, $dry_run=false)
{
// 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
// to some unique id.
$responses = array();
$dry = $request->getParam('dry') || false;
$params = $request->getParams();
$valid_modes = array('delete_dir', 'delete', 'moved', 'modify', 'create');
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
// by $valid_modes array
$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(
'error' => "Bad request. 'mode' parameter is invalid",
'key' => $k,
@ -570,16 +571,16 @@ class ApiController extends Zend_Controller_Action
$mode = $info_json['mode'];
unset( $info_json['mode'] );
// 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
// his requests with particular responses
$response['key'] = $k;
array_push($responses, $response);
// 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
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) );