Backport for EE 15582
This is a back-port for all CE related files.
This commit is contained in:
parent
564d78dac1
commit
1ada89d5f1
11 changed files with 95 additions and 2 deletions
1
qa/qa.rb
1
qa/qa.rb
|
@ -66,6 +66,7 @@ module QA
|
||||||
autoload :Fork, 'qa/resource/fork'
|
autoload :Fork, 'qa/resource/fork'
|
||||||
autoload :SSHKey, 'qa/resource/ssh_key'
|
autoload :SSHKey, 'qa/resource/ssh_key'
|
||||||
autoload :Snippet, 'qa/resource/snippet'
|
autoload :Snippet, 'qa/resource/snippet'
|
||||||
|
autoload :ProjectMember, 'qa/resource/project_member'
|
||||||
|
|
||||||
module Events
|
module Events
|
||||||
autoload :Base, 'qa/resource/events/base'
|
autoload :Base, 'qa/resource/events/base'
|
||||||
|
|
|
@ -85,6 +85,8 @@ module QA
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_file(name, contents)
|
def add_file(name, contents)
|
||||||
|
FileUtils.mkdir_p(::File.dirname(name))
|
||||||
|
|
||||||
::File.write(name, contents)
|
::File.write(name, contents)
|
||||||
|
|
||||||
if use_lfs?
|
if use_lfs?
|
||||||
|
|
|
@ -148,6 +148,12 @@ module QA
|
||||||
click_element :saml_login_button
|
click_element :saml_login_button
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sign_out_and_sign_in_as(user:)
|
||||||
|
Menu.perform(&:sign_out)
|
||||||
|
has_sign_in_tab?
|
||||||
|
sign_in_using_credentials(user)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def sign_in_using_gitlab_credentials(user)
|
def sign_in_using_gitlab_credentials(user)
|
||||||
|
|
|
@ -119,7 +119,7 @@ module QA
|
||||||
has_element?(:description, text: description)
|
has_element?(:description, text: description)
|
||||||
end
|
end
|
||||||
|
|
||||||
def merge!
|
def try_to_merge!
|
||||||
# The merge button is disabled on load
|
# The merge button is disabled on load
|
||||||
wait do
|
wait do
|
||||||
has_element?(:merge_button)
|
has_element?(:merge_button)
|
||||||
|
@ -131,6 +131,10 @@ module QA
|
||||||
end
|
end
|
||||||
|
|
||||||
merge_immediately
|
merge_immediately
|
||||||
|
end
|
||||||
|
|
||||||
|
def merge!
|
||||||
|
try_to_merge!
|
||||||
|
|
||||||
success = wait do
|
success = wait do
|
||||||
has_text?('The changes were merged into')
|
has_text?('The changes were merged into')
|
||||||
|
|
|
@ -44,3 +44,5 @@ module QA
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
QA::Page::Project::SubMenus::Repository.prepend_if_ee('QA::EE::Page::Project::SubMenus::Repository')
|
||||||
|
|
|
@ -11,6 +11,7 @@ module QA
|
||||||
ResourceNotFoundError = Class.new(RuntimeError)
|
ResourceNotFoundError = Class.new(RuntimeError)
|
||||||
ResourceFabricationFailedError = Class.new(RuntimeError)
|
ResourceFabricationFailedError = Class.new(RuntimeError)
|
||||||
ResourceURLMissingError = Class.new(RuntimeError)
|
ResourceURLMissingError = Class.new(RuntimeError)
|
||||||
|
ResourceNotDeletedError = Class.new(RuntimeError)
|
||||||
|
|
||||||
attr_reader :api_resource, :api_response
|
attr_reader :api_resource, :api_response
|
||||||
attr_writer :api_client
|
attr_writer :api_client
|
||||||
|
@ -30,6 +31,10 @@ module QA
|
||||||
resource_web_url(api_post)
|
resource_web_url(api_post)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def remove_via_api!
|
||||||
|
api_delete
|
||||||
|
end
|
||||||
|
|
||||||
def eager_load_api_client!
|
def eager_load_api_client!
|
||||||
return unless api_client.nil?
|
return unless api_client.nil?
|
||||||
|
|
||||||
|
@ -79,6 +84,17 @@ module QA
|
||||||
process_api_response(parse_body(response))
|
process_api_response(parse_body(response))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def api_delete
|
||||||
|
url = Runtime::API::Request.new(api_client, api_delete_path).url
|
||||||
|
response = delete(url)
|
||||||
|
|
||||||
|
unless response.code == HTTP_STATUS_NO_CONTENT
|
||||||
|
raise ResourceNotDeletedError, "Resource at #{url} could not be deleted (#{response.code}): `#{response}`."
|
||||||
|
end
|
||||||
|
|
||||||
|
response
|
||||||
|
end
|
||||||
|
|
||||||
def api_client
|
def api_client
|
||||||
@api_client ||= begin
|
@api_client ||= begin
|
||||||
Runtime::API::Client.new(:gitlab, is_new_session: !current_url.start_with?('http'), user: user)
|
Runtime::API::Client.new(:gitlab, is_new_session: !current_url.start_with?('http'), user: user)
|
||||||
|
|
|
@ -47,6 +47,18 @@ module QA
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.remove_via_api!(*args, &prepare_block)
|
||||||
|
options = args.extract_options!
|
||||||
|
resource = options.fetch(:resource) { new }
|
||||||
|
parents = options.fetch(:parents) { [] }
|
||||||
|
|
||||||
|
resource.eager_load_api_client!
|
||||||
|
|
||||||
|
do_fabricate!(resource: resource, prepare_block: prepare_block, parents: parents) do
|
||||||
|
log_fabrication(:api, resource, parents, args) { resource.remove_via_api! }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def fabricate!(*_args)
|
def fabricate!(*_args)
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
end
|
end
|
||||||
|
|
|
@ -72,6 +72,18 @@ module QA
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.unprotect_via_api!(&block)
|
||||||
|
self.remove_via_api!(&block)
|
||||||
|
end
|
||||||
|
|
||||||
|
def api_get_path
|
||||||
|
"/projects/#{@project.api_resource[:id]}/protected_branches/#{@branch_name}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def api_delete_path
|
||||||
|
"/projects/#{@project.api_resource[:id]}/protected_branches/#{@branch_name}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,6 +17,7 @@ module QA
|
||||||
:labels,
|
:labels,
|
||||||
:file_name,
|
:file_name,
|
||||||
:file_content
|
:file_content
|
||||||
|
attr_writer :no_preparation
|
||||||
|
|
||||||
attribute :project do
|
attribute :project do
|
||||||
Project.fabricate! do |resource|
|
Project.fabricate! do |resource|
|
||||||
|
@ -58,6 +59,7 @@ module QA
|
||||||
@file_name = "added_file.txt"
|
@file_name = "added_file.txt"
|
||||||
@file_content = "File Added"
|
@file_content = "File Added"
|
||||||
@target_new_branch = true
|
@target_new_branch = true
|
||||||
|
@no_preparation = false
|
||||||
end
|
end
|
||||||
|
|
||||||
def fabricate!
|
def fabricate!
|
||||||
|
@ -80,7 +82,7 @@ module QA
|
||||||
end
|
end
|
||||||
|
|
||||||
def fabricate_via_api!
|
def fabricate_via_api!
|
||||||
populate(:target, :source)
|
populate(:target, :source) unless @no_preparation
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
35
qa/qa/resource/project_member.rb
Normal file
35
qa/qa/resource/project_member.rb
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module QA
|
||||||
|
module Resource
|
||||||
|
class ProjectMember < Base
|
||||||
|
attr_accessor :user, :project, :access_level
|
||||||
|
attr_reader :level
|
||||||
|
|
||||||
|
def initialize
|
||||||
|
@level = {
|
||||||
|
guest: 10,
|
||||||
|
reporter: 20,
|
||||||
|
developer: 30,
|
||||||
|
maintainer: 40,
|
||||||
|
owner: 50
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def api_get_path
|
||||||
|
"/projects/#{project.api_resource[:id]}/members/#{user.api_resource[:id]}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def api_post_path
|
||||||
|
"/projects/#{project.api_resource[:id]}/members"
|
||||||
|
end
|
||||||
|
|
||||||
|
def api_post_body
|
||||||
|
{
|
||||||
|
user_id: user.api_resource[:id],
|
||||||
|
access_level: access_level
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -5,6 +5,7 @@ module QA
|
||||||
module Api
|
module Api
|
||||||
HTTP_STATUS_OK = 200
|
HTTP_STATUS_OK = 200
|
||||||
HTTP_STATUS_CREATED = 201
|
HTTP_STATUS_CREATED = 201
|
||||||
|
HTTP_STATUS_NO_CONTENT = 204
|
||||||
|
|
||||||
def post(url, payload)
|
def post(url, payload)
|
||||||
RestClient::Request.execute(
|
RestClient::Request.execute(
|
||||||
|
|
Loading…
Reference in a new issue