Skip to content

Commit

Permalink
Change 'script_id' to 'launcher_id'
Browse files Browse the repository at this point in the history
  • Loading branch information
euler-room committed Oct 31, 2024
1 parent c6dc975 commit 520d681
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 56 deletions.
8 changes: 4 additions & 4 deletions apps/dashboard/app/models/launcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,12 @@ def create_default_script

private

def self.script_path(root_dir, script_id)
unless script_id.to_s.match?(ID_REX)
raise(StandardError, "#{script_id} is invalid. Does not match #{ID_REX.inspect}")
def self.script_path(root_dir, launcher_id)
unless launcher_id.to_s.match?(ID_REX)
raise(StandardError, "#{launcher_id} is invalid. Does not match #{ID_REX.inspect}")
end

Pathname.new(File.join(Launcher.launchers_dir(root_dir), script_id.to_s))
Pathname.new(File.join(Launcher.launchers_dir(root_dir), launcher_id.to_s))
end

def default_script_path
Expand Down
104 changes: 52 additions & 52 deletions apps/dashboard/test/system/project_manager_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ def setup_script(project_id)
script_element[:id].gsub('launcher_', '')
end

def add_account(project_id, script_id, save: true)
def add_account(project_id, launcher_id, save: true)
visit project_path(project_id)
edit_launcher_path = edit_project_launcher_path(project_id, script_id)
edit_launcher_path = edit_project_launcher_path(project_id, launcher_id)
find("[href='#{edit_launcher_path}']").click

# now add 'auto_accounts'
Expand All @@ -63,9 +63,9 @@ def add_account(project_id, script_id, save: true)
click_on(I18n.t('dashboard.save')) if save
end

def add_bc_num_hours(project_id, script_id)
def add_bc_num_hours(project_id, launcher_id)
visit project_path(project_id)
edit_launcher_path = edit_project_launcher_path(project_id, script_id)
edit_launcher_path = edit_project_launcher_path(project_id, launcher_id)
find("[href='#{edit_launcher_path}']").click

# now add 'bc_num_hours'
Expand All @@ -76,7 +76,7 @@ def add_bc_num_hours(project_id, script_id)
click_on(I18n.t('dashboard.save'))
end

def add_auto_environment_variable(project_id, script_id, save: true)
def add_auto_environment_variable(project_id, launcher_id, save: true)
# now add 'auto_environment_variable'
click_on('Add new option')
select('Environment Variable', from: 'add_new_field_select')
Expand Down Expand Up @@ -224,7 +224,7 @@ def add_auto_environment_variable(project_id, script_id, save: true)
test 'creating and showing scripts' do
Dir.mktmpdir do |dir|
project_id = setup_project(dir)
script_id = setup_script(project_id)
launcher_id = setup_script(project_id)

expected_yml = <<~HEREDOC
---
Expand Down Expand Up @@ -259,9 +259,9 @@ def add_auto_environment_variable(project_id, script_id, save: true)

success_message = I18n.t('dashboard.jobs_scripts_created')
assert_selector('.alert-success', text: "Close\n#{success_message}")
assert_equal(expected_yml, File.read("#{dir}/projects/#{project_id}/.ondemand/scripts/#{script_id}/form.yml"))
assert_equal(expected_yml, File.read("#{dir}/projects/#{project_id}/.ondemand/scripts/#{launcher_id}/form.yml"))

launcher_path = project_launcher_path(project_id, script_id)
launcher_path = project_launcher_path(project_id, launcher_id)
find("[href='#{launcher_path}'].btn-success").click
assert_selector('h1', text: 'the script title', count: 1)
end
Expand All @@ -271,7 +271,7 @@ def add_auto_environment_variable(project_id, script_id, save: true)
Dir.mktmpdir do |dir|
Configuration.stubs(:launcher_default_items).returns(['bc_num_hours'])
project_id = setup_project(dir)
script_id = setup_script(project_id)
launcher_id = setup_script(project_id)

# note that bc_num_hours is in this YAML.
expected_yml = <<~HEREDOC
Expand Down Expand Up @@ -314,18 +314,18 @@ def add_auto_environment_variable(project_id, script_id, save: true)

