diff options
Diffstat (limited to 'qa/qa/resource')
-rw-r--r-- | qa/qa/resource/base.rb | 21 | ||||
-rw-r--r-- | qa/qa/resource/bulk_import_group.rb | 85 | ||||
-rw-r--r-- | qa/qa/resource/group_base.rb | 2 | ||||
-rw-r--r-- | qa/qa/resource/issue.rb | 41 | ||||
-rw-r--r-- | qa/qa/resource/merge_request.rb | 13 | ||||
-rw-r--r-- | qa/qa/resource/project.rb | 68 | ||||
-rw-r--r-- | qa/qa/resource/project_imported_from_github.rb | 7 |
7 files changed, 182 insertions, 55 deletions
diff --git a/qa/qa/resource/base.rb b/qa/qa/resource/base.rb index ca0087cf709..2848e3ba7d2 100644 --- a/qa/qa/resource/base.rb +++ b/qa/qa/resource/base.rb @@ -75,19 +75,18 @@ module QA end def log_fabrication(method, resource, parents, args) - return yield unless Runtime::Env.debug? - start = Time.now - prefix = "==#{'=' * parents.size}>" - msg = [prefix] - msg << "Built a #{name}" - msg << "as a dependency of #{parents.last}" if parents.any? - msg << "via #{method}" yield.tap do - msg << "in #{Time.now - start} seconds" - puts msg.join(' ') - puts if parents.empty? + Runtime::Logger.debug do + msg = ["==#{'=' * parents.size}>"] + msg << "Built a #{name}" + msg << "as a dependency of #{parents.last}" if parents.any? + msg << "via #{method}" + msg << "in #{Time.now - start} seconds" + + msg.join(' ') + end end end @@ -189,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 diff --git a/qa/qa/resource/bulk_import_group.rb b/qa/qa/resource/bulk_import_group.rb new file mode 100644 index 00000000000..5380bb16f10 --- /dev/null +++ b/qa/qa/resource/bulk_import_group.rb @@ -0,0 +1,85 @@ +# 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! + resource_web_url(api_post) + 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 + + private + + def transform_api_resource(api_resource) + return api_resource if api_resource[:web_url] + + # override transformation only for /bulk_imports endpoint which doesn't have web_url in response and + # ignore others so import_id is not overwritten incorrectly + api_resource[:web_url] = "#{gitlab_address}/#{full_path}" + api_resource[:import_id] = api_resource[:id] + api_resource + end + end + end +end diff --git a/qa/qa/resource/group_base.rb b/qa/qa/resource/group_base.rb index 652c6cf7d1e..b937b704613 100644 --- a/qa/qa/resource/group_base.rb +++ b/qa/qa/resource/group_base.rb @@ -101,3 +101,5 @@ module QA end end end + +QA::Resource::GroupBase.prepend_mod_with('Resource::GroupBase', namespace: QA) diff --git a/qa/qa/resource/issue.rb b/qa/qa/resource/issue.rb index ffffa0eecda..c45ab7593b6 100644 --- a/qa/qa/resource/issue.rb +++ b/qa/qa/resource/issue.rb @@ -14,11 +14,11 @@ module QA end end - attribute :id - attribute :iid - attribute :assignee_ids - attribute :labels - attribute :title + attributes :id, + :iid, + :assignee_ids, + :labels, + :title def initialize @assignee_ids = [] @@ -41,13 +41,21 @@ module QA end def api_get_path - "/projects/#{project.id}/issues/#{id}" + "/projects/#{project.id}/issues/#{iid}" end def api_post_path "/projects/#{project.id}/issues" end + def api_put_path + "/projects/#{project.id}/issues/#{iid}" + end + + def api_comments_path + "#{api_get_path}/notes" + end + def api_post_body { assignee_ids: assignee_ids, @@ -59,20 +67,31 @@ module QA end end - def api_put_path - "/projects/#{project.id}/issues/#{iid}" - end - def set_issue_assignees(assignee_ids:) put_body = { assignee_ids: assignee_ids } response = put Runtime::API::Request.new(api_client, api_put_path).url, put_body unless response.code == HTTP_STATUS_OK - raise ResourceUpdateFailedError, "Could not update issue assignees to #{assignee_ids}. Request returned (#{response.code}): `#{response}`." + raise( + ResourceUpdateFailedError, + "Could not update issue assignees to #{assignee_ids}. Request returned (#{response.code}): `#{response}`." + ) end QA::Runtime::Logger.debug("Successfully updated issue assignees to #{assignee_ids}") end + + # Get issue comments + # + # @return [Array] + def comments(auto_paginate: false, attempts: 0) + return parse_body(api_get_from(api_comments_path)) unless auto_paginate + + auto_paginated_response( + Runtime::API::Request.new(api_client, api_comments_path, per_page: '100').url, + attempts: attempts + ) + end end end end diff --git a/qa/qa/resource/merge_request.rb b/qa/qa/resource/merge_request.rb index 8d9de0ea718..8c313f5d518 100644 --- a/qa/qa/resource/merge_request.rb +++ b/qa/qa/resource/merge_request.rb @@ -152,7 +152,8 @@ module QA @project = Resource::ImportProject.fabricate_via_browser_ui! # Setting the name here, since otherwise some tests will look for an existing file in # the proejct without ever knowing what is in it. - @file_name = "github_controller_spec.rb" + @file_name = "added_file-00000000.txt" + @source_branch = "large_merge_request" visit("#{project.web_url}/-/merge_requests/1") current_url end @@ -160,9 +161,13 @@ module QA # Get MR comments # # @return [Array] - def comments - response = get(Runtime::API::Request.new(api_client, api_comments_path).url) - parse_body(response) + def comments(auto_paginate: false, attempts: 0) + return parse_body(api_get_from(api_comments_path)) unless auto_paginate + + auto_paginated_response( + Runtime::API::Request.new(api_client, api_comments_path, per_page: '100').url, + attempts: attempts + ) end private diff --git a/qa/qa/resource/project.rb b/qa/qa/resource/project.rb index d111b070863..53b8a9b0246 100644 --- a/qa/qa/resource/project.rb +++ b/qa/qa/resource/project.rb @@ -13,13 +13,14 @@ module QA :initialize_with_readme, :auto_devops_enabled, :github_personal_access_token, - :github_repository_path + :github_repository_path, + :gitlab_repository_path attributes :id, :name, :add_name_uuid, :description, - :standalone, + :personal_namespace, :runners_token, :visibility, :template_name, @@ -32,7 +33,7 @@ module QA end attribute :path_with_namespace do - "#{sandbox_path}#{group.path}/#{name}" if group + "#{group.full_path}/#{name}" end alias_method :full_path, :path_with_namespace @@ -51,7 +52,7 @@ module QA def initialize @add_name_uuid = true - @standalone = false + @personal_namespace = false @description = 'My awesome project' @initialize_with_readme = false @auto_devops_enabled = false @@ -69,7 +70,9 @@ module QA def fabricate! return if @import - unless @standalone + if @personal_namespace + Page::Dashboard::Projects.perform(&:click_new_project_button) + else group.visit! Page::Group::Show.perform(&:go_to_new_project) end @@ -84,13 +87,15 @@ module QA Page::Project::New.perform(&:click_blank_project_link) Page::Project::New.perform do |new_page| - new_page.choose_test_namespace + new_page.choose_test_namespace unless @personal_namespace new_page.choose_name(@name) new_page.add_description(@description) new_page.set_visibility(@visibility) - new_page.enable_initialize_with_readme if @initialize_with_readme + new_page.disable_initialize_with_readme unless @initialize_with_readme new_page.create_new_project end + + @id = Page::Project::Show.perform(&:project_id) end def fabricate_via_api! @@ -218,7 +223,7 @@ module QA auto_devops_enabled: @auto_devops_enabled } - unless @standalone + unless @personal_namespace post_body[:namespace_id] = group.id post_body[:path] = name end @@ -263,19 +268,24 @@ module QA result = parse_body(response) - Runtime::Logger.error("Import failed: #{result[:import_error]}") if result[:import_status] == "failed" + if result[:import_status] == "failed" + Runtime::Logger.error("Import failed: #{result[:import_error]}") + Runtime::Logger.error("Failed relations: #{result[:failed_relations]}") + end result[:import_status] end - def commits - response = get(request_url(api_commits_path)) - parse_body(response) + def commits(auto_paginate: false, attempts: 0) + return parse_body(api_get_from(api_commits_path)) unless auto_paginate + + auto_paginated_response(request_url(api_commits_path, per_page: '100'), attempts: attempts) end - def merge_requests - response = get(request_url(api_merge_requests_path)) - parse_body(response) + def merge_requests(auto_paginate: false, attempts: 0) + return parse_body(api_get_from(api_merge_requests_path)) unless auto_paginate + + auto_paginated_response(request_url(api_merge_requests_path, per_page: '100'), attempts: attempts) end def merge_request_with_title(title) @@ -299,9 +309,10 @@ module QA parse_body(response) end - def repository_branches - response = get(request_url(api_repository_branches_path)) - parse_body(response) + def repository_branches(auto_paginate: false, attempts: 0) + return parse_body(api_get_from(api_repository_branches_path)) unless auto_paginate + + auto_paginated_response(request_url(api_repository_branches_path, per_page: '100'), attempts: attempts) end def repository_tags @@ -324,19 +335,22 @@ module QA parse_body(response) end - def issues - response = get(request_url(api_issues_path)) - parse_body(response) + def issues(auto_paginate: false, attempts: 0) + return parse_body(api_get_from(api_issues_path)) unless auto_paginate + + auto_paginated_response(request_url(api_issues_path, per_page: '100'), attempts: attempts) end - def labels - response = get(request_url(api_labels_path)) - parse_body(response) + def labels(auto_paginate: false, attempts: 0) + return parse_body(api_get_from(api_labels_path)) unless auto_paginate + + auto_paginated_response(request_url(api_labels_path, per_page: '100'), attempts: attempts) end - def milestones - response = get(request_url(api_milestones_path)) - parse_body(response) + def milestones(auto_paginate: false, attempts: 0) + return parse_body(api_get_from(api_milestones_path)) unless auto_paginate + + auto_paginated_response(request_url(api_milestones_path, per_page: '100'), attempts: attempts) end def wikis diff --git a/qa/qa/resource/project_imported_from_github.rb b/qa/qa/resource/project_imported_from_github.rb index 214e8f517bb..8aa19555d50 100644 --- a/qa/qa/resource/project_imported_from_github.rb +++ b/qa/qa/resource/project_imported_from_github.rb @@ -18,9 +18,12 @@ module QA Page::Project::Import::Github.perform do |import_page| import_page.add_personal_access_token(github_personal_access_token) - import_page.import!(github_repository_path, name) - import_page.go_to_project(name) + import_page.import!(github_repository_path, group.full_path, name) + import_page.wait_for_success(github_repository_path) end + + reload! + visit! end def go_to_import_page |