+ Add POST for testcases.

This commit is contained in:
zhujinyong
2021-09-14 14:05:56 +08:00
parent f60c06fd5c
commit 9d3c257592
3 changed files with 58 additions and 2 deletions
+5 -1
View File
@@ -76,8 +76,12 @@ class bugsEntry extends entry
* @access public
* @return void
*/
public function post($productID)
public function post($productID = 0)
{
if(!$productID) $productID = $this->param('product');
if(!$productID and isset($this->requestBody->product)) $productID = $this->requestBody->product;
if(!$productID) return $this->sendError(400, 'Need product id.');
$fields = 'title,project,execution,openedBuild,assignedTo,pri,severity,type,story';
$this->batchSetPost($fields);
+4 -1
View File
@@ -28,7 +28,10 @@ class testcaseEntry extends entry
if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message);
if(!isset($data->case)) $this->sendError(400, 'error');
$this->send(200, $this->format($data->case, 'openedDate:time,lastEditedDate:time,lastRunDate:time,scriptedDate:date,reviewedDate:date,deleted:bool'));
$case = $data->case;
$case->steps = (isset($case->steps) and !empty($case->steps)) ? array_values(get_object_vars($case->steps)) : array();
$this->send(200, $this->format($case, 'openedDate:time,lastEditedDate:time,lastRunDate:time,scriptedDate:date,reviewedDate:date,deleted:bool'));
}
/**
+49
View File
@@ -57,4 +57,53 @@ class testcasesEntry extends entry
return $this->sendError(400, 'error');
}
/**
* POST method.
*
* @param int $productID
* @access public
* @return void
*/
public function post($productID = 0)
{
if(!$productID) $productID = $this->param('product');
if(!$productID and isset($this->requestBody->product)) $productID = $this->requestBody->product;
if(!$productID) return $this->sendError(400, 'Need product id.');
$fields = 'module,type,stage,story,title,precondition,pri';
$this->batchSetPost($fields);
$this->setPost('product', $productID);
/* Set steps and expects. */
if(isset($this->requestBody->steps))
{
$steps = array();
$expects = array();
$stepType = array();
foreach($this->requestBody->steps as $step)
{
$steps[] = $step->desc;
$expects[] = $step->expect;
$stepType[] = 'item';
}
$this->setPost('steps', $steps);
$this->setPost('expects', $expects);
$this->setPost('stepType', $stepType);
}
$control = $this->loadController('testcase', 'create');
$this->requireFields('title,type,pri,steps');
$control->create(0);
$data = $this->getData();
if(isset($data->result) and $data->result == 'fail') return $this->sendError(400, $data->message);
if(isset($data->result) and !isset($data->id)) return $this->sendError(400, $data->message);
$case = $this->loadModel('testcase')->getByID($data->id);
$case->steps = (isset($case->steps) and !empty($case->steps)) ? array_values($case->steps) : array();
$this->send(200, $this->format($case, 'openedDate:time,lastEditedDate:time,lastRunDate:time,scriptedDate:date,reviewedDate:date,deleted:bool'));
}
}