success_message = I18n.t('dashboard.jobs_scripts_created')
assert_selector('.alert-success', text: "Close\n#{success_message}")
assert_equal(expected_yml, File.read("#{dir}/projects/#{project_id}/.ondemand/scripts/#{script_id}/form.yml"))
assert_equal(expected_yml, File.read("#{dir}/projects/#{project_id}/.ondemand/scripts/#{launcher_id}/form.yml"))
end
end

test 'showing scripts with auto attributes' do
Dir.mktmpdir do |dir|
project_id = setup_project(dir)
script_id = setup_script(project_id)
launcher_id = setup_script(project_id)
project_dir = File.join(dir, 'projects', project_id)
add_account(project_id, script_id)
add_account(project_id, launcher_id)

launcher_path = project_launcher_path(project_id, script_id)
launcher_path = project_launcher_path(project_id, launcher_id)
find("[href='#{launcher_path}'].btn-success").click
assert_selector('h1', text: 'the script title', count: 1)

Expand All @@ -344,10 +344,10 @@ def add_auto_environment_variable(project_id, script_id, save: true)
test 'deleting a script that succeeds' do
Dir.mktmpdir do |dir|
project_id = setup_project(dir)
script_id = setup_script(project_id)
launcher_id = setup_script(project_id)
project_dir = File.join(dir, 'projects', project_id)
ondemand_dir = File.join(project_dir, '.ondemand')
script_dir = File.join(ondemand_dir, 'scripts', script_id)
script_dir = File.join(ondemand_dir, 'scripts', launcher_id)

# ASSERT SCRIPT DIRECTORY IS CREATED
assert_equal true, File.directory?(script_dir)
Expand All @@ -359,7 +359,7 @@ def add_auto_environment_variable(project_id, script_id, save: true)
end

accept_confirm do
find("#delete_#{script_id}").click
find("#delete_#{launcher_id}").click
end

assert_selector '.alert-success', text: 'Script successfully deleted!'
Expand All @@ -371,12 +371,12 @@ def add_auto_environment_variable(project_id, script_id, save: true)
test 'submitting a script with auto attributes that succeeds' do
Dir.mktmpdir do |dir|
project_id = setup_project(dir)
script_id = setup_script(project_id)
launcher_id = setup_script(project_id)
project_dir = File.join(dir, 'projects', project_id)
ondemand_dir = File.join(project_dir, '.ondemand')
add_account(project_id, script_id)
add_account(project_id, launcher_id)

launcher_path = project_launcher_path(project_id, script_id)
launcher_path = project_launcher_path(project_id, launcher_id)
find("[href='#{launcher_path}'].btn-success").click
assert_selector('h1', text: 'the script title', count: 1)

Expand Down Expand Up @@ -412,18 +412,18 @@ def add_auto_environment_variable(project_id, script_id, save: true)
test 'submitting a script with job name' do
Dir.mktmpdir do |dir|
project_id = setup_project(dir)
script_id = setup_script(project_id)
launcher_id = setup_script(project_id)
project_dir = File.join(dir, 'projects', project_id)
ondemand_dir = File.join(project_dir, '.ondemand')
add_account(project_id, script_id, save: false)
add_account(project_id, launcher_id, save: false)

click_on('Add new option')
select('Job Name', from: 'add_new_field_select')
click_on(I18n.t('dashboard.add'))
fill_in('launcher_auto_job_name', with: 'my cool job name')
click_on(I18n.t('dashboard.save'))

launcher_path = project_launcher_path(project_id, script_id)
launcher_path = project_launcher_path(project_id, launcher_id)
find("[href='#{launcher_path}'].btn-success").click
assert_selector('h1', text: 'the script title', count: 1)

Expand Down Expand Up @@ -460,12 +460,12 @@ def add_auto_environment_variable(project_id, script_id, save: true)
test 'submitting a script with auto attributes that fails' do
Dir.mktmpdir do |dir|
project_id = setup_project(dir)
script_id = setup_script(project_id)
launcher_id = setup_script(project_id)
project_dir = File.join(dir, 'projects', project_id)
ondemand_dir = File.join(project_dir, '.ondemand')
add_account(project_id, script_id)
add_account(project_id, launcher_id)

