Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
b2040837
Commit
b2040837
authored
Dec 05, 2017
by
Travis Miller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add project export API tests
parent
0bf6ed2e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
290 additions
and
0 deletions
+290
-0
spec/requests/api/project_export_spec.rb
spec/requests/api/project_export_spec.rb
+290
-0
No files found.
spec/requests/api/project_export_spec.rb
0 → 100644
View file @
b2040837
require
'spec_helper'
describe
API
::
ProjectExport
do
set
(
:project
)
{
create
(
:project
)
}
set
(
:project_none
)
{
create
(
:project
,
path:
'export-none'
)
}
set
(
:project_started
)
{
create
(
:project
,
path:
'export-started'
)
}
set
(
:project_finished
)
{
create
(
:project
,
path:
'export-finished'
)
}
set
(
:user
)
{
create
(
:user
)
}
set
(
:admin
)
{
create
(
:admin
)
}
let
(
:path
)
{
"/projects/
#{
project
.
id
}
/export"
}
let
(
:path_none
)
{
"/projects/
#{
project_none
.
id
}
/export"
}
let
(
:path_started
)
{
"/projects/
#{
project_started
.
id
}
/export"
}
let
(
:path_finished
)
{
"/projects/
#{
project_finished
.
id
}
/export"
}
let
(
:download_path
)
{
"/projects/
#{
project
.
id
}
/export/download"
}
let
(
:download_path_none
)
{
"/projects/
#{
project_none
.
id
}
/export/download"
}
let
(
:download_path_started
)
{
"/projects/
#{
project_started
.
id
}
/export/download"
}
let
(
:download_path_finished
)
{
"/projects/
#{
project_finished
.
id
}
/export/download"
}
let
(
:export_path
)
{
"
#{
Dir
.
tmpdir
}
/project_export_spec"
}
before
do
allow_any_instance_of
(
Gitlab
::
ImportExport
).
to
receive
(
:storage_path
).
and_return
(
export_path
)
# simulate exporting work directory
FileUtils
.
mkdir_p
File
.
join
(
project_started
.
export_path
,
'securerandom-hex'
)
# simulate exported
FileUtils
.
mkdir_p
project_finished
.
export_path
FileUtils
.
touch
File
.
join
(
project_finished
.
export_path
,
'_export.tar.gz'
)
end
after
do
FileUtils
.
rm_rf
(
export_path
,
secure:
true
)
end
shared_examples_for
'when project export is disabled'
do
before
do
stub_application_setting
(
project_export_enabled?:
false
)
end
it_behaves_like
'404 response'
end
describe
'GET /projects/:project_id/export'
do
shared_examples_for
'get project export status not found'
do
it_behaves_like
'404 response'
do
let
(
:request
)
{
get
api
(
path
,
user
)
}
end
end
shared_examples_for
'get project export status denied'
do
it_behaves_like
'403 response'
do
let
(
:request
)
{
get
api
(
path
,
user
)
}
end
end
shared_examples_for
'get project export status ok'
do
it
'is none'
do
get
api
(
path_none
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
match_response_schema
(
'public_api/v4/project/export_status'
)
expect
(
json_response
[
'export_status'
]).
to
eq
(
'none'
)
end
it
'is started'
do
get
api
(
path_started
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
match_response_schema
(
'public_api/v4/project/export_status'
)
expect
(
json_response
[
'export_status'
]).
to
eq
(
'started'
)
end
it
'is finished'
do
get
api
(
path_finished
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
match_response_schema
(
'public_api/v4/project/export_status'
)
expect
(
json_response
[
'export_status'
]).
to
eq
(
'finished'
)
end
end
it_behaves_like
'when project export is disabled'
do
let
(
:request
)
{
get
api
(
path
,
admin
)
}
end
context
'when project export is enabled'
do
context
'when user is an admin'
do
let
(
:user
)
{
admin
}
it_behaves_like
'get project export status ok'
end
context
'when user is a master'
do
before
do
project
.
add_master
(
user
)
project_none
.
add_master
(
user
)
project_started
.
add_master
(
user
)
project_finished
.
add_master
(
user
)
end
it_behaves_like
'get project export status ok'
end
context
'when user is a developer'
do
before
do
project
.
add_developer
(
user
)
end
it_behaves_like
'get project export status denied'
end
context
'when user is a reporter'
do
before
do
project
.
add_reporter
(
user
)
end
it_behaves_like
'get project export status denied'
end
context
'when user is a guest'
do
before
do
project
.
add_guest
(
user
)
end
it_behaves_like
'get project export status denied'
end
context
'when user is not a member'
do
it_behaves_like
'get project export status not found'
end
end
end
describe
'GET /projects/:project_id/export/download'
do
shared_examples_for
'get project export download not found'
do
it_behaves_like
'404 response'
do
let
(
:request
)
{
get
api
(
download_path
,
user
)
}
end
end
shared_examples_for
'get project export download denied'
do
it_behaves_like
'403 response'
do
let
(
:request
)
{
get
api
(
download_path
,
user
)
}
end
end
shared_examples_for
'get project export download'
do
it_behaves_like
'404 response'
do
let
(
:request
)
{
get
api
(
download_path_none
,
user
)
}
end
it_behaves_like
'404 response'
do
let
(
:request
)
{
get
api
(
download_path_started
,
user
)
}
end
it
'downloads'
do
get
api
(
download_path_finished
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
end
end
it_behaves_like
'when project export is disabled'
do
let
(
:request
)
{
get
api
(
download_path
,
admin
)
}
end
context
'when project export is enabled'
do
context
'when user is an admin'
do
let
(
:user
)
{
admin
}
it_behaves_like
'get project export download'
end
context
'when user is a master'
do
before
do
project
.
add_master
(
user
)
project_none
.
add_master
(
user
)
project_started
.
add_master
(
user
)
project_finished
.
add_master
(
user
)
end
it_behaves_like
'get project export download'
end
context
'when user is a developer'
do
before
do
project
.
add_developer
(
user
)
end
it_behaves_like
'get project export download denied'
end
context
'when user is a reporter'
do
before
do
project
.
add_reporter
(
user
)
end
it_behaves_like
'get project export download denied'
end
context
'when user is a guest'
do
before
do
project
.
add_guest
(
user
)
end
it_behaves_like
'get project export download denied'
end
context
'when user is not a member'
do
it_behaves_like
'get project export download not found'
end
end
end
describe
'POST /projects/:project_id/export'
do
shared_examples_for
'post project export start not found'
do
it_behaves_like
'404 response'
do
let
(
:request
)
{
post
api
(
path
,
user
)
}
end
end
shared_examples_for
'post project export start denied'
do
it_behaves_like
'403 response'
do
let
(
:request
)
{
post
api
(
path
,
user
)
}
end
end
shared_examples_for
'post project export start'
do
it
'starts'
do
post
api
(
path
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
202
)
end
end
it_behaves_like
'when project export is disabled'
do
let
(
:request
)
{
post
api
(
path
,
admin
)
}
end
context
'when project export is enabled'
do
context
'when user is an admin'
do
let
(
:user
)
{
admin
}
it_behaves_like
'post project export start'
end
context
'when user is a master'
do
before
do
project
.
add_master
(
user
)
project_none
.
add_master
(
user
)
project_started
.
add_master
(
user
)
project_finished
.
add_master
(
user
)
end
it_behaves_like
'post project export start'
end
context
'when user is a developer'
do
before
do
project
.
add_developer
(
user
)
end
it_behaves_like
'post project export start denied'
end
context
'when user is a reporter'
do
before
do
project
.
add_reporter
(
user
)
end
it_behaves_like
'post project export start denied'
end
context
'when user is a guest'
do
before
do
project
.
add_guest
(
user
)
end
it_behaves_like
'post project export start denied'
end
context
'when user is not a member'
do
it_behaves_like
'post project export start not found'
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment