Merge pull request #19452 from owncloud/ocs_provisioning_api_more_tests

OCS provisioning API more tests
This commit is contained in:
Thomas Müller 2015-10-06 11:19:48 +02:00
commit d9ffb09479
3 changed files with 130 additions and 13 deletions

View File

@ -43,16 +43,32 @@ class FeatureContext extends BehatContext {
}
/**
* @When /^sending "([^"]*)" to "([^"]*)"$/
*/
* @When /^sending "([^"]*)" to "([^"]*)"$/
*/
public function sendingTo($verb, $url) {
$this->sendingToWith($verb, $url, null);
}
/**
* @Then /^the status code should be "([^"]*)"$/
* Parses the xml answer to get ocs response which doesn't match with
* http one in v1 of the api.
*/
public function getOCSResponse($response){
return $response->xml()->meta[0]->statuscode;
}
/**
* @Then /^the OCS status code should be "([^"]*)"$/
*/
public function theStatusCodeShouldBe($statusCode) {
public function theOCSStatusCodeShouldBe($statusCode) {
PHPUnit_Framework_Assert::assertEquals($statusCode, $this->getOCSResponse($this->response));
}
/**
* @Then /^the HTTP status code should be "([^"]*)"$/
*/
public function theHTTPStatusCodeShouldBe($statusCode) {
PHPUnit_Framework_Assert::assertEquals($statusCode, $this->response->getStatusCode());
}
@ -91,7 +107,9 @@ class FeatureContext extends BehatContext {
public function userDoesNotExist($user) {
try {
$this->userExists($user);
PHPUnit_Framework_Assert::fail('The user "' . $user . '" exists');
} catch (\GuzzleHttp\Exception\ClientException $ex) {
$this->response = $ex->getResponse();
PHPUnit_Framework_Assert::assertEquals(404, $ex->getResponse()->getStatusCode());
}
}
@ -100,7 +118,7 @@ class FeatureContext extends BehatContext {
* @When /^creating the user "([^"]*)r"$/
*/
public function creatingTheUser($user) {
$fullUrl = $this->baseUrl . "v2.php/cloud/users/$user";
$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/$user" ;
$client = new Client();
$options = [];
if ($this->currentUser === 'admin') {
@ -113,9 +131,55 @@ class FeatureContext extends BehatContext {
'password' => '123456'
]
]);
}
/**
* @When /^creating the group "([^"]*)r"$/
*/
public function creatingTheGroup($group) {
$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/groups/addgroup" ;
$client = new Client();
$options = [];
if ($this->currentUser === 'admin') {
$options['auth'] = $this->adminUser;
}
$this->response = $client->post($fullUrl, [
'form_params' => [
'groupid' => $user
]
]);
}
/**
* @Given /^group "([^"]*)" exists$/
*/
public function groupExists($group) {
$fullUrl = $this->baseUrl . "v2.php/cloud/groups/$group";
$client = new Client();
$options = [];
if ($this->currentUser === 'admin') {
$options['auth'] = $this->adminUser;
}
$this->response = $client->get($fullUrl, $options);
PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode());
}
/**
* @Given /^group "([^"]*)" does not exist$/
*/
public function groupDoesNotExist($group) {
try {
$this->groupExists($group);
PHPUnit_Framework_Assert::fail('The group "' . $group . '" exists');
} catch (\GuzzleHttp\Exception\ClientException $ex) {
$this->response = $ex->getResponse();
PHPUnit_Framework_Assert::assertEquals(404, $ex->getResponse()->getStatusCode());
}
}
/**
* @When /^sending "([^"]*)" to "([^"]*)" with$/
* @param \Behat\Gherkin\Node\TableNode|null $formData
@ -138,5 +202,4 @@ class FeatureContext extends BehatContext {
$this->response = $ex->getResponse();
}
}
}

View File

@ -5,12 +5,14 @@ Feature: provisioning
Scenario: Getting an not existing user
Given As an "admin"
When sending "GET" to "/cloud/users/test"
Then the status code should be "200"
Then the OCS status code should be "998"
And the HTTP status code should be "200"
Scenario: Listing all users
Given As an "admin"
When sending "GET" to "/cloud/users"
Then the status code should be "200"
Then the OCS status code should be "100"
And the HTTP status code should be "200"
Scenario: Create a user
Given As an "admin"
@ -18,15 +20,67 @@ Feature: provisioning
When sending "POST" to "/cloud/users" with
| userid | brand-new-user |
| password | 123456 |
Then the OCS status code should be "100"
And the HTTP status code should be "200"
And user "brand-new-user" exists
Then the status code should be "200"
Scenario: Create an existing user
Given As an "admin"
And user "brand-new-user" exists
When sending "POST" to "/cloud/users" with
| userid | brand-new-user |
| password | 123456 |
Then the OCS status code should be "102"
And the HTTP status code should be "200"
Scenario: Get an existing user
Given As an "admin"
When sending "GET" to "/cloud/users/brand-new-user"
Then the OCS status code should be "100"
And the HTTP status code should be "200"
Scenario: Edit a user
Given As an "admin"
And user "brand-new-user" exists
When sending "PUT" to "/cloud/users/brand-new-user" with
| key | quota |
| value | 12MB |
| key | email |
| value | brand-new-user@gmail.com |
Then the OCS status code should be "100"
And the HTTP status code should be "200"
And user "brand-new-user" exists
Scenario: Delete a user
Given As an "admin"
And user "brand-new-user" exists
When sending "POST" to "/cloud/users" with
| userid | brand-new-user |
Then the status code should be "200"
When sending "DELETE" to "/cloud/users/brand-new-user"
Then the OCS status code should be "100"
And the HTTP status code should be "200"
And user "brand-new-user" does not exist
Scenario: Create a group
Given As an "admin"
And group "new-group" does not exist
When sending "POST" to "/cloud/groups" with
| groupid | new-group |
| password | 123456 |
Then the OCS status code should be "100"
And the HTTP status code should be "200"
And group "new-group" exists
Scenario: Delete a group
Given As an "admin"
And group "new-group" exists
When sending "DELETE" to "/cloud/groups/new-group"
Then the OCS status code should be "100"
And the HTTP status code should be "200"
And group "new-group" does not exist

View File

@ -5,5 +5,5 @@ Feature: provisioning
Scenario: Getting an not existing user
Given As an "admin"
When sending "GET" to "/cloud/users/test"
Then the status code should be "404"
Then the HTTP status code should be "404"