Skip to content

Commit

Permalink
test with core branch
Browse files Browse the repository at this point in the history
  • Loading branch information
SwikritiT committed Sep 5, 2022
1 parent 7f18716 commit bc834a7
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 126 deletions.
5 changes: 5 additions & 0 deletions .drone.env
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# The test runner source for API tests
<<<<<<< HEAD
CORE_COMMITID=b51fb4c01f08763e023aece4f90308e07a7ac73f
CORE_BRANCH=master
=======
CORE_COMMITID=6500d5fd867411fa0ba568b261c695f1b110266f
CORE_BRANCH=adjust-tus-code-to-reuse-on-ocis
>>>>>>> test with core branch

# The test runner source for UI tests
WEB_COMMITID=4828c892d292dbccd382104c11486bc5d21340b0
Expand Down
25 changes: 13 additions & 12 deletions tests/acceptance/features/apiSpaces/filePreviews.feature
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,18 @@ Feature: Preview file in project space


Scenario Outline: An user can preview image files in the project space
Given user "Alice" has uploaded a file "<entity>" via TUS inside of the space "previews of the files" using the WebDAV API
When user "Alice" downloads the preview of "<entity>" of the space "previews of the files" with width "<width>" and height "<height>" using the WebDAV API
Given using spaces DAV path
And user "Alice" has uploaded a file from "<source>" to "<destination>" via TUS inside of the space "previews of the files" using the WebDAV API
When user "Alice" downloads the preview of "<destination>" of the space "previews of the files" with width "<width>" and height "<height>" using the WebDAV API
Then the HTTP status code should be "200"
Examples:
| entity | width | height |
| testavatar.png | 36 | 36 |
| testavatar.png | 1200 | 1200 |
| testavatar.png | 1920 | 1920 |
| testavatar.jpg | 36 | 36 |
| testavatar.jpg | 1200 | 1200 |
| testavatar.jpg | 1920 | 1920 |
| example.gif | 36 | 36 |
| example.gif | 1200 | 1200 |
| example.gif | 1280 | 1280 |
| source | destination | width | height |
| filesForUpload/testavatar.png | testavatar.png | 36 | 36 |
| filesForUpload/testavatar.png | testavatar.png | 1200 | 1200 |
| filesForUpload/testavatar.png | testavatar.png | 1920 | 1920 |
| filesForUpload/testavatar.jpg | testavatar.jpg | 36 | 36 |
| filesForUpload/testavatar.jpg | testavatar.jpg | 1200 | 1200 |
| filesForUpload/testavatar.jpg | testavatar.jpg | 1920 | 1920 |
| filesForUpload/example.gif | example.gif | 36 | 36 |
| filesForUpload/example.gif | example.gif | 1200 | 1200 |
| filesForUpload/example.gif | example.gif | 1280 | 1280 |
5 changes: 3 additions & 2 deletions tests/acceptance/features/apiSpaces/tusUpload.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ Feature: upload resources using TUS protocol
| username |
| Alice |
And the administrator has given "Alice" the role "Space Admin" using the settings api
And using spaces DAV path


Scenario: upload a file within the set quota to a project space
Given user "Alice" has created a space "Project Jupiter" of type "project" with quota "10000"
When user "Alice" uploads a file with content "uploaded content" to "upload.txt" via TUS inside of the space "Project Jupiter" using the WebDAV API
Then the HTTP status code should be "204"
When user "Alice" uploads a file with content "uploaded content" to "/upload.txt" via TUS inside of the space "Project Jupiter" using the WebDAV API
Then the HTTP status code should be "200"
And for user "Alice" the space "Project Jupiter" should contain these entries:
| upload.txt |

Expand Down
139 changes: 27 additions & 112 deletions tests/acceptance/features/bootstrap/SpacesTusContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use GuzzleHttp\Exception\GuzzleException;
use TestHelpers\HttpRequestHelper;
use Behat\Gherkin\Node\TableNode;
use TestHelpers\WebDavHelper;

require_once 'bootstrap.php';

Expand Down Expand Up @@ -62,39 +63,44 @@ public function before(BeforeScenarioScope $scope): void {
}

