Commit 8af400b2 authored by Andrejs Cunskis's avatar Andrejs Cunskis Committed by Mark Lapierre

E2E: Bulk group import api test

parent 3c4d5efb
......@@ -73,6 +73,7 @@ module QA
autoload :GroupBase, 'qa/resource/group_base'
autoload :Sandbox, 'qa/resource/sandbox'
autoload :Group, 'qa/resource/group'
autoload :BulkImportGroup, 'qa/resource/bulk_import_group'
autoload :Issue, 'qa/resource/issue'
autoload :ProjectIssueNote, 'qa/resource/project_issue_note'
autoload :Project, 'qa/resource/project'
......
......@@ -188,7 +188,7 @@ module QA
end
def log_having_both_api_result_and_block(name, api_value)
QA::Runtime::Logger.info(<<~MSG.strip)
QA::Runtime::Logger.debug(<<~MSG.strip)
<#{self.class}> Attribute #{name.inspect} has both API response `#{api_value}` and a block. API response will be picked. Block will be ignored.
MSG
end
......
# frozen_string_literal: true
module QA
module Resource
class BulkImportGroup < Group
attributes :source_group_path,
:import_id
attribute :destination_group_path do
source_group_path
end
attribute :access_token do
api_client.personal_access_token
end
alias_method :path, :source_group_path
delegate :gitlab_address, to: 'QA::Runtime::Scenario'
def fabricate_via_browser_ui!
Page::Main::Menu.perform(&:go_to_create_group)
Page::Group::New.perform do |group|
group.switch_to_import_tab
group.connect_gitlab_instance(gitlab_address, api_client.personal_access_token)
end
Page::Group::BulkImport.perform do |import_page|
import_page.import_group(path, sandbox.path)
end
reload!
visit!
end
def fabricate_via_api!
response = post(Runtime::API::Request.new(api_client, api_post_path).url, api_post_body)
@import_id = parse_body(response)[:id]
"#{gitlab_address}/#{full_path}"
end
def api_post_path
'/bulk_imports'
end
def api_post_body
{
configuration: {
url: gitlab_address,
access_token: access_token
},
entities: [
{
source_type: 'group_entity',
source_full_path: source_group_path,
destination_name: destination_group_path,
destination_namespace: sandbox.path
}
]
}
end
def import_status
response = get(Runtime::API::Request.new(api_client, "/bulk_imports/#{import_id}").url)
unless response.code == HTTP_STATUS_OK
raise ResourceQueryError, "Could not get import status. Request returned (#{response.code}): `#{response}`."
end
parse_body(response)[:status]
end
end
end
end
# frozen_string_literal: true
module QA
RSpec.describe 'Manage', :requires_admin do
describe 'Bulk group import via api' do
let!(:staging?) { Runtime::Scenario.gitlab_address.include?('staging.gitlab.com') }
let(:admin_api_client) { Runtime::API::Client.as_admin }
let(:user) do
Resource::User.fabricate_via_api! do |usr|
usr.api_client = admin_api_client
usr.hard_delete_on_api_removal = true
end
end
let(:api_client) { Runtime::API::Client.new(user: user) }
let(:personal_access_token) { api_client.personal_access_token }
let(:sandbox) do
Resource::Sandbox.fabricate_via_api! do |group|
group.api_client = admin_api_client
end
end
let(:source_group) do
Resource::Sandbox.fabricate_via_api! do |group|
group.api_client = api_client
group.path = "source-group-for-import-#{SecureRandom.hex(4)}"
end
end
let(:subgroup) do
Resource::Group.fabricate_via_api! do |group|
group.api_client = api_client
group.sandbox = source_group
group.path = "subgroup-for-import-#{SecureRandom.hex(4)}"
end
end
let(:imported_subgroup) do
Resource::Group.init do |group|
group.api_client = api_client
group.sandbox = imported_group
group.path = subgroup.path
end
end
let(:imported_group) do
Resource::BulkImportGroup.fabricate_via_api! do |group|
group.api_client = api_client
group.sandbox = sandbox
group.source_group_path = source_group.path
end
end
before do
Runtime::Feature.enable(:bulk_import) unless staging?
Runtime::Feature.enable(:top_level_group_creation_enabled) if staging?
sandbox.add_member(user, Resource::Members::AccessLevel::MAINTAINER)
Resource::GroupLabel.fabricate_via_api! do |label|
label.api_client = api_client
label.group = source_group
label.title = "source-group-#{SecureRandom.hex(4)}"
end
Resource::GroupLabel.fabricate_via_api! do |label|
label.api_client = api_client
label.group = subgroup
label.title = "subgroup-#{SecureRandom.hex(4)}"
end
end
# Non blocking issues:
# https://gitlab.com/gitlab-org/gitlab/-/issues/331252
# https://gitlab.com/gitlab-org/gitlab/-/issues/333678 <- can cause 500 when creating user and group back to back
it(
'imports group with subgroups and labels',
testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/1871'
) do
Page::Group::BulkImport.perform do |import_page|
imported_group
expect { imported_group.import_status }.to eventually_eq('finished').within(duration: 300, interval: 2)
aggregate_failures do
expect(imported_group.reload!).to eq(source_group)
expect(imported_group.labels).to include(*source_group.labels)
expect(imported_subgroup.reload!).to eq(subgroup)
expect(imported_subgroup.labels).to include(*subgroup.labels)
end
end
end
after do
user.remove_via_api!
ensure
Runtime::Feature.disable(:bulk_import) unless staging?
Runtime::Feature.disable(:top_level_group_creation_enabled) if staging?
end
end
end
end
......@@ -29,27 +29,11 @@ module QA
end
end
let(:subgroup) do
Resource::Group.fabricate_via_api! do |group|
group.api_client = api_client
group.sandbox = source_group
group.path = "subgroup-for-import-#{SecureRandom.hex(4)}"
end
end
let(:imported_group) do
Resource::Group.init do |group|
Resource::BulkImportGroup.init do |group|
group.api_client = api_client
group.sandbox = sandbox
group.path = source_group.path
end
end
let(:imported_subgroup) do
Resource::Group.init do |group|
group.api_client = api_client
group.sandbox = imported_group
group.path = subgroup.path
group.source_group_path = source_group.path
end
end
......@@ -61,7 +45,6 @@ module QA
# create groups explicitly before connecting gitlab instance
source_group
subgroup
Flow::Login.sign_in(as: user)
Page::Main::Menu.perform(&:go_to_create_group)
......@@ -78,29 +61,14 @@ module QA
'imports group with subgroups and labels',
testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/1785'
) do
Resource::GroupLabel.fabricate_via_api! do |label|
label.api_client = api_client
label.group = source_group
label.title = "source-group-#{SecureRandom.hex(4)}"
end
Resource::GroupLabel.fabricate_via_api! do |label|
label.api_client = api_client
label.group = subgroup
label.title = "subgroup-#{SecureRandom.hex(4)}"
end
Page::Group::BulkImport.perform do |import_page|
import_page.import_group(source_group.path, sandbox.path)
expect(import_page).to have_imported_group(source_group.path, wait: 300)
import_page.import_group(imported_group.path, imported_group.sandbox.path)
aggregate_failures do
expect { imported_group.reload! }.to eventually_eq(source_group).within(duration: 10)
expect { imported_group.labels }.to eventually_include(*source_group.labels).within(duration: 10)
expect(import_page).to have_imported_group(imported_group.path, wait: 300)
# Do not validate subgroups until https://gitlab.com/gitlab-org/gitlab/-/issues/332818 is resolved
# expect { imported_subgroup.reload! }.to eventually_eq(subgroup).within(duration: 30)
# expect { imported_subgroup.labels }.to eventually_include(*subgroup.labels).within(duration: 30)
imported_group.reload!.visit!
Page::Group::Show.perform do |group|
expect(group).to have_content(imported_group.path)
end
end
end
......
......@@ -170,16 +170,16 @@ RSpec.describe QA::Resource::Base do
let(:api_resource) { { test: 'api_with_block' } }
before do
allow(QA::Runtime::Logger).to receive(:info)
allow(QA::Runtime::Logger).to receive(:debug)
end
it 'returns value from api and emits an INFO log entry' do
it 'returns value from api and emits an debug log entry' do
result = subject.fabricate!(resource: resource)
expect(result).to be_a(described_class)
expect(result.test).to eq('api_with_block')
expect(QA::Runtime::Logger)
.to have_received(:info).with(/api_with_block/)
.to have_received(:debug).with(/api_with_block/)
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment