Commit efcfcd45169ebf7f95279a3e6b1b5fb7b32aab0a
Committed by
Paulo Meireles
1 parent
c9ee80a9
Exists in
master
and in
22 other branches
[Mezuro] Started functionals tests for myprofile controller.
Showing
6 changed files
with
85 additions
and
69 deletions
Show diff stats
plugins/mezuro/lib/kalibro/base_tool.rb
... | ... | @@ -6,8 +6,8 @@ class Kalibro::BaseTool < Kalibro::Model |
6 | 6 | request("BaseTool", :get_base_tool_names)[:base_tool_name].to_a |
7 | 7 | end |
8 | 8 | |
9 | - def self.find_by_name(name) | |
10 | - new request("BaseTool", :get_base_tool, {:base_tool_name => name})[:base_tool] | |
9 | + def self.find_by_name(base_tool_name) | |
10 | + new request("BaseTool", :get_base_tool, {:base_tool_name => base_tool_name})[:base_tool] | |
11 | 11 | end |
12 | 12 | |
13 | 13 | def supported_metric=(value) | ... | ... |
plugins/mezuro/lib/kalibro/metric_configuration.rb
... | ... | @@ -50,9 +50,14 @@ class Kalibro::MetricConfiguration < Kalibro::Model |
50 | 50 | end |
51 | 51 | |
52 | 52 | def save |
53 | + begin | |
53 | 54 | self.class.request("MetricConfiguration", :save_metric_configuration, { |
54 | 55 | :metric_configuration => to_hash, |
55 | 56 | :configuration_name => configuration_name}) |
57 | + true | |
58 | + rescue Exception => error | |
59 | + false | |
60 | + end | |
56 | 61 | end |
57 | 62 | |
58 | 63 | def destroy | ... | ... |
plugins/mezuro/lib/kalibro/model.rb
... | ... | @@ -18,11 +18,7 @@ class Kalibro::Model |
18 | 18 | end |
19 | 19 | hash |
20 | 20 | end |
21 | - | |
22 | - def self.request(endpoint, action, request_body = nil) | |
23 | - response = client(endpoint).request(:kalibro, action) { soap.body = request_body } | |
24 | - response.to_hash["#{action}_response".to_sym] # response is a Savon::SOAP::Response, and to_hash is a Savon::SOAP::Response method | |
25 | - end | |
21 | + | |
26 | 22 | protected |
27 | 23 | |
28 | 24 | def fields |
... | ... | @@ -55,6 +51,11 @@ class Kalibro::Model |
55 | 51 | field.to_s[0] != '@' and field != :attributes! and (field.to_s =~ /xsi/).nil? |
56 | 52 | end |
57 | 53 | |
54 | + def self.request(endpoint, action, request_body = nil) | |
55 | + response = client(endpoint).request(:kalibro, action) { soap.body = request_body } | |
56 | + response.to_hash["#{action}_response".to_sym] # response is a Savon::SOAP::Response, and to_hash is a Savon::SOAP::Response method | |
57 | + end | |
58 | + | |
58 | 59 | def to_objects_array(value, model_class = nil) |
59 | 60 | array = value.kind_of?(Array) ? value : [value] |
60 | 61 | array.each.collect { |element| to_object(element, model_class) } |
... | ... | @@ -65,3 +66,4 @@ class Kalibro::Model |
65 | 66 | end |
66 | 67 | |
67 | 68 | end |
69 | + | ... | ... |
plugins/mezuro/test/fixtures/metric_result_fixtures.rb
... | ... | @@ -9,13 +9,13 @@ class MetricResultFixtures |
9 | 9 | result.metric = NativeMetricFixtures.amloc |
10 | 10 | result.value = 0.0 |
11 | 11 | result.descendent_results = [40.0, 42.0] |
12 | - result.range = RangeFixtures.amloc_excellent | |
12 | + result.range = RangeFixtures.range_excellent | |
13 | 13 | result |
14 | 14 | end |
15 | 15 | |
16 | 16 | def self.sc_result |
17 | 17 | result = Kalibro::Entities::MetricResult.new |
18 | - result.metric = CompoundMetricFixtures.sc | |
18 | + result.metric = CompoundMetricFixtures.compound_metric | |
19 | 19 | result.value = 1.0 |
20 | 20 | result.descendent_results = [2.0, 42.0] |
21 | 21 | result |
... | ... | @@ -23,14 +23,14 @@ class MetricResultFixtures |
23 | 23 | |
24 | 24 | def self.amloc_result_hash |
25 | 25 | {:metric => NativeMetricFixtures.amloc_hash, :value => 0.0, :descendent_result => [40.0, 42.0], |
26 | - :range => RangeFixtures.amloc_excellent_hash, | |
26 | + :range => RangeFixtures.range_excellent_hash, | |
27 | 27 | :attributes! => {:metric => { |
28 | 28 | 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', |
29 | 29 | 'xsi:type' => 'kalibro:nativeMetricXml' }}} |
30 | 30 | end |
31 | 31 | |
32 | 32 | def self.sc_result_hash |
33 | - {:metric => CompoundMetricFixtures.sc_hash, :value => 1.0, :descendent_result => [2.0, 42.0], | |
33 | + {:metric => CompoundMetricFixtures.compound_metric_hash, :value => 1.0, :descendent_result => [2.0, 42.0], | |
34 | 34 | :attributes! => {:metric => { |
35 | 35 | 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', |
36 | 36 | 'xsi:type' => 'kalibro:compoundMetricXml' }}} | ... | ... |
plugins/mezuro/test/functional/mezuro_plugin_myprofile_controller_test.rb
... | ... | @@ -14,80 +14,91 @@ class MezuroPluginMyprofileControllerTest < ActionController::TestCase |
14 | 14 | @response = ActionController::TestResponse.new |
15 | 15 | @profile = fast_create(Community) |
16 | 16 | |
17 | - @base_tool = BaseToolFixtures.analizo | |
18 | - @base_tool_client = Kalibro::Client::BaseToolClient.new | |
17 | + @base_tool = BaseToolFixtures.base_tool | |
19 | 18 | @metric = NativeMetricFixtures.amloc |
20 | - @metric_configuration_client = Kalibro::Client::MetricConfigurationClient.new | |
21 | - @metric_configuration = MetricConfigurationFixtures.amloc_configuration | |
22 | - @compound_metric_configuration = MetricConfigurationFixtures.sc_configuration | |
23 | - @configuration = ConfigurationFixtures.kalibro_configuration | |
19 | + @metric_configuration = MetricConfigurationFixtures.amloc_metric_configuration | |
20 | + @metric_configuration_hash = MetricConfigurationFixtures.amloc_metric_configuration_hash | |
21 | + @compound_metric_configuration = MetricConfigurationFixtures.sc_metric_configuration | |
22 | + @configuration = ConfigurationFixtures.configuration | |
24 | 23 | end |
25 | - | |
26 | - should 'assign configuration content in choose_base_tool' do | |
27 | - create_configuration_content | |
28 | - Kalibro::Client::BaseToolClient.expects(:base_tools).returns([]) | |
24 | + | |
25 | + should 'test choose_base_tool' do | |
26 | + create_configuration_content | |
27 | + Kalibro::BaseTool.expects(:all_names).returns(@base_tool.name) | |
29 | 28 | get :choose_base_tool, :profile => @profile.identifier, :id => @content.id |
30 | - assert_equal assigns(:configuration_content), @content | |
31 | - end | |
32 | - | |
33 | - should 'assign configuration and base_tool name in choose_metric' do | |
34 | - create_configuration_content | |
35 | - Kalibro::Client::BaseToolClient.expects(:new).returns(@base_tool_client) | |
36 | - @base_tool_client.expects(:base_tool).with(@base_tool.name).returns(@base_tool) | |
37 | - get :choose_metric, :profile => @profile.identifier, :id => @content.id, :base_tool => @base_tool.name | |
29 | + assert_equal @base_tool.name, assigns(:base_tools) | |
38 | 30 | assert_equal @content, assigns(:configuration_content) |
39 | - assert_equal @base_tool.name, assigns(:base_tool) | |
31 | + assert_response 200 | |
40 | 32 | end |
41 | 33 | |
42 | - should 'get base_tool by name' do | |
34 | + should 'test choose_metric' do | |
43 | 35 | create_configuration_content |
44 | - Kalibro::Client::BaseToolClient.expects(:new).returns(@base_tool_client) | |
45 | - @base_tool_client.expects(:base_tool).with(@base_tool.name).returns(@base_tool) | |
36 | + Kalibro::BaseTool.expects(:find_by_name).with(@base_tool.name).returns(@base_tool) | |
37 | + @base_tool.expects(:supported_metrics).returns(@base_tool.supported_metric) | |
46 | 38 | get :choose_metric, :profile => @profile.identifier, :id => @content.id, :base_tool => @base_tool.name |
39 | + assert_equal @content, assigns(:configuration_content) | |
47 | 40 | assert_equal @base_tool.name, assigns(:base_tool) |
41 | + assert_equal @base_tool.supported_metric, assigns(:supported_metrics) | |
42 | + assert_response 200 | |
48 | 43 | end |
49 | 44 | |
50 | - should 'get chosen native metric and configuration name' do | |
45 | + should 'test new_metric_configuration' do | |
51 | 46 | create_configuration_content |
52 | - Kalibro::Client::BaseToolClient.expects(:new).returns(@base_tool_client) | |
53 | - @base_tool_client.expects(:base_tool).with(@base_tool.name).returns(@base_tool) | |
47 | + Kalibro::BaseTool.expects(:find_by_name).with(@base_tool.name).returns(@base_tool) | |
48 | + @base_tool.expects(:metric).with(@metric.name).returns(@metric) | |
54 | 49 | get :new_metric_configuration, :profile => @profile.identifier, :id => @content.id, :base_tool => @base_tool.name, :metric_name => @metric.name |
55 | 50 | assert_equal @content, assigns(:configuration_content) |
56 | 51 | assert_equal @metric, assigns(:metric) |
52 | + assert_response 200 | |
57 | 53 | end |
58 | 54 | |
59 | - should 'call configuration client in new_compound_metric_configuration method' do | |
55 | + | |
56 | + should 'test new_compound_metric_configuration' do | |
60 | 57 | create_configuration_content |
61 | - configuration_client = mock | |
62 | - Kalibro::Client::ConfigurationClient.expects(:new).returns(configuration_client) | |
63 | - configuration_client.expects(:configuration).with(@configuration.name).returns(@configuration) | |
58 | + Kalibro::Configuration.expects(:find_by_name).with(@content.name).returns(@configuration) | |
59 | + @configuration.expects(:metric_configurations).returns(@configuration.metric_configuration) | |
64 | 60 | get :new_compound_metric_configuration, :profile => @profile.identifier, :id => @content.id |
61 | + assert_equal @content, assigns(:configuration_content) | |
62 | + assert_equal @configuration.metric_configuration, assigns(:metric_configurations) | |
65 | 63 | assert_response 200 |
66 | 64 | end |
67 | 65 | |
68 | - should 'assign configuration name and get metric_configuration' do | |
66 | + should 'test edit_metric_configuration' do | |
69 | 67 | create_configuration_content |
70 | - Kalibro::Client::MetricConfigurationClient.expects(:new).returns(@metric_configuration_client) | |
71 | - @metric_configuration_client.expects(:metric_configuration).with(@configuration.name, @metric.name).returns(@metric_configuration) | |
68 | + Kalibro::MetricConfiguration.expects(:find_by_configuration_name_and_metric_name).with(@configuration.name, @metric.name).returns(@metric_configuration) | |
72 | 69 | get :edit_metric_configuration, :profile => @profile.identifier, :id => @content.id, :metric_name => @metric.name |
73 | - assert_equal assigns(:configuration_content), @content | |
74 | - assert_equal assigns(:metric_configuration), @metric_configuration | |
75 | - assert_equal assigns(:metric), @metric_configuration.metric | |
70 | + assert_equal @content, assigns(:configuration_content) | |
71 | + assert_equal @metric_configuration, assigns(:metric_configuration) | |
72 | + assert_equal @metric_configuration.metric, assigns(:metric) | |
73 | + assert_response 200 | |
76 | 74 | end |
77 | 75 | |
78 | - should 'test metric creation' do | |
76 | + should 'test edit_compound_metric_configuration' do | |
79 | 77 | create_configuration_content |
80 | - Kalibro::Client::MetricConfigurationClient.expects(:new).returns(@metric_configuration_client) | |
81 | - @metric_configuration_client.expects(:save) | |
82 | - get :create_metric_configuration, :profile => @profile.identifier, :id => @content.id, | |
83 | - :metric_configuration => { :code => @metric_configuration.code, :weight => @metric_configuration.code, :aggregation => @metric_configuration.aggregation_form, | |
84 | - :metric => { :name => @metric.name, :origin => @metric.origin, :description => @metric.description, :scope => @metric.scope, :language => @metric.language }} | |
78 | + Kalibro::MetricConfiguration.expects(:find_by_configuration_name_and_metric_name).with(@configuration.name, @metric.name).returns(@compound_metric_configuration) | |
79 | + Kalibro::Configuration.expects(:find_by_name).with(@content.name).returns(@configuration) | |
80 | + @configuration.expects(:metric_configurations).returns(@configuration.metric_configuration) | |
81 | + get :edit_compound_metric_configuration, :profile => @profile.identifier, :id => @content.id, :metric_name => @metric.name | |
82 | + assert_equal @content, assigns(:configuration_content) | |
83 | + assert_equal @compound_metric_configuration, assigns(:metric_configuration) | |
84 | + assert_equal @compound_metric_configuration.metric, assigns(:metric) | |
85 | + assert_equal @configuration.metric_configuration, assigns(:metric_configurations) | |
86 | + assert_response 200 | |
87 | + end | |
88 | + | |
89 | + should 'test create_metric_configuration' do | |
90 | + create_configuration_content | |
91 | + @metric_configuration.expects(:save).returns(true) | |
92 | + MezuroPlugin::ConfigurationContent.expects(:validate_kalibro_configuration_name).returns(true) | |
93 | + MezuroPlugin::ConfigurationContent.expects(:send_configuration_to_service).returns(true) | |
94 | + get :create_metric_configuration, :profile => @profile.identifier, :id => @content.id, :metric_configuration => @metric_configuration_hash | |
85 | 95 | assert_response 302 |
86 | 96 | end |
87 | 97 | |
98 | +=begin | |
88 | 99 | should 'test compound metric creation' do |
89 | 100 | create_configuration_content |
90 | - Kalibro::Client::MetricConfigurationClient.expects(:new).returns(@metric_configuration_client) | |
101 | + Kalibro::MetricConfiguration.expects(:new).returns(@metric_configuration_client) | |
91 | 102 | @metric_configuration_client.expects(:save) |
92 | 103 | get :create_compound_metric_configuration, :profile => @profile.identifier, :id => @content.id, |
93 | 104 | :metric_configuration => { :code => @compound_metric_configuration.code, :weight => @compound_metric_configuration.weight, |
... | ... | @@ -99,7 +110,7 @@ class MezuroPluginMyprofileControllerTest < ActionController::TestCase |
99 | 110 | |
100 | 111 | should 'test metric edition' do |
101 | 112 | create_configuration_content |
102 | - Kalibro::Client::MetricConfigurationClient.expects(:new).returns(@metric_configuration_client) | |
113 | + Kalibro::MetricConfiguration.expects(:new).returns(@metric_configuration_client) | |
103 | 114 | @metric_configuration_client.expects(:metric_configuration).with(@configuration.name,@metric.name).returns(@metric_configuration) |
104 | 115 | get :edit_metric_configuration, :profile => @profile.identifier, :id => @content.id, :metric_name => @metric.name |
105 | 116 | assert_response 200 |
... | ... | @@ -108,8 +119,8 @@ class MezuroPluginMyprofileControllerTest < ActionController::TestCase |
108 | 119 | should 'test compound metric edition' do |
109 | 120 | create_configuration_content |
110 | 121 | configuration_client = mock |
111 | - Kalibro::Client::MetricConfigurationClient.expects(:new).returns(@metric_configuration_client) | |
112 | - Kalibro::Client::ConfigurationClient.expects(:new).returns(configuration_client) | |
122 | + Kalibro::MetricConfiguration.expects(:new).returns(@metric_configuration_client) | |
123 | + Kalibro::Configuration.expects(:new).returns(configuration_client) | |
113 | 124 | configuration_client.expects(:configuration).with(@configuration.name).returns(@configuration) |
114 | 125 | @metric_configuration_client.expects(:metric_configuration).with(@configuration.name,@metric.name).returns(@compound_metric_configuration) |
115 | 126 | get :edit_compound_metric_configuration, :profile => @profile.identifier, :id => @content.id, :metric_name => @metric.name |
... | ... | @@ -118,8 +129,8 @@ class MezuroPluginMyprofileControllerTest < ActionController::TestCase |
118 | 129 | |
119 | 130 | should 'update metric configuration' do |
120 | 131 | create_configuration_content |
121 | - Kalibro::Client::MetricConfigurationClient.expects(:new).returns(@metric_configuration_client) | |
122 | - Kalibro::Client::MetricConfigurationClient.expects(:new).returns(@metric_configuration_client) | |
132 | + Kalibro::MetricConfiguration.expects(:new).returns(@metric_configuration_client) | |
133 | + Kalibro::MetricConfiguration.expects(:new).returns(@metric_configuration_client) | |
123 | 134 | @metric_configuration_client.expects(:metric_configuration).with(@configuration.name, @metric_configuration.metric.name).returns(@metric_configuration) |
124 | 135 | @metric_configuration_client.expects(:save) |
125 | 136 | get :update_metric_configuration, :profile => @profile.identifier, :id => @content.id, |
... | ... | @@ -130,8 +141,8 @@ class MezuroPluginMyprofileControllerTest < ActionController::TestCase |
130 | 141 | |
131 | 142 | should 'update compound metric configuration' do |
132 | 143 | create_configuration_content |
133 | - Kalibro::Client::MetricConfigurationClient.expects(:new).returns(@metric_configuration_client) | |
134 | - Kalibro::Client::MetricConfigurationClient.expects(:new).returns(@metric_configuration_client) | |
144 | + Kalibro::MetricConfiguration.expects(:new).returns(@metric_configuration_client) | |
145 | + Kalibro::MetricConfiguration.expects(:new).returns(@metric_configuration_client) | |
135 | 146 | @metric_configuration_client.expects(:metric_configuration).with(@configuration.name, @compound_metric_configuration.metric.name).returns(@compound_metric_configuration) |
136 | 147 | @metric_configuration_client.expects(:save) |
137 | 148 | get :update_compound_metric_configuration, :profile => @profile.identifier, :id => @content.id, |
... | ... | @@ -151,33 +162,31 @@ class MezuroPluginMyprofileControllerTest < ActionController::TestCase |
151 | 162 | |
152 | 163 | should 'create instance range' do |
153 | 164 | create_configuration_content |
154 | - Kalibro::Client::MetricConfigurationClient.expects(:new).returns(@metric_configuration_client) | |
155 | - Kalibro::Client::MetricConfigurationClient.expects(:new).returns(@metric_configuration_client) | |
165 | + Kalibro::MetricConfiguration.expects(:new).returns(@metric_configuration_client) | |
166 | + Kalibro::MetricConfiguration.expects(:new).returns(@metric_configuration_client) | |
156 | 167 | @metric_configuration_client.expects(:metric_configuration).with(@configuration.name, @metric.name).returns(@metric_configuration) |
157 | 168 | @metric_configuration_client.expects(:save) |
158 | 169 | range = @metric_configuration.ranges[0] |
159 | 170 | get :create_range, :profile => @profile.identifier, :range => { :beginning => range.beginning, :end => range.end, :label => range.label, |
160 | 171 | :grade => range.grade, :color => range.color, :comments => range.comments }, :id => @content.id, :metric_name => @metric.name |
161 | - assert assigns(:range).instance_of?(Kalibro::Entities::Range) | |
172 | + assert assigns(:range).instance_of?(Kalibro::Range) | |
162 | 173 | end |
163 | 174 | |
164 | 175 | should 'redirect from remove metric configuration' do |
165 | 176 | create_configuration_content |
166 | - Kalibro::Client::MetricConfigurationClient.expects(:new).returns(@metric_configuration_client) | |
177 | + Kalibro::MetricConfiguration.expects(:new).returns(@metric_configuration_client) | |
167 | 178 | @metric_configuration_client.expects(:remove) |
168 | 179 | get :remove_metric_configuration, :profile => @profile.identifier, :id => @content.id, :metric_name => @metric.name |
169 | 180 | assert_response 302 |
170 | 181 | end |
171 | 182 | |
172 | 183 | private |
184 | +=end | |
173 | 185 | |
174 | 186 | def create_configuration_content |
175 | - client = mock | |
176 | - Kalibro::Client::ConfigurationClient.expects(:new).returns(client) | |
177 | - client.expects(:configuration_names).returns([]) | |
187 | + Kalibro::Configuration.expects(:all_names).returns([]) | |
178 | 188 | @content = MezuroPlugin::ConfigurationContent.new(:profile => @profile, :name => @configuration.name) |
179 | 189 | @content.expects(:send_configuration_to_service).returns(nil) |
180 | 190 | @content.save |
181 | 191 | end |
182 | - | |
183 | 192 | end | ... | ... |
plugins/mezuro/test/unit/kalibro/metric_configuration_test.rb
... | ... | @@ -53,7 +53,7 @@ class MetricConfigurationTest < ActiveSupport::TestCase |
53 | 53 | } |
54 | 54 | response_hash = {:metric_configuration => @metric_configuration1.to_hash} |
55 | 55 | Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :get_metric_configuration, request_body).returns(response_hash) |
56 | - metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_and_metric(@metric_configuration1.configuration_name, | |
56 | + metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(@metric_configuration1.configuration_name, | |
57 | 57 | @metric_configuration1.metric.name) |
58 | 58 | assert_equal @metric_configuration1.code, metric_configuration.code |
59 | 59 | end | ... | ... |