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
def sign_in_as_admin
sign_in(as: Runtime::User.admin)
end
def sign_in_unless_signed_in(as: nil)
sign_in(as: as) unless Page::Main::Menu.perform(&:signed_in?)
end
end
end
end
......@@ -8,7 +8,10 @@ module QA
attr_accessor :path, :description
attribute :sandbox do
Sandbox.fabricate!
Sandbox.fabricate_via_api! do |sandbox|
sandbox.user = user
sandbox.api_client = api_client
end
end
attribute :id
......
......@@ -26,8 +26,6 @@ module QA
end
attribute :target do
project.visit!
Repository::ProjectPush.fabricate! do |resource|
resource.project = project
resource.branch_name = 'master'
......
......@@ -46,19 +46,24 @@ module QA
end
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) }
Runtime::Browser.visit(@address, Page::Main::Login)
Page::Main::Login.perform { |login| login.sign_in_using_credentials(user: @user) }
end
Page::Main::Menu.perform(&:sign_out) if @is_new_session && signed_in_initially
Flow::Login.sign_in_unless_signed_in(as: @user)
token = Resource::PersonalAccessToken.fabricate!.access_token
# 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
Page::Main::Menu.perform(&:sign_out) if @is_new_session
Page::Main::Menu.perform(&:sign_out) if @is_new_session || !signed_in_initially
token
end
......
......@@ -4,9 +4,6 @@ module QA
context 'Create' do
describe 'Download merge request patch and diff' 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.name = 'project'
end
......@@ -19,6 +16,8 @@ module QA
end
it 'views the merge request email patches' do
Flow::Login.sign_in
@merge_request.visit!
Page::MergeRequest::Show.perform(&:view_email_patches)
......@@ -28,6 +27,8 @@ module QA
end
it 'views the merge request plain diff' do
Flow::Login.sign_in
@merge_request.visit!
Page::MergeRequest::Show.perform(&:view_plain_diff)
......
......@@ -6,23 +6,12 @@ module QA
describe 'File templates' do
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
login
@project = Resource::Project.fabricate! do |project|
@project = Resource::Project.fabricate_via_api! do |project|
project.name = 'file-template-project'
project.description = 'Add file templates via the Files view'
project.initialize_with_readme = true
end
Page::Main::Menu.perform(&:sign_out)
end
templates = [
......@@ -56,7 +45,8 @@ module QA
it "user adds #{template[:file_name]} via file template #{template[:name]}" do
content = fetch_template_from_api(template[:api_path], template[:api_key])
login
Flow::Login.sign_in
@project.visit!
Page::Project::Show.perform(&:create_new_file!)
......
......@@ -4,14 +4,10 @@ module QA
context 'Create' do
describe 'Git clone over HTTP', :ldap_no_tls do
before(:all) do
Runtime::Browser.visit(:gitlab, Page::Main::Login)
Page::Main::Login.perform(&:sign_in_using_credentials)
@project = Resource::Project.fabricate! do |scenario|
@project = Resource::Project.fabricate_via_api! do |scenario|
scenario.name = 'project-with-code'
scenario.description = 'project for git clone tests'
end
@project.visit!
Git::Repository.perform do |repository|
repository.uri = @project.repository_http_location.uri
......
......@@ -31,8 +31,7 @@ module QA
end
def view_commit
Runtime::Browser.visit(:gitlab, Page::Main::Login)
Page::Main::Login.perform(&:sign_in_using_credentials)
Flow::Login.sign_in
@project.visit!
Page::Project::Show.perform do |show|
......
......@@ -6,21 +6,12 @@ module QA
describe 'Web IDE file templates' do
include Runtime::Fixtures
def login
Runtime::Browser.visit(:gitlab, Page::Main::Login)
Page::Main::Login.perform(&:sign_in_using_credentials)
end
before(:all) do
login
@project = Resource::Project.fabricate! do |project|
@project = Resource::Project.fabricate_via_api! do |project|
project.name = 'file-template-project'
project.description = 'Add file templates via the Web IDE'
project.initialize_with_readme = true
end
Page::Main::Menu.perform(&:sign_out)
end
templates = [
......@@ -54,7 +45,8 @@ module QA
it "user adds #{template[:file_name]} via file template #{template[:name]}" do
content = fetch_template_from_api(template[:api_path], template[:api_key])
login
Flow::Login.sign_in
@project.visit!
Page::Project::Show.perform(&:open_web_ide!)
......
......@@ -14,7 +14,6 @@ module QA
describe 'Group audit logs' do
before(:all) do
sign_in
@group = Resource::Group.fabricate_via_api! do |resource|
resource.path = "test-group-#{SecureRandom.hex(8)}"
end
......
......@@ -39,10 +39,17 @@ module QA
]
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.path = 'template-group'
group.user = admin
group.api_client = @api_client
end
@file_template_project = Resource::Project.fabricate_via_api! do |project|
......@@ -51,12 +58,16 @@ module QA
project.description = 'Add group file templates'
project.auto_devops_enabled = false
project.initialize_with_readme = true
project.user = admin
project.api_client = @api_client
end
Resource::Repository::Commit.fabricate_via_api! do |commit|
commit.project = @file_template_project
commit.commit_message = 'Add group file templates'
commit.add_files(templates)
commit.user = admin
commit.api_client = @api_client
end
@project = Resource::Project.fabricate_via_api! do |project|
......@@ -65,9 +76,9 @@ module QA
project.description = 'Add files for group file templates'
project.auto_devops_enabled = false
project.initialize_with_readme = true
project.user = admin
project.api_client = @api_client
end
Page::Main::Menu.perform(&:sign_out)
end
after(:all) do
......@@ -101,8 +112,7 @@ module QA
end
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]
return
......@@ -117,11 +127,10 @@ module QA
end
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]
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
......
......@@ -16,13 +16,10 @@ module QA
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
before do
Flow::Login.sign_in
group = Resource::Group.fabricate_via_api!
group.visit!
......@@ -34,6 +31,8 @@ module QA
context 'project insights page' do
before do
Flow::Login.sign_in
project = Resource::Project.fabricate_via_api! do |project|
project.name = 'project-insights'
project.description = 'Project Insights'
......
......@@ -13,8 +13,7 @@ module QA
describe 'Project audit logs' do
before(:all) do
sign_in
@project = Resource::Project.fabricate_via_browser_ui! do |project|
@project = Resource::Project.fabricate_via_api! do |project|
project.name = 'awesome-project'
project.initialize_with_readme = true
end
......@@ -28,7 +27,10 @@ module QA
context "Add project" 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
it_behaves_like 'project audit event logs', ["Add project"]
end
......
......@@ -33,8 +33,6 @@ module QA
push.files = @files
push.commit_message = 'Add test files'
end
Page::Main::Menu.perform(&:sign_out_if_signed_in)
end
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