launcher_path = project_launcher_path(project_id, script_id)
launcher_path = project_launcher_path(project_id, launcher_id)
find("[href='#{launcher_path}'].btn-success").click
assert_selector('h1', text: 'the script title', count: 1)

Expand Down Expand Up @@ -494,11 +494,11 @@ def add_auto_environment_variable(project_id, script_id, save: true)
test 'editing scripts initializes correctly' do
Dir.mktmpdir do |dir|
project_id = setup_project(dir)
script_id = setup_script(project_id)
launcher_id = setup_script(project_id)

visit project_path(project_id)

edit_launcher_path = edit_project_launcher_path(project_id, script_id)
edit_launcher_path = edit_project_launcher_path(project_id, launcher_id)
find("[href='#{edit_launcher_path}']").click

click_on('Add new option')
Expand All @@ -516,11 +516,11 @@ def add_auto_environment_variable(project_id, script_id, save: true)
test 'adding new fields to scripts' do
Dir.mktmpdir do |dir|
project_id = setup_project(dir)
script_id = setup_script(project_id)
launcher_id = setup_script(project_id)

visit project_path(project_id)

edit_launcher_path = edit_project_launcher_path(project_id, script_id)
edit_launcher_path = edit_project_launcher_path(project_id, launcher_id)
find("[href='#{edit_launcher_path}']").click

# only shows 'cluster' & 'auto_scripts'
Expand All @@ -533,8 +533,8 @@ def add_auto_environment_variable(project_id, script_id, save: true)
end

# add bc_num_hours
add_bc_num_hours(project_id, script_id)
script_edit_path = edit_project_launcher_path(project_id, script_id)
add_bc_num_hours(project_id, launcher_id)
script_edit_path = edit_project_launcher_path(project_id, launcher_id)
find("[href='#{script_edit_path}']").click

# now shows 'cluster', 'auto_scripts' & the newly added'bc_num_hours'
Expand All @@ -552,7 +552,7 @@ def add_auto_environment_variable(project_id, script_id, save: true)
find('#save_launcher_bc_num_hours').click

# add auto_environment_variable
add_auto_environment_variable(project_id, script_id)
add_auto_environment_variable(project_id, launcher_id)
find('#edit_launcher_auto_environment_variable').click

find("[data-auto-environment-variable='name']").fill_in(with: 'SOME_VARIABLE')
Expand Down Expand Up @@ -616,22 +616,22 @@ def add_auto_environment_variable(project_id, script_id, save: true)
required: false
HEREDOC

assert_equal(expected_yml, File.read("#{dir}/projects/#{project_id}/.ondemand/scripts/#{script_id}/form.yml"))
assert_equal(expected_yml, File.read("#{dir}/projects/#{project_id}/.ondemand/scripts/#{launcher_id}/form.yml"))
end
end

test 'removing script fields' do
Dir.mktmpdir do |dir|
project_id = setup_project(dir)
script_id = setup_script(project_id)
launcher_id = setup_script(project_id)

# add bc_num_hours
add_bc_num_hours(project_id, script_id)
add_account(project_id, script_id)
add_bc_num_hours(project_id, launcher_id)
add_account(project_id, launcher_id)

# go to edit it and see that there is cluster and bc_num_hours
visit project_path(project_id)
edit_launcher_path = edit_project_launcher_path(project_id, script_id)
edit_launcher_path = edit_project_launcher_path(project_id, launcher_id)
find("[href='#{edit_launcher_path}']").click
# puts page.body
assert_equal 4, page.all('.editable-form-field').size
Expand Down Expand Up @@ -708,7 +708,7 @@ def add_auto_environment_variable(project_id, script_id, save: true)
required: false
HEREDOC

assert_equal(expected_yml, File.read("#{dir}/projects/#{project_id}/.ondemand/scripts/#{script_id}/form.yml"))
assert_equal(expected_yml, File.read("#{dir}/projects/#{project_id}/.ondemand/scripts/#{launcher_id}/form.yml"))
end
end

