Skip to content

Commit

Permalink
More API test for file versions
Browse files Browse the repository at this point in the history
  • Loading branch information
paurakhsharma authored and phil-davis committed Jun 7, 2018
1 parent c5da7de commit cbc1fc0
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 1 deletion.
84 changes: 83 additions & 1 deletion tests/acceptance/features/apiMain/dav-versions.feature
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,86 @@ Feature: dav-versions
And user "user1" has uploaded file with content "user1 content" to "/sharefile.txt"
When user "user0" restores version index "1" of file "/sharefile.txt" using the API
Then the HTTP status code should be "204"
And the downloaded content when downloading file "/sharefile.txt" for user "user0" with range "bytes=0-12" should be "user0 content"
And the downloaded content when downloading file "/sharefile.txt" for user "user0" with range "bytes=0-12" should be "user0 content"

Scenario: sharer restores the file inside a shared folder modified by sharee
Given user "user0" has been created
And user "user1" has been created
And user "user0" has created a folder "/sharingfolder"
And user "user0" has shared folder "/sharingfolder" with user "user1"
And user "user0" has uploaded file with content "user0 content" to "/sharingfolder/sharefile.txt"
And user "user1" has uploaded file with content "user1 content" to "/sharingfolder/sharefile.txt"
When user "user0" restores version index "1" of file "/sharingfolder/sharefile.txt" using the API
Then the HTTP status code should be "204"
And the downloaded content when downloading file "/sharingfolder/sharefile.txt" for user "user0" with range "bytes=0-12" should be "user0 content"

Scenario: sharee restores the file inside a shared folder modified by sharee
Given user "user0" has been created
And user "user1" has been created
And user "user0" has created a folder "/sharingfolder"
And user "user0" has shared folder "/sharingfolder" with user "user1"
And user "user0" has uploaded file with content "user0 content" to "/sharingfolder/sharefile.txt"
And user "user1" has uploaded file with content "user1 content" to "/sharingfolder/sharefile.txt"
When user "user1" restores version index "1" of file "/sharingfolder/sharefile.txt" using the API
Then the HTTP status code should be "204"
And the downloaded content when downloading file "/sharingfolder/sharefile.txt" for user "user1" with range "bytes=0-12" should be "user0 content"

Scenario: sharer restores the file inside a shared folder created by sharee and modified by sharer
Given user "user0" has been created
And user "user1" has been created
And user "user0" has created a folder "/sharingfolder"
And user "user0" has shared folder "/sharingfolder" with user "user1"
And user "user1" has uploaded file with content "user1 content" to "/sharingfolder/sharefile.txt"
And user "user0" has uploaded file with content "user0 content" to "/sharingfolder/sharefile.txt"
When user "user0" restores version index "1" of file "/sharingfolder/sharefile.txt" using the API
Then the HTTP status code should be "204"
And the downloaded content when downloading file "/sharingfolder/sharefile.txt" for user "user0" with range "bytes=0-12" should be "user1 content"

Scenario: sharee restores the file inside a shared folder created by sharee and modified by sharer
Given user "user0" has been created
And user "user1" has been created
And user "user0" has created a folder "/sharingfolder"
And user "user0" has shared folder "/sharingfolder" with user "user1"
And user "user1" has uploaded file with content "user1 content" to "/sharingfolder/sharefile.txt"
And user "user0" has uploaded file with content "user0 content" to "/sharingfolder/sharefile.txt"
When user "user1" restores version index "1" of file "/sharingfolder/sharefile.txt" using the API
Then the HTTP status code should be "204"
And the downloaded content when downloading file "/sharingfolder/sharefile.txt" for user "user1" with range "bytes=0-12" should be "user1 content"

Scenario: sharer restores the file inside a shared folder created by sharee and modified by sharee
Given user "user0" has been created
And user "user1" has been created
And user "user0" has created a folder "/sharingfolder"
And user "user0" has shared folder "/sharingfolder" with user "user1"
And user "user1" has uploaded file with content "old content" to "/sharingfolder/sharefile.txt"
And user "user1" has uploaded file with content "new content" to "/sharingfolder/sharefile.txt"
When user "user0" restores version index "1" of file "/sharingfolder/sharefile.txt" using the API
Then the HTTP status code should be "204"
And the downloaded content when downloading file "/sharingfolder/sharefile.txt" for user "user0" with range "bytes=0-12" should be "old content"

Scenario: sharee restores the file inside a shared folder created by sharer and modified by sharer
Given user "user0" has been created
And user "user1" has been created
And user "user0" has created a folder "/sharingfolder"
And user "user0" has shared folder "/sharingfolder" with user "user1"
And user "user0" has uploaded file with content "old content" to "/sharingfolder/sharefile.txt"
And user "user0" has uploaded file with content "new content" to "/sharingfolder/sharefile.txt"
When user "user1" restores version index "1" of file "/sharingfolder/sharefile.txt" using the API
Then the HTTP status code should be "204"
And the downloaded content when downloading file "/sharingfolder/sharefile.txt" for user "user1" with range "bytes=0-12" should be "old content"

Scenario: sharer restores the file inside a group shared folder modified by sharee
Given user "user0" has been created
And user "user1" has been created
And user "user2" has been created
And group "newgroup" has been created
And user "user1" has been added to group "newgroup"
And user "user2" has been added to group "newgroup"
And user "user0" has created a folder "/sharingfolder"
And user "user0" has shared folder "/sharingfolder" with group "newgroup"
And user "user0" has uploaded file with content "user0 content" to "/sharingfolder/sharefile.txt"
And user "user1" has uploaded file with content "user1 content" to "/sharingfolder/sharefile.txt"
And user "user2" has uploaded file with content "user2 content" to "/sharingfolder/sharefile.txt"
When user "user0" restores version index "2" of file "/sharingfolder/sharefile.txt" using the API
Then the HTTP status code should be "204"
And the downloaded content when downloading file "/sharingfolder/sharefile.txt" for user "user0" with range "bytes=0-12" should be "user0 content"
12 changes: 12 additions & 0 deletions tests/acceptance/features/bootstrap/WebDav.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ trait WebDav {
*/
private $storedFileID = null;

/**
* @var int
*/
private $lastUploadTime = null;

/**
* a variable that contains the dav path without "remote.php/(web)dav"
* when setting $this->davPath directly by usingDavPath()
Expand Down Expand Up @@ -1395,9 +1400,16 @@ public function userUploadsAFileWithContentTo(
) {
$file = \GuzzleHttp\Stream\Stream::factory($content);
try {
$time = \time();
if ($this->lastUploadTime !== null && $time - $this->lastUploadTime < 1) {
// prevent creating two uploads with the same "stime" which is
// based on seconds, this prevents creation of uploads with same etag
\sleep(1);
}
$this->response = $this->makeDavRequest(
$user, "PUT", $destination, [], $file
);
$this->lastUploadTime = \time();
return $this->response->getHeader('oc-fileid');
} catch (BadResponseException $e) {
// 4xx and 5xx responses cause an exception
Expand Down

0 comments on commit cbc1fc0

Please sign in to comment.