Skip to content

Commit

Permalink
fix test fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
relf committed Jan 1, 2020
1 parent f5ac652 commit 53be1a0
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 40 deletions.
11 changes: 8 additions & 3 deletions app/controllers/analyses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,22 @@ def create
# PATCH/PUT /mdas/1
def update
if @mda.update(mda_params)
redirect_to mda_url(@mda), notice: "MDA was successfully updated."
redirect_to mda_url(@mda), notice: "Analysis #{@mda.name} was successfully updated."
else
render :edit
end
end

# DELETE /mdas/1
def destroy
@mda.destroy
redirect_to mdas_url, notice: "MDA was successfully deleted."
if @mda.parent
redirect_to mdas_url, alert: "Can not delete nested analysis (you should delete parent first)."
else
@mda.destroy!
redirect_to mdas_url, notice: "Analysis #{@mda.name} was successfully deleted."
end
rescue Operation::ForbiddenRemovalException => exc
# p "Can not delete analysis #{@mda.name} for following reason: "+exc.message
redirect_to mdas_url, alert: "Can not delete analysis #{@mda.name} for following reason: "+exc.message
end

Expand Down
59 changes: 41 additions & 18 deletions test/controllers/analyses_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
class AnalysesControllerTest < ActionDispatch::IntegrationTest
setup do
sign_in users(:user1)
@mda = analyses(:cicav)
@cicav = analyses(:cicav)
@singl = analyses(:singleton)
end

test "should get index" do
Expand Down Expand Up @@ -50,7 +51,7 @@ class AnalysesControllerTest < ActionDispatch::IntegrationTest

test "should authorized access to members" do
sign_in users(:user3)
get mda_url(@mda)
get mda_url(@cicav)
assert_response :success
end

Expand Down Expand Up @@ -80,56 +81,78 @@ class AnalysesControllerTest < ActionDispatch::IntegrationTest
end

test "should show analysis" do
get mda_url(@mda)
get mda_url(@cicav)
assert_response :success
end

test "should get edit" do
get edit_mda_url(@mda)
get edit_mda_url(@cicav)
assert_response :success
end

test "should update analysis" do
patch mda_url(@mda), params: { analysis: { name: @mda.name } }
assert_redirected_to mda_url(@mda)
patch mda_url(@cicav), params: { analysis: { name: @cicav.name } }
assert_redirected_to mda_url(@cicav)
end

test "should destroy analysis" do
sign_out users(:user1)
sign_in users(:user3)
assert_difference("Analysis.count", -1) do
delete mda_url(@mda)
delete mda_url(@singl)
end
assert_redirected_to mdas_url
assert_not flash[:alert]
end

test "should not destroy analysis if nested" do
assert_difference("Analysis.count", 0) do
delete mda_url(analyses(:innermda))
end
assert_redirected_to mdas_url
assert_match /Can not delete nested analysis/, flash[:alert]
end

test "tata should not destroy analysis due to operation" do
assert_difference("Analysis.count", 0) do
delete mda_url(@cicav)
end
assert_redirected_to mdas_url
assert_match /Can not delete analysis/, flash[:alert]
end

test "should not destroy analysis, if not owner" do
sign_out users(:user1)
sign_in users(:user2)
assert_difference("Analysis.count", 0) do
delete mda_url(@mda)
delete mda_url(@singl)
end
assert_redirected_to root_path
assert_equal "You are not authorized to perform this action.", flash[:error]
end

test "should destroy discipline when destroying analysis" do
q = @mda.disciplines
sign_out users(:user1)
sign_in users(:user3)
q = @singl.disciplines
assert_difference("Discipline.count", -q.count) do
delete mda_url(@mda)
delete mda_url(@singl)
end
end

test "should destroy variables when destroying analysis" do
q = Variable.joins(discipline: :analysis).where(analyses: { id: @mda.id })
sign_out users(:user1)
sign_in users(:user3)
q = Variable.joins(discipline: :analysis).where(analyses: { id: @singl.id })
assert_difference("Variable.count", -q.count) do
delete mda_url(@mda)
delete mda_url(@singl)
end
end

test "should destroy connections when destroying analysis" do
q = Connection.of_analysis(@mda.id)
sign_out users(:user1)
sign_in users(:user3)
q = Connection.of_analysis(@singl.id)
assert_difference("Connection.count", -q.count) do
delete mda_url(@mda)
delete mda_url(@singl)
end
end

Expand All @@ -144,10 +167,10 @@ class AnalysesControllerTest < ActionDispatch::IntegrationTest
sign_out users(:user1)
sign_in users(:user2)
assert_difference("Analysis.count") do
post mdas_url, params: { mda_id: @mda.id }
post mdas_url, params: { mda_id: @cicav.id }
assert_redirected_to mda_url(Analysis.last)
end
assert_equal @mda.disciplines.count, Analysis.last.disciplines.count
assert_equal @cicav.disciplines.count, Analysis.last.disciplines.count
end