Expand Down Expand Up @@ -769,10 +769,10 @@ def add_auto_environment_variable(project_id, script_id, save: true)
test 'excluding and including select options' do
Dir.mktmpdir do |dir|
project_id = setup_project(dir)
script_id = setup_script(project_id)
add_account(project_id, script_id)
launcher_id = setup_script(project_id)
add_account(project_id, launcher_id)

visit edit_project_launcher_path(project_id, script_id)
visit edit_project_launcher_path(project_id, launcher_id)

find('#edit_launcher_auto_accounts').click
exclude_accounts = ['pas2051', 'pas1871', 'pas1754', 'pas1604']
Expand All @@ -792,7 +792,7 @@ def add_auto_environment_variable(project_id, script_id, save: true)

find('#save_script_edit').click
assert_current_path(project_path(project_id))
launcher_path = project_launcher_path(project_id, script_id)
launcher_path = project_launcher_path(project_id, launcher_id)
find("[href='#{launcher_path}'].btn-success").click

# now let's check scripts#show to see if they've actually been excluded.
Expand All @@ -801,7 +801,7 @@ def add_auto_environment_variable(project_id, script_id, save: true)
assert(!show_account_options.include?(acct))
end

visit edit_project_launcher_path(project_id, script_id)
visit edit_project_launcher_path(project_id, launcher_id)
find('#edit_launcher_auto_accounts').click

exclude_accounts.each do |acct|
Expand All @@ -820,7 +820,7 @@ def add_auto_environment_variable(project_id, script_id, save: true)

find('#save_script_edit').click
assert_current_path(project_path(project_id))
launcher_path = project_launcher_path(project_id, script_id)
launcher_path = project_launcher_path(project_id, launcher_id)
find("[href='#{launcher_path}'].btn-success").click

# now let's check scripts#show and they should be back.
Expand All @@ -834,10 +834,10 @@ def add_auto_environment_variable(project_id, script_id, save: true)
test 'fixing select options' do
Dir.mktmpdir do |dir|
project_id = setup_project(dir)
script_id = setup_script(project_id)
add_account(project_id, script_id)
launcher_id = setup_script(project_id)
add_account(project_id, launcher_id)

visit edit_project_launcher_path(project_id, script_id)
visit edit_project_launcher_path(project_id, launcher_id)

find('#edit_launcher_auto_accounts').click
accounts_select = find('#launcher_auto_accounts')
Expand Down Expand Up @@ -865,8 +865,8 @@ def add_auto_environment_variable(project_id, script_id, save: true)
test 'excluding newly created options' do
Dir.mktmpdir do |dir|
project_id = setup_project(dir)
script_id = setup_script(project_id)
visit(edit_project_launcher_path(project_id, script_id))
launcher_id = setup_script(project_id)
visit(edit_project_launcher_path(project_id, launcher_id))

# now add 'auto_accounts'
click_on('Add new option')
Expand Down Expand Up @@ -915,11 +915,11 @@ def add_auto_environment_variable(project_id, script_id, save: true)
forms = Dir.glob("#{abs_project_dir}/.ondemand/**/*/form.yml")
assert_equal(3, forms.size)

script_id = '8woi7ghd'
orig_form = "#{Rails.root}/test/fixtures/projects/chemistry-5533/.ondemand/scripts/#{script_id}/form.yml"
launcher_id = '8woi7ghd'
orig_form = "#{Rails.root}/test/fixtures/projects/chemistry-5533/.ondemand/scripts/#{launcher_id}/form.yml"
orig_form = YAML.safe_load(File.read(orig_form))

new_form = "#{abs_project_dir}/.ondemand/scripts/#{script_id}/form.yml"
new_form = "#{abs_project_dir}/.ondemand/scripts/#{launcher_id}/form.yml"
new_form = YAML.safe_load(File.read(new_form))

# 'form' & 'title' are the same
Expand Down

0 comments on commit 520d681

Please sign in to comment.