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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
190afc62
Commit
190afc62
authored
Nov 02, 2018
by
Mark Lapierre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create users via the API
Allows users to be fetched/created via the API.
parent
74b5dce4
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
89 additions
and
42 deletions
+89
-42
qa/qa/factory/api_fabricator.rb
qa/qa/factory/api_fabricator.rb
+6
-2
qa/qa/factory/resource/fork.rb
qa/qa/factory/resource/fork.rb
+8
-35
qa/qa/factory/resource/user.rb
qa/qa/factory/resource/user.rb
+36
-0
qa/qa/specs/features/browser_ui/1_manage/login/register_spec.rb
...specs/features/browser_ui/1_manage/login/register_spec.rb
+1
-1
qa/qa/specs/features/browser_ui/1_manage/project/add_project_member_spec.rb
...es/browser_ui/1_manage/project/add_project_member_spec.rb
+2
-4
qa/spec/factory/resource/user_spec.rb
qa/spec/factory/resource/user_spec.rb
+36
-0
No files found.
qa/qa/factory/api_fabricator.rb
View file @
190afc62
...
...
@@ -52,14 +52,18 @@ module QA
end
def
api_get
url
=
Runtime
::
API
::
Request
.
new
(
api_client
,
api_get_path
).
url
process_api_response
(
parse_body
(
api_get_from
(
api_get_path
)))
end
def
api_get_from
(
get_path
)
url
=
Runtime
::
API
::
Request
.
new
(
api_client
,
get_path
).
url
response
=
get
(
url
)
unless
response
.
code
==
HTTP_STATUS_OK
raise
ResourceNotFoundError
,
"Resource at
#{
url
}
could not be found (
#{
response
.
code
}
): `
#{
response
}
`."
end
process_api_response
(
parse_body
(
response
))
response
end
def
api_post
...
...
qa/qa/factory/resource/fork.rb
View file @
190afc62
...
...
@@ -15,44 +15,17 @@ module QA
end
end
def
visit_project_with_retry
# The user intermittently fails to stay signed in after visiting the
# project page. The new user is registered and then signs in and a
# screenshot shows that signing in was successful. Then the project
# page is visited but a screenshot shows the user is no longer signed
# in. It's difficult to reproduce locally but GDK logs don't seem to
# show anything unexpected. This method attempts to work around the
# problem and capture data to help troubleshoot.
Capybara
::
Screenshot
.
screenshot_and_save_page
start
=
Time
.
now
while
Time
.
now
-
start
<
20
push
.
project
.
visit!
puts
"Visited project page"
Capybara
::
Screenshot
.
screenshot_and_save_page
return
if
Page
::
Main
::
Menu
.
act
{
has_personal_area?
(
wait:
0
)
}
puts
"Not signed in. Attempting to sign in again."
Capybara
::
Screenshot
.
screenshot_and_save_page
Runtime
::
Browser
.
visit
(
:gitlab
,
Page
::
Main
::
Login
)
Page
::
Main
::
Login
.
perform
do
|
login
|
login
.
sign_in_using_credentials
(
user
)
end
end
raise
"Failed to load project page and stay logged in"
end
def
fabricate!
populate
(
:push
,
:user
)
visit_project_with_retry
# Sign out as admin and sign is as the fork user
Page
::
Main
::
Menu
.
perform
(
&
:sign_out
)
Runtime
::
Browser
.
visit
(
:gitlab
,
Page
::
Main
::
Login
)
Page
::
Main
::
Login
.
perform
do
|
login
|
login
.
sign_in_using_credentials
(
user
)
end
push
.
project
.
visit!
Page
::
Project
::
Show
.
perform
(
&
:fork_project
)
...
...
qa/qa/factory/resource/user.rb
View file @
190afc62
...
...
@@ -50,6 +50,42 @@ module QA
end
end
end
def
fabricate_via_api!
resource_web_url
(
api_get
)
rescue
ResourceNotFoundError
super
end
def
api_get_path
"/users/
#{
fetch_id
(
username
)
}
"
end
def
api_post_path
'/users'
end
def
api_post_body
{
email:
email
,
password:
password
,
username:
username
,
name:
name
,
skip_confirmation:
true
}
end
private
def
fetch_id
(
username
)
users
=
parse_body
(
api_get_from
(
"/users?username=
#{
username
}
"
))
unless
users
.
size
==
1
&&
users
.
first
[
:username
]
==
username
raise
ResourceNotFoundError
,
"Expected one user with username
#{
username
}
but found: `
#{
users
}
`."
end
users
.
first
[
:id
]
end
end
end
end
...
...
qa/qa/specs/features/browser_ui/1_manage/login/register_spec.rb
View file @
190afc62
...
...
@@ -5,7 +5,7 @@ module QA
it
'user registers and logs in'
do
Runtime
::
Browser
.
visit
(
:gitlab
,
Page
::
Main
::
Login
)
Factory
::
Resource
::
User
.
fabricate!
Factory
::
Resource
::
User
.
fabricate
_via_browser_ui
!
# TODO, since `Signed in successfully` message was removed
# this is the only way to tell if user is signed in correctly.
...
...
qa/qa/specs/features/browser_ui/1_manage/project/add_project_member_spec.rb
View file @
190afc62
...
...
@@ -5,18 +5,16 @@ module QA
describe
'Add project member'
do
it
'user adds project member'
do
Runtime
::
Browser
.
visit
(
:gitlab
,
Page
::
Main
::
Login
)
Page
::
Main
::
Login
.
perform
(
&
:sign_in_using_credentials
)
user
=
Factory
::
Resource
::
User
.
fabricate!
Page
::
Main
::
Menu
.
perform
{
|
main
|
main
.
sign_out
}
Page
::
Main
::
Login
.
act
{
sign_in_using_credentials
}
project
=
Factory
::
Resource
::
Project
.
fabricate!
do
|
resource
|
resource
.
name
=
'add-member-project'
end
project
.
visit!
Page
::
Project
::
Menu
.
act
{
click_members_settings
}
Page
::
Project
::
Menu
.
perform
(
&
:click_members_settings
)
Page
::
Project
::
Settings
::
Members
.
perform
do
|
page
|
page
.
add_member
(
user
.
username
)
end
...
...
qa/spec/factory/resource/user_spec.rb
0 → 100644
View file @
190afc62
# frozen_string_literal: true
describe
QA
::
Factory
::
Resource
::
User
do
describe
"#fabricate_via_api!"
do
Response
=
Struct
.
new
(
:code
,
:body
)
it
'fetches an existing user'
do
existing_users
=
[
{
id:
'0'
,
name:
'name'
,
username:
'name'
,
web_url:
''
}
]
users_response
=
Response
.
new
(
'200'
,
JSON
.
dump
(
existing_users
))
single_user_response
=
Response
.
new
(
'200'
,
JSON
.
dump
(
existing_users
.
first
))
expect
(
subject
).
to
receive
(
:api_get_from
).
with
(
"/users?username=name"
).
and_return
(
users_response
)
expect
(
subject
).
to
receive
(
:api_get_from
).
with
(
"/users/0"
).
and_return
(
single_user_response
)
subject
.
username
=
'name'
subject
.
fabricate_via_api!
expect
(
subject
.
api_response
).
to
eq
(
existing_users
.
first
)
end
it
'tries to create a user if it does not exist'
do
expect
(
subject
).
to
receive
(
:api_get_from
).
with
(
"/users?username=foo"
).
and_return
(
Response
.
new
(
'200'
,
'[]'
))
expect
(
subject
).
to
receive
(
:api_post
).
and_return
({
web_url:
''
})
subject
.
username
=
'foo'
subject
.
fabricate_via_api!
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