[tests-only][full-ci] Extend API contract tests for GET drives/spaces (#5151)

* do not set response from helper functions

* extend list spaces tests

* fix php code style
This commit is contained in:
Sawjan Gurung
2022-12-05 22:27:51 +05:45
committed by GitHub
parent b8a90b5335
commit 2469af12ac
2 changed files with 106 additions and 112 deletions

View File

@@ -14,14 +14,17 @@ Feature: List and create spaces
Scenario: An ordinary user can request information about their Space via the Graph API
When user "Alice" lists all available spaces via the GraphApi
Then the HTTP status code should be "200"
And the json responded should contain a space "Alice Hansen" with these key and value pairs:
| key | value |
| driveType | personal |
| driveAlias | personal/alice |
| id | %space_id% |
| name | Alice Hansen |
| quota@@@state | normal |
| root@@@webDavUrl | %base_url%/dav/spaces/%space_id% |
And the json responded should contain a space "Alice Hansen" owned by "Alice" with these key and value pairs:
| key | value |
| driveType | personal |
| driveAlias | personal/alice |
| id | %space_id% |
| name | Alice Hansen |
| owner@@@user@@@id | %user_id% |
| quota@@@state | normal |
| root@@@id | %space_id% |
| root@@@webDavUrl | %base_url%/dav/spaces/%space_id% |
| webUrl | %base_url%/f/%space_id% |
Scenario: An ordinary user can request information about their Space via the Graph API using a filter
@@ -33,7 +36,7 @@ Feature: List and create spaces
| key | value |
| driveType | virtual |
| id | %space_id% |
| name | Shares |
| name | Shares |
When user "Alice" lists all available spaces via the GraphApi with query "$filter=driveType eq 'personal'"
Then the HTTP status code should be "200"
And the json responded should contain a space "Alice Hansen" with these key and value pairs:
@@ -43,6 +46,7 @@ Feature: List and create spaces
| name | Alice Hansen |
| quota@@@state | normal |
| root@@@webDavUrl | %base_url%/dav/spaces/%space_id% |
| webUrl | %base_url%/f/%space_id% |
And the json responded should not contain a space with name "Shares"
And the json responded should only contain spaces of type "personal"
@@ -82,6 +86,7 @@ Feature: List and create spaces
| name | Project Mars |
| quota@@@total | 1000000000 |
| root@@@webDavUrl | %base_url%/dav/spaces/%space_id% |
| webUrl | %base_url%/f/%space_id% |
Scenario: An admin user can create a Space via the Graph API with certain quota
@@ -94,6 +99,7 @@ Feature: List and create spaces
| name | Project Venus |
| quota@@@total | 2000 |
| root@@@webDavUrl | %base_url%/dav/spaces/%space_id% |
| webUrl | %base_url%/f/%space_id% |
Scenario: A user can list his personal space via multiple endpoints
@@ -104,12 +110,14 @@ Feature: List and create spaces
| name | Alice Hansen |
| root@@@webDavUrl | %base_url%/dav/spaces/%space_id% |
| owner@@@user@@@id | %user_id% |
| webUrl | %base_url%/f/%space_id% |
When user "Alice" looks up the single space "Alice Hansen" via the GraphApi by using its id
Then the json responded should contain a space "Alice Hansen" with these key and value pairs:
| key | value |
| driveType | personal |
| name | Alice Hansen |
| root@@@webDavUrl | %base_url%/dav/spaces/%space_id% |
| webUrl | %base_url%/f/%space_id% |
Scenario: A user can list his created spaces via multiple endpoints
@@ -123,6 +131,7 @@ Feature: List and create spaces
| name | Project Venus |
| quota@@@total | 2000 |
| root@@@webDavUrl | %base_url%/dav/spaces/%space_id% |
| webUrl | %base_url%/f/%space_id% |
When user "Alice" looks up the single space "Project Venus" via the GraphApi by using its id
Then the json responded should contain a space "Project Venus" with these key and value pairs:
| key | value |
@@ -131,3 +140,4 @@ Feature: List and create spaces
| name | Project Venus |
| quota@@@total | 2000 |
| root@@@webDavUrl | %base_url%/dav/spaces/%space_id% |
| webUrl | %base_url%/f/%space_id% |

View File

@@ -300,21 +300,14 @@ class SpacesContext implements Context {
$space = $this->getSpaceByName($user, $spaceName);
$fullUrl = $this->baseUrl . $this->davSpacesUrl . $space["id"] . "/" . $fileName;
$this->featureContext->setResponse(
HttpRequestHelper::get(
$fullUrl,
"",
$user,
$this->featureContext->getPasswordForUser($user),
[],
"{}"
)
return HttpRequestHelper::get(
$fullUrl,
"",
$user,
$this->featureContext->getPasswordForUser($user),
[],
"{}"
);
$this->featureContext->theHTTPStatusCodeShouldBe(
200,
"file $fileName not found"
);
return $this->featureContext->getResponse();
}
/**
@@ -349,17 +342,15 @@ class SpacesContext implements Context {
$folderName = '';
}
$fullUrl = $this->baseUrl . $this->davSpacesUrl . $space["id"] . "/" . $folderName;
$this->featureContext->setResponse(
HttpRequestHelper::sendRequest(
$fullUrl,
$this->featureContext->getStepLineRef(),
'PROPFIND',
$user,
$this->featureContext->getPasswordForUser($user),
['Depth' => '0'],
)
$response = HttpRequestHelper::sendRequest(
$fullUrl,
$this->featureContext->getStepLineRef(),
'PROPFIND',
$user,
$this->featureContext->getPasswordForUser($user),
['Depth' => '0'],
);
$responseArray = json_decode(json_encode($this->featureContext->getResponseXml()->xpath("//d:response/d:propstat/d:prop/oc:fileid")), true, 512, JSON_THROW_ON_ERROR);
$responseArray = json_decode(json_encode($this->featureContext->getResponseXml($response)->xpath("//d:response/d:propstat/d:prop/oc:fileid")), true, 512, JSON_THROW_ON_ERROR);
Assert::assertNotEmpty($responseArray, "the PROPFIND response for $folderName is empty");
return $responseArray[0][0];
}
@@ -388,20 +379,17 @@ class SpacesContext implements Context {
* @throws Exception|GuzzleException
*/
public function getUserIdByUserName(string $userName): string {
$this->featureContext->setResponse(
GraphHelper::getUser(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$this->featureContext->getAdminUsername(),
$this->featureContext->getAdminPassword(),
$userName
)
$response = GraphHelper::getUser(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$this->featureContext->getAdminUsername(),
$this->featureContext->getAdminPassword(),
$userName
);
if ($this->featureContext->getResponse()) {
$rawBody = $this->featureContext->getResponse()->getBody()->getContents();
$response = \json_decode($rawBody, true, 512, JSON_THROW_ON_ERROR);
if (isset($response["id"])) {
return $response["id"];
if ($response) {
$data = \json_decode($response->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR);
if (isset($data["id"])) {
return $data["id"];
} else {
throw new Exception(__METHOD__ . " accounts-list is empty");
}
@@ -484,22 +472,18 @@ class SpacesContext implements Context {
foreach ($drives as $value) {
if (!\array_key_exists("deleted", $value["root"])) {
$this->featureContext->setResponse(
GraphHelper::disableSpace(
$this->featureContext->getBaseUrl(),
$userAdmin,
$this->featureContext->getPasswordForUser($userAdmin),
$value["id"]
)
);
}
$this->featureContext->setResponse(
GraphHelper::deleteSpace(
GraphHelper::disableSpace(
$this->featureContext->getBaseUrl(),
$userAdmin,
$this->featureContext->getPasswordForUser($userAdmin),
$value["id"]
)
);
}
GraphHelper::deleteSpace(
$this->featureContext->getBaseUrl(),
$userAdmin,
$this->featureContext->getPasswordForUser($userAdmin),
$value["id"]
);
}
}
@@ -589,15 +573,13 @@ class SpacesContext implements Context {
* @throws Exception
*/
public function theUserListsAllAvailableSpacesUsingTheGraphApi(string $user, string $query = ''): void {
$this->featureContext->setResponse(
GraphHelper::getAllSpaces(
$this->featureContext->getBaseUrl(),
$user,
$this->featureContext->getPasswordForUser($user),
"?" . $query
)
$response = GraphHelper::getAllSpaces(
$this->featureContext->getBaseUrl(),
$user,
$this->featureContext->getPasswordForUser($user),
"?" . $query
);
$this->rememberTheAvailableSpaces();
$this->rememberTheAvailableSpaces($response);
}
/**
@@ -690,12 +672,18 @@ class SpacesContext implements Context {
/**
* Remember the available Spaces
*
* @param ResponseInterface|null $response
*
* @return void
*
* @throws Exception
*/
public function rememberTheAvailableSpaces(): void {
$rawBody = $this->featureContext->getResponse()->getBody()->getContents();
public function rememberTheAvailableSpaces(?ResponseInterface $response = null): void {
if ($response) {
$rawBody = $response->getBody()->getContents();
} else {
$rawBody = $this->featureContext->getResponse()->getBody()->getContents();
}
$drives = json_decode($rawBody, true, 512, JSON_THROW_ON_ERROR);
if (isset($drives["value"])) {
$drives = $drives["value"];
@@ -1521,7 +1509,7 @@ class SpacesContext implements Context {
);
$fullUrl = $space["root"]["webDavUrl"] . '/' . ltrim($fileSource, "/");
$this->copyFilesAndFoldersRequest($user, $fullUrl, $headers);
$this->featureContext->setResponse($this->copyFilesAndFoldersRequest($user, $fullUrl, $headers));
}
/**
@@ -1550,7 +1538,8 @@ class SpacesContext implements Context {
$fileSource = $this->escapePath(\trim($fileSource, "/"));
$fullUrl = $space["root"]["webDavUrl"] . '/' . $fileSource;
$this->moveFilesAndFoldersRequest($user, $fullUrl, $headers);
$this->featureContext->setResponse($this->moveFilesAndFoldersRequest($user, $fullUrl, $headers));
$this->featureContext->pushToLastHttpStatusCodesArray();
}
/**
@@ -1591,22 +1580,17 @@ class SpacesContext implements Context {
* @param string $fullUrl
* @param string $headers
*
* @return void
* @return ResponseInterface
* @throws GuzzleException
*/
public function moveFilesAndFoldersRequest(string $user, string $fullUrl, array $headers):void {
$this->featureContext->setResponse(
HttpRequestHelper::sendRequest(
$fullUrl,
$this->featureContext->getStepLineRef(),
'MOVE',
$user,
$this->featureContext->getPasswordForUser($user),
$headers,
)
);
$this->featureContext->pushToLastHttpStatusCodesArray(
(string)$this->featureContext->getResponse()->getStatusCode()
public function moveFilesAndFoldersRequest(string $user, string $fullUrl, array $headers): ResponseInterface {
return HttpRequestHelper::sendRequest(
$fullUrl,
$this->featureContext->getStepLineRef(),
'MOVE',
$user,
$this->featureContext->getPasswordForUser($user),
$headers,
);
}
@@ -1632,7 +1616,7 @@ class SpacesContext implements Context {
$space = $this->getSpaceByName($user, $fromSpaceName);
$headers['Destination'] = $this->destinationHeaderValueWithSpaceName($user, $fileDestination, $toSpaceName);
$fullUrl = $space["root"]["webDavUrl"] . '/' . ltrim($fileSource, "/");
$this->copyFilesAndFoldersRequest($user, $fullUrl, $headers);
$this->featureContext->setResponse($this->copyFilesAndFoldersRequest($user, $fullUrl, $headers));
}
/**
@@ -1661,10 +1645,12 @@ class SpacesContext implements Context {
$headers['Overwrite'] = 'T';
$fullUrl = $space["root"]["webDavUrl"] . '/' . ltrim($fileSource, "/");
if ($action === 'copying') {
$this->copyFilesAndFoldersRequest($user, $fullUrl, $headers);
$response = $this->copyFilesAndFoldersRequest($user, $fullUrl, $headers);
} else {
$this->moveFilesAndFoldersRequest($user, $fullUrl, $headers);
$response = $this->moveFilesAndFoldersRequest($user, $fullUrl, $headers);
}
$this->featureContext->setResponse($response);
$this->featureContext->pushToLastHttpStatusCodesArray();
}
/**
@@ -1721,7 +1707,8 @@ class SpacesContext implements Context {
$space = $this->getSpaceByName($user, $fromSpaceName);
$headers['Destination'] = $this->destinationHeaderValueWithSpaceName($user, $fileDestination, $toSpaceName);
$fullUrl = $space["root"]["webDavUrl"] . '/' . \ltrim($fileSource, "/");
$this->moveFilesAndFoldersRequest($user, $fullUrl, $headers);
$this->featureContext->setResponse($this->moveFilesAndFoldersRequest($user, $fullUrl, $headers));
$this->featureContext->pushToLastHttpStatusCodesArray();
}
/**
@@ -1749,19 +1736,17 @@ class SpacesContext implements Context {
* @param string $fullUrl
* @param array $headers
*
* @return void
* @return ResponseInterface
* @throws GuzzleException
*/
public function copyFilesAndFoldersRequest(string $user, string $fullUrl, array $headers):void {
$this->featureContext->setResponse(
HttpRequestHelper::sendRequest(
$fullUrl,
$this->featureContext->getStepLineRef(),
'COPY',
$user,
$this->featureContext->getPasswordForUser($user),
$headers,
)
public function copyFilesAndFoldersRequest(string $user, string $fullUrl, array $headers): ResponseInterface {
return HttpRequestHelper::sendRequest(
$fullUrl,
$this->featureContext->getStepLineRef(),
'COPY',
$user,
$this->featureContext->getPasswordForUser($user),
$headers,
);
}
@@ -1837,10 +1822,10 @@ class SpacesContext implements Context {
* @param string $userRecipient
* @param string $role
*
* @return void
* @return ResponseInterface
* @throws GuzzleException
*/
public function sendRequestForShareOfEntityInsideOfSpace(string $user, string $entity, string $spaceName, string $userRecipient, string $role):void {
public function sendRequestForShareOfEntityInsideOfSpace(string $user, string $entity, string $spaceName, string $userRecipient, string $role): ResponseInterface {
$space = $this->getSpaceByName($user, $spaceName);
$body = [
"space_ref" => $space['id'] . "/" . $entity,
@@ -1850,15 +1835,12 @@ class SpacesContext implements Context {
];
$fullUrl = $this->baseUrl . $this->ocsApiUrl;
$this->featureContext->setResponse(
$this->sendPostRequestToUrl(
$fullUrl,
$user,
$this->featureContext->getPasswordForUser($user),
$body
)
return $this->sendPostRequestToUrl(
$fullUrl,
$user,
$this->featureContext->getPasswordForUser($user),
$body
);
$this->setLastShareData();
}
/**
@@ -1880,7 +1862,8 @@ class SpacesContext implements Context {
string $userRecipient,
string $role
): void {
$this->sendRequestForShareOfEntityInsideOfSpace($user, $entity, $spaceName, $userRecipient, $role);
$this->featureContext->setResponse($this->sendRequestForShareOfEntityInsideOfSpace($user, $entity, $spaceName, $userRecipient, $role));
$this->setLastShareData();
}
/**
@@ -1902,8 +1885,9 @@ class SpacesContext implements Context {
string $userRecipient,
string $role
): void {
$this->sendRequestForShareOfEntityInsideOfSpace($user, $entity, $spaceName, $userRecipient, $role);
$this->featureContext->theHTTPStatusCodeShouldBe(
$response = $this->sendRequestForShareOfEntityInsideOfSpace($user, $entity, $spaceName, $userRecipient, $role);
Assert:assertEquals(
$response->getStatusCode(),
200,
"Expected response status code should be 200"
);