From 4e694786254e3fc937185cfa87b94db4796abd37 Mon Sep 17 00:00:00 2001 From: Roshan Lamichhane Date: Mon, 30 Jan 2023 17:18:08 +0545 Subject: [PATCH 1/2] Added test scenarios for relative quota amount of personal space --- .../features/apiSpaces/quota.feature | 21 ++++++++++++++ .../features/bootstrap/SpacesContext.php | 29 +++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/tests/acceptance/features/apiSpaces/quota.feature b/tests/acceptance/features/apiSpaces/quota.feature index 72f29d5bf5a..fddcadf2362 100644 --- a/tests/acceptance/features/apiSpaces/quota.feature +++ b/tests/acceptance/features/apiSpaces/quota.feature @@ -65,3 +65,24 @@ Feature: State of the quota And user "Alice" has uploaded a file inside space "Project Delta" with content "7 bytes" to "test.txt" When user "Alice" uploads a file inside space "Project Delta" with content "00011 bytes" to "test.txt" using the WebDAV API Then the HTTP status code should be "507" + + + Scenario Outline: Check the relative amount of quota of personal space + Given user "Admin" has changed the quota of the personal space of "Alice Hansen" space to "10000" + And user "Alice" has uploaded file "" to "/demo.txt" + When the user "Alice" requests these endpoints with "GET" with basic auth + | endpoint | + | | + Then the HTTP status code should be "200" + And the json responded should contain these key and value pairs: + | key | value | + | quota@@@free | | + | quota@@@used | | + | quota@@@total | | + | quota@@@relative | | + Examples: + | file_upload | end_point | quota_free | quota_used | quota_total | quota_relative | + | /filesForUpload/lorem.txt | /ocs/v1.php/cloud/users/Alice?format=json | 9301 | 699 | 10000 | 6.99 | + | /filesForUpload/lorem-big.txt | /ocs/v1.php/cloud/users/Alice?format=json | 883 | 9117 | 10000 | 91.17 | + | /filesForUpload/lorem.txt | /ocs/v2.php/cloud/users/Alice?format=json | 9301 | 699 | 10000 | 6.99 | + | /filesForUpload/lorem-big.txt | /ocs/v2.php/cloud/users/Alice?format=json | 883 | 9117 | 10000 | 91.17 | diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index 6bbfd3f2fc5..a15eebcd5ca 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -3134,4 +3134,33 @@ public function publicDownloadsTheFolderFromTheLastCreatedPublicLink(string $res ) ); } + + /** + * @Then /^the json responded should contain these key and value pairs:$/ + * + * Loops through data items in response to find given key and value pairs + * It does not support field value replacing + * + * @param TableNode $table + * + * @return void + * @throws Exception + */ + public function theJsonRespondedShouldContainTheseKeyAndValuePairs(TableNode $table):void { + $this->featureContext->verifyTableNodeColumns($table, ['key', 'value']); + $response = json_decode((string)$this->featureContext->getResponse()->getBody(), true, 512, JSON_THROW_ON_ERROR); + $data = $response["ocs"]["data"]; + foreach ($table->getHash() as $row) { + $key = $row['key']; + $expectedValue = $row['value']; + $segments = explode('@@@', $key); + $actualValue = $data; + foreach ($segments as $segment) { + $arrayKeyExists = \array_key_exists($segment, $actualValue); + Assert::assertTrue($arrayKeyExists, "The key $segment does not exist on the response"); + $actualValue = $actualValue[$segment]; + } + Assert::assertEquals($expectedValue, $actualValue, "Expected $expectedValue but received $actualValue"); + } + } } From 15c152bd62207ab6969745ab6c2ea00a80f45ad7 Mon Sep 17 00:00:00 2001 From: Roshan Lamichhane Date: Thu, 2 Feb 2023 14:22:52 +0545 Subject: [PATCH 2/2] Added necessary helper function --- .../features/apiSpaces/quota.feature | 18 ++++------ .../features/bootstrap/OCSContext.php | 18 ++++++++++ .../features/bootstrap/SpacesContext.php | 34 ++++++++----------- 3 files changed, 39 insertions(+), 31 deletions(-) diff --git a/tests/acceptance/features/apiSpaces/quota.feature b/tests/acceptance/features/apiSpaces/quota.feature index fddcadf2362..3ba1bc5d8e3 100644 --- a/tests/acceptance/features/apiSpaces/quota.feature +++ b/tests/acceptance/features/apiSpaces/quota.feature @@ -74,15 +74,11 @@ Feature: State of the quota | endpoint | | | Then the HTTP status code should be "200" - And the json responded should contain these key and value pairs: - | key | value | - | quota@@@free | | - | quota@@@used | | - | quota@@@total | | - | quota@@@relative | | + And the OCS status code should be "" + And the relative quota amount should be "" Examples: - | file_upload | end_point | quota_free | quota_used | quota_total | quota_relative | - | /filesForUpload/lorem.txt | /ocs/v1.php/cloud/users/Alice?format=json | 9301 | 699 | 10000 | 6.99 | - | /filesForUpload/lorem-big.txt | /ocs/v1.php/cloud/users/Alice?format=json | 883 | 9117 | 10000 | 91.17 | - | /filesForUpload/lorem.txt | /ocs/v2.php/cloud/users/Alice?format=json | 9301 | 699 | 10000 | 6.99 | - | /filesForUpload/lorem-big.txt | /ocs/v2.php/cloud/users/Alice?format=json | 883 | 9117 | 10000 | 91.17 | + | file_upload | end_point | ocs_code | quota_relative | + | /filesForUpload/lorem.txt | /ocs/v1.php/cloud/users/%username% | 100 | 6.99 | + | /filesForUpload/lorem-big.txt | /ocs/v1.php/cloud/users/%username% | 100 | 91.17 | + | /filesForUpload/lorem.txt | /ocs/v2.php/cloud/users/%username% | 200 | 6.99 | + | /filesForUpload/lorem-big.txt | /ocs/v2.php/cloud/users/%username% | 200 | 91.17 | diff --git a/tests/acceptance/features/bootstrap/OCSContext.php b/tests/acceptance/features/bootstrap/OCSContext.php index 75f7ea6a8e4..afe400ab0c8 100644 --- a/tests/acceptance/features/bootstrap/OCSContext.php +++ b/tests/acceptance/features/bootstrap/OCSContext.php @@ -940,6 +940,24 @@ public function getOCSResponseStatusCode(ResponseInterface $response):string { ); } + /** + * Parses the xml answer to return data items from ocs response + * + * @param ResponseInterface $response + * + * @return SimpleXMLElement + * @throws Exception + */ + public function getOCSResponseData(ResponseInterface $response): SimpleXMLElement { + $responseXml = $this->featureContext->getResponseXml($response, __METHOD__); + if (isset($responseXml->data)) { + return $responseXml->data; + } + throw new Exception( + "No OCS data items found in responseXml" + ); + } + /** * Parses the xml answer to get ocs response message which doesn't match with * http one in v1 of the api. diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index a15eebcd5ca..58047e551fe 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -3136,31 +3136,25 @@ public function publicDownloadsTheFolderFromTheLastCreatedPublicLink(string $res } /** - * @Then /^the json responded should contain these key and value pairs:$/ + * @Then the relative quota amount should be :quota_amount * - * Loops through data items in response to find given key and value pairs - * It does not support field value replacing - * - * @param TableNode $table + * @param string $quotaAmount * * @return void * @throws Exception */ - public function theJsonRespondedShouldContainTheseKeyAndValuePairs(TableNode $table):void { - $this->featureContext->verifyTableNodeColumns($table, ['key', 'value']); - $response = json_decode((string)$this->featureContext->getResponse()->getBody(), true, 512, JSON_THROW_ON_ERROR); - $data = $response["ocs"]["data"]; - foreach ($table->getHash() as $row) { - $key = $row['key']; - $expectedValue = $row['value']; - $segments = explode('@@@', $key); - $actualValue = $data; - foreach ($segments as $segment) { - $arrayKeyExists = \array_key_exists($segment, $actualValue); - Assert::assertTrue($arrayKeyExists, "The key $segment does not exist on the response"); - $actualValue = $actualValue[$segment]; - } - Assert::assertEquals($expectedValue, $actualValue, "Expected $expectedValue but received $actualValue"); + public function theRelativeQuotaAmountShouldBe(string $quotaAmount): void { + $data = $this->ocsContext->getOCSResponseData($this->featureContext->getResponse()); + if (isset($data->quota, $data->quota->relative)) { + Assert::assertEquals( + $data->quota->relative, + $quotaAmount, + "Expected relative quota amount to be $quotaAmount but found to be $data->quota->relative" + ); + } else { + throw new Exception( + "No relative quota amount found in responseXml" + ); } } }