test "should make a copy of a nested analysis" do
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/meta_models_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class MetaModelsControllerTest < ActionDispatch::IntegrationTest
assert_equal "10", z.parameter.upper
assert_equal 1, mda.response_variables.count
mm = MetaModel.last
assert_equal @ope, mm.operation
assert_equal @ope, mm.operation.base_operation
assert_equal mda.disciplines.last, mm.discipline
assert_equal Surrogate::SMT_KPLS, mm.default_surrogate_kind
assert_equal 1, mm.surrogates.count
Expand Down
8 changes: 4 additions & 4 deletions test/fixtures/cases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ case_objective_in:
0.87, 2.15, 1.71, 1.54, 2.15, 2.17, 1.54, 2.20, 1.87, 1.0]

case1_metamodel2:
operation: doe_metamodel2
operation: doe2
variable: varx1_out
values: [7.7392804924995495, 3.6007798935817577, 3.989850801305399, 0.9313474293213041, 4.508603023298205,
7.884786920282569, 6.904193222540709, 2.9943279135979184, 4.610473153197965, 9.356387990896843,
Expand All @@ -59,7 +59,7 @@ case1_metamodel2:
3.0883656196335814, 3.512763328620458, 5.585752947917726, 4.863906539028047, 1.750391268438162]

case2_metamodel2:
operation: doe_metamodel2
operation: doe2
variable: varobj_geo_out
values: [93.00737696553041, 43.70581905802386, 86.43371516710735, 31.879906386871358, 69.41420147959725,
157.902046847367, 69.02123124092256, 14.917277295355847, 41.78954896113599, 118.61423315836271,
Expand All @@ -73,7 +73,7 @@ case2_metamodel2:
35.84181704608911, 91.78267552333716, 91.45203330892522, 61.766913310180094, 17.753394593134015]

case3_metamodel2:
operation: doe_metamodel2
operation: doe2
variable: varz_design_out
coord_index: 0
values: [3.2611702546557684, 4.184181278462304, 8.308813012449447, 4.9387549836644675, 6.181894927202372,
Expand All @@ -88,7 +88,7 @@ case3_metamodel2:
5.024487982315788, 7.870331021515714, 6.565081276248916, 5.602374444201422, 2.6095305543769998]

case4_metamodel2:
operation: doe_metamodel2
operation: doe2
variable: varz_design_out
coord_index: 1
values: [9.093767974924843, 6.364621709036845, 0.4579683838429552, 4.2842158969411335, 4.959564713315759,
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/jobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ sobol_sensitivity_job:
<<: *default_assume_done
operation: sobol_sensitivity

doe_metamodel2_job:
doe2_job:
<<: *default_assume_done
status: DONE
operation: doe_metamodel2
operation: doe2
4 changes: 2 additions & 2 deletions test/fixtures/meta_models.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
cicav_metamodel:
discipline: disc_cicav_metamodel
operation: doe
operation: mm_from_doe
default_surrogate_kind: SMT_KRIGING

cicav_metamodel2:
discipline: disc_cicav_metamodel2
operation: doe_metamodel2
operation: mm_from_doe2
default_surrogate_kind: SMT_KRIGING
15 changes: 13 additions & 2 deletions test/fixtures/operations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ doe:
driver: smt_doe_lhs
analysis: cicav
success: [1, 0, 1]


mm_from_doe:
base_operation: doe
name: mm
driver: smt_metamodel_kriging

morris_doe:
name: "morris doe"
driver: salib_doe_morris
Expand All @@ -42,7 +47,7 @@ sobol_sensitivity:
analysis: cicav
success: []

doe_metamodel2:
doe2:
name: LHS
driver: smt_doe_lhs
analysis: cicav
Expand All @@ -51,3 +56,9 @@ doe_metamodel2:
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1]

mm_from_doe2:
base_operation: doe2
name: mm2
driver: smt_metamodel_kriging

4 changes: 2 additions & 2 deletions test/fixtures/roles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ owner_singleton_role:
name: :owner
resource: singleton (Analysis)

owner_gm_one:
owner_gm_one_role:
name: :owner
resource: gm_one (GeometryModel)

owner_gm_two:
owner_gm_two_role:
name: :owner
resource: gm_two (GeometryModel)

6 changes: 3 additions & 3 deletions test/fixtures/users_roles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ users_roles8:

users_roles10:
user: user1
role: owner_gm_one
role: owner_gm_one_role

users_roles11:
user: user2
role: owner_gm_two
role: owner_gm_two_role

users_roles12:
user: user3
role: owner_singleton
role: owner_singleton_role
6 changes: 3 additions & 3 deletions test/models/analysis_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,11 @@ class AnalysisTest < ActiveSupport::TestCase
assert copy.is_metamodel_analysis?
orig_conns = Connection.of_analysis(mda)
copy_conns = Connection.of_analysis(copy)
# Connection.print(orig_conns)
# puts
# Connection.print(copy_conns)
assert_equal orig_conns.size, copy_conns.size
end

test "should copy of a copy of a metamodel and predict with even middle copy removed" do
skip "doe copy not yet implemented"
mda = analyses(:cicav_metamodel_analysis)
copy = mda.create_copy!
assert copy.is_metamodel_analysis?
Expand All @@ -137,6 +135,8 @@ class AnalysisTest < ActiveSupport::TestCase
y = mm.predict(x)
assert_in_delta 5, y[0][0]
assert_equal x.size, y.size
p mda.disciplines.second.meta_model.operation
mda.operations.map(&:destroy)
mda.destroy
mm.reload
y = mm.predict(x)
Expand Down

0 comments on commit 53be1a0

Please sign in to comment.