/**
* @Given /^user "([^"]*)" has uploaded a file "([^"]*)" via TUS inside of the space "([^"]*)" using the WebDAV API$/
* @Given /^user "([^"]*)" has uploaded a file from "([^"]*)" to "([^"]*)" via TUS inside of the space "([^"]*)" using the WebDAV API$/
*
* @param string $user
* @param string $resource
* @param string $source
* @param string $destination
* @param string $spaceName
*
* @return void
*
* @throws Exception
* @throws GuzzleException
*/
public function uploadFileViaTus(string $user, string $resource, string $spaceName): void {
$this->userUploadsAFileViaTusInsideOfTheSpaceUsingTheWebdavApi($user, $resource, $spaceName);
$this->featureContext->theHTTPStatusCodeShouldBe(204, "Expected response status code should be 204");
public function userHasUploadedFileViaTusInSpace(string $user, string $source, string $destination, string $spaceName): void {
$this->userUploadsAFileViaTusInsideOfTheSpaceUsingTheWebdavApi($user, $source, $destination, $spaceName);
$this->featureContext->theHTTPStatusCodeShouldBe(200, "Expected response status code should be 204");
}

/**
* @When /^user "([^"]*)" uploads a file "([^"]*)" via TUS inside of the space "([^"]*)" using the WebDAV API$/
* @When /^user "([^"]*)" uploads a file from "([^"]*)" to "([^"]*)" via TUS inside of the space "([^"]*)" using the WebDAV API$/
*
* @param string $user
* @param string $resource
* @param string $source
* @param string $spaceName
* @param array|null $headers
* @param string $destination
* @param array|null $uploadMetadata
*
* @return void
*
* @throws Exception
* @throws GuzzleException
*/
public function userUploadsAFileViaTusInsideOfTheSpaceUsingTheWebdavApi(string $user, string $resource, string $spaceName, ?array $headers = null) {
$this->createTusResource($user, $resource, $spaceName, $headers);
$this->featureContext->theHTTPStatusCodeShouldBe(201, "Expected response status code should be 201");
$this->uploadResourceThroughTUS($user, $resource);
public function userUploadsAFileViaTusInsideOfTheSpaceUsingTheWebdavApi(string $user, string $source, string $destination, string $spaceName, ?array $uploadMetadata = null) {
$space = $this->spacesContext->getSpaceByName($user, $spaceName);
if (!WebDavHelper::$SPACE_ID_FROM_OCIS) {
WebDavHelper::$SPACE_ID_FROM_OCIS = $space['id'];
}
$this->tusContext->userUploadsUsingTusAFileTo($user, $source, $destination);
WebDavHelper::$SPACE_ID_FROM_OCIS = null;
}

/**
Expand All @@ -110,8 +116,7 @@ public function userUploadsAFileViaTusInsideOfTheSpaceUsingTheWebdavApi(string $
* @throws GuzzleException
*/
public function userHasCreatedANewTusResourceForTheSpaceUsingTheWebdavApiWithTheseHeaders(string $user, string $spaceName, TableNode $headers):void {
$this->featureContext->verifyTableNodeColumnsCount($headers, 2);
$this->createTusResource($user, "", $spaceName, $headers->getRowsHash());
$this->userCreatesANewTusResourceForTheSpaceUsingTheWebdavApiWithTheseHeaders($user, $spaceName, $headers);
$this->featureContext->theHTTPStatusCodeShouldBe(201, "Expected response status code should be 201");
}

Expand All @@ -128,22 +133,11 @@ public function userHasCreatedANewTusResourceForTheSpaceUsingTheWebdavApiWithThe
* @throws GuzzleException
*/
public function userCreatesANewTusResourceForTheSpaceUsingTheWebdavApiWithTheseHeaders(string $user, string $spaceName, TableNode $headers):void {
$this->featureContext->verifyTableNodeColumnsCount($headers, 2);
$this->createTusResource($user, "", $spaceName, $headers->getRowsHash());
}

/**
* @When /^user "([^"]*)" creates a new TUS resource "([^"]*)" for the space "([^"]*)" using the WebDAV API$/
*
* @param string $user
* @param string $resource
* @param string $spaceName
*
* @return void
* @throws Exception|GuzzleException
*/
public function userCreatesANewTusResourceForTheSpaceUsingTheWebdavApi(string $user, string $resource, string $spaceName):void {
$this->createTusResource($user, $resource, $spaceName);
$space = $this->spacesContext->getSpaceByName($user, $spaceName);
if (!WebDavHelper::$SPACE_ID_FROM_OCIS) {
WebDavHelper::$SPACE_ID_FROM_OCIS = $space['id'];
}
$this->tusContext->createNewTUSResourceWithHeaders($user, $headers, '');
}

/**
Expand All @@ -158,89 +152,10 @@ public function userCreatesANewTusResourceForTheSpaceUsingTheWebdavApi(string $u
* @throws Exception|GuzzleException
*/
public function userUploadsAFileWithContentToViaTusInsideOfTheSpaceUsingTheWebdavApi(string $user, string $content, string $resource, string $spaceName) {
$sourceFile = fopen($this->featureContext->acceptanceTestsDirLocation() . 'filesForUpload/' . $resource, "w");
fwrite($sourceFile, $content);
$this->userUploadsAFileViaTusInsideOfTheSpaceUsingTheWebdavApi($user, $resource, $spaceName);
fclose($sourceFile);
\unlink($this->featureContext->acceptanceTestsDirLocation() . 'filesForUpload/' . $resource);
}

/**
* send POST request to create the TUS resource
*
* @param string $user
* @param string|null $resource
* @param string $spaceName
* @param array|null $headers
*
* @return void
* @throws Exception|GuzzleException
*/
public function createTusResource(string $user, ?string $resource, string $spaceName, ?array $headers = null): void {
$space = $this->spacesContext->getSpaceByName($user, $spaceName);
$fullUrl = $this->baseUrl . "/remote.php/dav/spaces/" . $space["id"];

$tusEndpoint = "tusEndpoint " . base64_encode(str_replace("$", "%", $fullUrl));
if ($headers === null) {
$fileName = "filename " . base64_encode($resource);
$headers = [
"Tus-Resumable" => "1.0.0",
"Upload-Metadata" => $tusEndpoint . ',' . $fileName,
"Upload-Length" => filesize($this->featureContext->acceptanceTestsDirLocation() . 'filesForUpload/' . $resource)
];
}
$this->featureContext->setResponse(
HttpRequestHelper::post(
$fullUrl,
"",
$this->featureContext->getActualUsername($user),
$this->featureContext->getUserPassword($user),
$headers,
''
)
);
}

/**
* send PATCH request to upload resource through TUS
*
* @param string $user
* @param string $resource
*
* @return void
* @throws Exception|GuzzleException
*/
public function uploadResourceThroughTUS(string $user, string $resource): void {
$resourceLocation = $this->featureContext->getResponse()->getHeader('Location');
if (\sizeof($resourceLocation) > 0) {
$resourceLocation = $resourceLocation[0];
} else {
throw new \Exception(__METHOD__ . " Location header could not be found");
if (!WebDavHelper::$SPACE_ID_FROM_OCIS) {
WebDavHelper::$SPACE_ID_FROM_OCIS = $space['id'];
}
$file = \fopen($this->featureContext->acceptanceTestsDirLocation() . 'filesForUpload/' . $resource, 'r');

$this->featureContext->setResponse(
HttpRequestHelper::sendRequest(
$resourceLocation,
"",
'HEAD',
$user,
$this->featureContext->getPasswordForUser($user),
[],
""
)
);
$this->featureContext->theHTTPStatusCodeShouldBe(200, "Expected response status code should be 200");
$this->featureContext->setResponse(
HttpRequestHelper::sendRequest(
$resourceLocation,
"",
'PATCH',
$user,
$this->featureContext->getPasswordForUser($user),
["Tus-Resumable" => "1.0.0", "Upload-Offset" => 0, 'Content-Type' => 'application/offset+octet-stream'],
$file
)
);
$this->tusContext->userUploadsAFileWithContentToUsingTus($user, $content, $resource);
}
}

0 comments on commit bc834a7

Please sign in to comment.