Commit 0d6b42a5 authored by Mark Lapierre's avatar Mark Lapierre

Update tests to not log in in before(:all) blocks

Also changes the API client to log out after creating an access token
if it wasn't already logged in. This is so that it doesn't leave the
browser logged in at the start of tests when they expect to be able to
log in. For example, if a test is the first in the suite it will log
in to create an access token. If that happens in a before(:context)
block, the test will already be logged in, so an attempt to log in
would fail.
parent 6b043e7d
...@@ -29,6 +29,10 @@ module QA ...@@ -29,6 +29,10 @@ module QA
def sign_in_as_admin def sign_in_as_admin
sign_in(as: Runtime::User.admin) sign_in(as: Runtime::User.admin)
end end
def sign_in_unless_signed_in(as: nil)
sign_in(as: as) unless Page::Main::Menu.perform(&:signed_in?)
end
end end
end end
end end
...@@ -8,7 +8,10 @@ module QA ...@@ -8,7 +8,10 @@ module QA
attr_accessor :path, :description attr_accessor :path, :description
attribute :sandbox do attribute :sandbox do
Sandbox.fabricate! Sandbox.fabricate_via_api! do |sandbox|
sandbox.user = user
sandbox.api_client = api_client
end
end end
attribute :id attribute :id
......
...@@ -26,8 +26,6 @@ module QA ...@@ -26,8 +26,6 @@ module QA
end end
attribute :target do attribute :target do
project.visit!
Repository::ProjectPush.fabricate! do |resource| Repository::ProjectPush.fabricate! do |resource|
resource.project = project resource.project = project
resource.branch_name = 'master' resource.branch_name = 'master'
......
...@@ -46,19 +46,24 @@ module QA ...@@ -46,19 +46,24 @@ module QA
end end
def create_personal_access_token def create_personal_access_token
Page::Main::Menu.perform(&:sign_out) if @is_new_session && Page::Main::Menu.perform { |p| p.has_personal_area?(wait: 0) } signed_in_initially = Page::Main::Menu.perform(&:signed_in?)
unless Page::Main::Menu.perform { |p| p.has_personal_area?(wait: 0) } Page::Main::Menu.perform(&:sign_out) if @is_new_session && signed_in_initially
Runtime::Browser.visit(@address, Page::Main::Login)
Page::Main::Login.perform { |login| login.sign_in_using_credentials(user: @user) } Flow::Login.sign_in_unless_signed_in(as: @user)
end
token = Resource::PersonalAccessToken.fabricate!.access_token token = Resource::PersonalAccessToken.fabricate!.access_token
# If this is a new session, that tests that follow could fail if they # If this is a new session, that tests that follow could fail if they
# try to sign in without starting a new session # try to sign in without starting a new session.
# Also, if the browser wasn't already signed in, leaving it
# signed in could cause tests to fail when they try to sign
# in again. For example, that would happen if a test has a
# before(:context) block that fabricates via the API, and
# it's the first test to run so it creates an access token
#
# Sign out so the tests can successfully sign in # Sign out so the tests can successfully sign in
Page::Main::Menu.perform(&:sign_out) if @is_new_session Page::Main::Menu.perform(&:sign_out) if @is_new_session || !signed_in_initially
token token
end end
......
...@@ -4,9 +4,6 @@ module QA ...@@ -4,9 +4,6 @@ module QA
context 'Create' do context 'Create' do
describe 'Download merge request patch and diff' do describe 'Download merge request patch and diff' do
before(:context) do before(:context) do
Runtime::Browser.visit(:gitlab, Page::Main::Login)
Page::Main::Login.perform(&:sign_in_using_credentials)
project = Resource::Project.fabricate_via_api! do |project| project = Resource::Project.fabricate_via_api! do |project|
project.name = 'project' project.name = 'project'
end end
...@@ -19,6 +16,8 @@ module QA ...@@ -19,6 +16,8 @@ module QA
end end
it 'views the merge request email patches' do it 'views the merge request email patches' do
Flow::Login.sign_in
@merge_request.visit! @merge_request.visit!
Page::MergeRequest::Show.perform(&:view_email_patches) Page::MergeRequest::Show.perform(&:view_email_patches)
...@@ -28,6 +27,8 @@ module QA ...@@ -28,6 +27,8 @@ module QA
end end
it 'views the merge request plain diff' do it 'views the merge request plain diff' do
Flow::Login.sign_in
@merge_request.visit! @merge_request.visit!
Page::MergeRequest::Show.perform(&:view_plain_diff) Page::MergeRequest::Show.perform(&:view_plain_diff)
......
...@@ -6,23 +6,12 @@ module QA ...@@ -6,23 +6,12 @@ module QA
describe 'File templates' do describe 'File templates' do
include Runtime::Fixtures include Runtime::Fixtures
def login
unless Page::Main::Menu.perform(&:signed_in?)
Runtime::Browser.visit(:gitlab, Page::Main::Login)
Page::Main::Login.perform(&:sign_in_using_credentials)
end
end
before(:all) do before(:all) do
login @project = Resource::Project.fabricate_via_api! do |project|
@project = Resource::Project.fabricate! do |project|
project.name = 'file-template-project' project.name = 'file-template-project'
project.description = 'Add file templates via the Files view' project.description = 'Add file templates via the Files view'
project.initialize_with_readme = true project.initialize_with_readme = true
end end
Page::Main::Menu.perform(&:sign_out)
end end
templates = [ templates = [
...@@ -56,7 +45,8 @@ module QA ...@@ -56,7 +45,8 @@ module QA
it "user adds #{template[:file_name]} via file template #{template[:name]}" do it "user adds #{template[:file_name]} via file template #{template[:name]}" do
content = fetch_template_from_api(template[:api_path], template[:api_key]) content = fetch_template_from_api(template[:api_path], template[:api_key])
login Flow::Login.sign_in
@project.visit! @project.visit!
Page::Project::Show.perform(&:create_new_file!) Page::Project::Show.perform(&:create_new_file!)
......
...@@ -4,14 +4,10 @@ module QA ...@@ -4,14 +4,10 @@ module QA
context 'Create' do context 'Create' do
describe 'Git clone over HTTP', :ldap_no_tls do describe 'Git clone over HTTP', :ldap_no_tls do
before(:all) do before(:all) do
Runtime::Browser.visit(:gitlab, Page::Main::Login) @project = Resource::Project.fabricate_via_api! do |scenario|
Page::Main::Login.perform(&:sign_in_using_credentials)
@project = Resource::Project.fabricate! do |scenario|
scenario.name = 'project-with-code' scenario.name = 'project-with-code'
scenario.description = 'project for git clone tests' scenario.description = 'project for git clone tests'
end end
@project.visit!
Git::Repository.perform do |repository| Git::Repository.perform do |repository|
repository.uri = @project.repository_http_location.uri repository.uri = @project.repository_http_location.uri
......
...@@ -31,8 +31,7 @@ module QA ...@@ -31,8 +31,7 @@ module QA
end end
def view_commit def view_commit
Runtime::Browser.visit(:gitlab, Page::Main::Login) Flow::Login.sign_in
Page::Main::Login.perform(&:sign_in_using_credentials)
@project.visit! @project.visit!
Page::Project::Show.perform do |show| Page::Project::Show.perform do |show|
......
...@@ -6,21 +6,12 @@ module QA ...@@ -6,21 +6,12 @@ module QA
describe 'Web IDE file templates' do describe 'Web IDE file templates' do
include Runtime::Fixtures include Runtime::Fixtures
def login
Runtime::Browser.visit(:gitlab, Page::Main::Login)
Page::Main::Login.perform(&:sign_in_using_credentials)
end
before(:all) do before(:all) do
login @project = Resource::Project.fabricate_via_api! do |project|
@project = Resource::Project.fabricate! do |project|
project.name = 'file-template-project' project.name = 'file-template-project'
project.description = 'Add file templates via the Web IDE' project.description = 'Add file templates via the Web IDE'
project.initialize_with_readme = true project.initialize_with_readme = true
end end
Page::Main::Menu.perform(&:sign_out)
end end
templates = [ templates = [
...@@ -54,7 +45,8 @@ module QA ...@@ -54,7 +45,8 @@ module QA
it "user adds #{template[:file_name]} via file template #{template[:name]}" do it "user adds #{template[:file_name]} via file template #{template[:name]}" do
content = fetch_template_from_api(template[:api_path], template[:api_key]) content = fetch_template_from_api(template[:api_path], template[:api_key])
login Flow::Login.sign_in
@project.visit! @project.visit!
Page::Project::Show.perform(&:open_web_ide!) Page::Project::Show.perform(&:open_web_ide!)
......
...@@ -14,7 +14,6 @@ module QA ...@@ -14,7 +14,6 @@ module QA
describe 'Group audit logs' do describe 'Group audit logs' do
before(:all) do before(:all) do
sign_in
@group = Resource::Group.fabricate_via_api! do |resource| @group = Resource::Group.fabricate_via_api! do |resource|
resource.path = "test-group-#{SecureRandom.hex(8)}" resource.path = "test-group-#{SecureRandom.hex(8)}"
end end
......
...@@ -39,10 +39,17 @@ module QA ...@@ -39,10 +39,17 @@ module QA
] ]
before(:all) do before(:all) do
Flow::Login.sign_in_as_admin admin = QA::Resource::User.new.tap do |user|
user.username = QA::Runtime::User.admin_username
user.password = QA::Runtime::User.admin_password
end
@api_client = Runtime::API::Client.new(:gitlab, user: admin)
@api_client.personal_access_token
@group = Resource::Group.fabricate_via_api! do |group| @group = Resource::Group.fabricate_via_api! do |group|
group.path = 'template-group' group.path = 'template-group'
group.user = admin
group.api_client = @api_client
end end
@file_template_project = Resource::Project.fabricate_via_api! do |project| @file_template_project = Resource::Project.fabricate_via_api! do |project|
...@@ -51,12 +58,16 @@ module QA ...@@ -51,12 +58,16 @@ module QA
project.description = 'Add group file templates' project.description = 'Add group file templates'
project.auto_devops_enabled = false project.auto_devops_enabled = false
project.initialize_with_readme = true project.initialize_with_readme = true
project.user = admin
project.api_client = @api_client
end end
Resource::Repository::Commit.fabricate_via_api! do |commit| Resource::Repository::Commit.fabricate_via_api! do |commit|
commit.project = @file_template_project commit.project = @file_template_project
commit.commit_message = 'Add group file templates' commit.commit_message = 'Add group file templates'
commit.add_files(templates) commit.add_files(templates)
commit.user = admin
commit.api_client = @api_client
end end
@project = Resource::Project.fabricate_via_api! do |project| @project = Resource::Project.fabricate_via_api! do |project|
...@@ -65,9 +76,9 @@ module QA ...@@ -65,9 +76,9 @@ module QA
project.description = 'Add files for group file templates' project.description = 'Add files for group file templates'
project.auto_devops_enabled = false project.auto_devops_enabled = false
project.initialize_with_readme = true project.initialize_with_readme = true
project.user = admin
project.api_client = @api_client
end end
Page::Main::Menu.perform(&:sign_out)
end end
after(:all) do after(:all) do
...@@ -101,8 +112,7 @@ module QA ...@@ -101,8 +112,7 @@ module QA
end end
def set_file_template_if_not_already_set def set_file_template_if_not_already_set
api_client = Runtime::API::Client.new(:gitlab) response = get Runtime::API::Request.new(@api_client, "/groups/#{@group.id}").url
response = get Runtime::API::Request.new(api_client, "/groups/#{@group.id}").url
if parse_body(response)[:file_template_project_id] if parse_body(response)[:file_template_project_id]
return return
...@@ -117,11 +127,10 @@ module QA ...@@ -117,11 +127,10 @@ module QA
end end
def remove_group_file_template_if_set def remove_group_file_template_if_set
api_client = Runtime::API::Client.new(:gitlab) response = get Runtime::API::Request.new(@api_client, "/groups/#{@group.id}").url
response = get Runtime::API::Request.new(api_client, "/groups/#{@group.id}").url
if parse_body(response)[:file_template_project_id] if parse_body(response)[:file_template_project_id]
put Runtime::API::Request.new(api_client, "/groups/#{@group.id}").url, { file_template_project_id: nil } put Runtime::API::Request.new(@api_client, "/groups/#{@group.id}").url, { file_template_project_id: nil }
end end
end end
end end
......
...@@ -16,13 +16,10 @@ module QA ...@@ -16,13 +16,10 @@ module QA
end end
end end
before(:all) do
Runtime::Browser.visit(:gitlab, Page::Main::Login)
Page::Main::Login.perform(&:sign_in_using_credentials)
end
context 'group insights page' do context 'group insights page' do
before do before do
Flow::Login.sign_in
group = Resource::Group.fabricate_via_api! group = Resource::Group.fabricate_via_api!
group.visit! group.visit!
...@@ -34,6 +31,8 @@ module QA ...@@ -34,6 +31,8 @@ module QA
context 'project insights page' do context 'project insights page' do
before do before do
Flow::Login.sign_in
project = Resource::Project.fabricate_via_api! do |project| project = Resource::Project.fabricate_via_api! do |project|
project.name = 'project-insights' project.name = 'project-insights'
project.description = 'Project Insights' project.description = 'Project Insights'
......
...@@ -13,8 +13,7 @@ module QA ...@@ -13,8 +13,7 @@ module QA
describe 'Project audit logs' do describe 'Project audit logs' do
before(:all) do before(:all) do
sign_in @project = Resource::Project.fabricate_via_api! do |project|
@project = Resource::Project.fabricate_via_browser_ui! do |project|
project.name = 'awesome-project' project.name = 'awesome-project'
project.initialize_with_readme = true project.initialize_with_readme = true
end end
...@@ -28,7 +27,10 @@ module QA ...@@ -28,7 +27,10 @@ module QA
context "Add project" do context "Add project" do
before do before do
@project.visit! Resource::Project.fabricate_via_browser_ui! do |project|
project.name = 'audit-add-project-via-ui'
project.initialize_with_readme = true
end.visit!
end end
it_behaves_like 'project audit event logs', ["Add project"] it_behaves_like 'project audit event logs', ["Add project"]
end end
......
...@@ -33,8 +33,6 @@ module QA ...@@ -33,8 +33,6 @@ module QA
push.files = @files push.files = @files
push.commit_message = 'Add test files' push.commit_message = 'Add test files'
end end
Page::Main::Menu.perform(&:sign_out_if_signed_in)
end end
context 'built-in', :requires_admin do context 'built-in', :requires_admin do
......
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