Commit d493cc56203adef61e3532ca3e013f31a5298616
Committed by
Carlos Morais
1 parent
f83c66b0
Exists in
master
and in
29 other branches
Update KalibroClient with new service operations
Showing
2 changed files
with
26 additions
and
27 deletions
Show diff stats
plugins/mezuro/lib/kalibro/client/kalibro_client.rb
| 1 | 1 | class Kalibro::Client::KalibroClient |
| 2 | + | |
| 3 | + def self.process_project(project_name) | |
| 4 | + new.process_project(project_name) | |
| 5 | + end | |
| 2 | 6 | |
| 3 | 7 | def initialize |
| 4 | 8 | @port = Kalibro::Client::Port.new('Kalibro') |
| ... | ... | @@ -12,8 +16,16 @@ class Kalibro::Client::KalibroClient |
| 12 | 16 | @port.request(:process_project, {:project_name => project_name}) |
| 13 | 17 | end |
| 14 | 18 | |
| 15 | - def self.process_project(project_name) | |
| 16 | - new.process_project(project_name) | |
| 19 | + def process_periodically(project_name, period_in_days) | |
| 20 | + @port.request(:process_periodically, {:project_name => project_name, :period_in_days => period_in_days}) | |
| 21 | + end | |
| 22 | + | |
| 23 | + def process_period(project_name) | |
| 24 | + @port.request(:get_process_period, {:project_name => project_name})[:period] | |
| 25 | + end | |
| 26 | + | |
| 27 | + def cancel_periodic_process(project_name) | |
| 28 | + @port.request(:cancel_periodic_process, {:project_name => project_name}) | |
| 17 | 29 | end |
| 18 | 30 | |
| 19 | 31 | end | ... | ... |
plugins/mezuro/test/unit/kalibro/client/project_result_client_test.rb
| ... | ... | @@ -13,59 +13,46 @@ class ProjectResultClientTest < ActiveSupport::TestCase |
| 13 | 13 | @project_name = @result.project.name |
| 14 | 14 | @date = @result.date |
| 15 | 15 | @flag = DateTime.now.sec % 2 == 0 |
| 16 | + | |
| 17 | + @request = {:project_name => @project_name} | |
| 18 | + @request_with_date = {:project_name => @project_name, :date => @date} | |
| 19 | + @flag_response = {:has_results => @flag} | |
| 20 | + @result_response = {:project_result => @result.to_hash} | |
| 16 | 21 | end |
| 17 | 22 | |
| 18 | 23 | should 'retrieve if project has results' do |
| 19 | - @port.expects(:request).with(:has_results_for, request).returns(flag_response) | |
| 24 | + @port.expects(:request).with(:has_results_for, @request).returns(@flag_response) | |
| 20 | 25 | assert_equal @flag, @client.has_results_for(@project_name) |
| 21 | 26 | end |
| 22 | 27 | |
| 23 | 28 | should 'retrieve if project has results before date' do |
| 24 | - @port.expects(:request).with(:has_results_before, request_with_date).returns(flag_response) | |
| 29 | + @port.expects(:request).with(:has_results_before, @request_with_date).returns(@flag_response) | |
| 25 | 30 | assert_equal @flag, @client.has_results_before(@project_name, @date) |
| 26 | 31 | end |
| 27 | 32 | |
| 28 | 33 | should 'retrieve if project has results after date' do |
| 29 | - @port.expects(:request).with(:has_results_after, request_with_date).returns(flag_response) | |
| 34 | + @port.expects(:request).with(:has_results_after, @request_with_date).returns(@flag_response) | |
| 30 | 35 | assert_equal @flag, @client.has_results_after(@project_name, @date) |
| 31 | 36 | end |
| 32 | 37 | |
| 33 | 38 | should 'get first result of project' do |
| 34 | - @port.expects(:request).with(:get_first_result_of, request).returns(result_response) | |
| 39 | + @port.expects(:request).with(:get_first_result_of, @request).returns(@result_response) | |
| 35 | 40 | assert_equal @result, @client.first_result(@project_name) |
| 36 | 41 | end |
| 37 | 42 | |
| 38 | 43 | should 'get last result of project' do |
| 39 | - @port.expects(:request).with(:get_last_result_of, request).returns(result_response) | |
| 44 | + @port.expects(:request).with(:get_last_result_of, @request).returns(@result_response) | |
| 40 | 45 | assert_equal @result, @client.last_result(@project_name) |
| 41 | 46 | end |
| 42 | 47 | |
| 43 | 48 | should 'get first result of project after date' do |
| 44 | - @port.expects(:request).with(:get_first_result_after, request_with_date).returns(result_response) | |
| 49 | + @port.expects(:request).with(:get_first_result_after, @request_with_date).returns(@result_response) | |
| 45 | 50 | assert_equal @result, @client.first_result_after(@project_name, @date) |
| 46 | 51 | end |
| 47 | 52 | |
| 48 | 53 | should 'get last result of project before date' do |
| 49 | - @port.expects(:request).with(:get_last_result_before, request_with_date).returns(result_response) | |
| 54 | + @port.expects(:request).with(:get_last_result_before, @request_with_date).returns(@result_response) | |
| 50 | 55 | assert_equal @result, @client.last_result_before(@project_name, @date) |
| 51 | 56 | end |
| 52 | 57 | |
| 53 | - private | |
| 54 | - | |
| 55 | - def request | |
| 56 | - {:project_name => @project_name} | |
| 57 | - end | |
| 58 | - | |
| 59 | - def request_with_date | |
| 60 | - {:project_name => @project_name, :date => @date} | |
| 61 | - end | |
| 62 | - | |
| 63 | - def flag_response | |
| 64 | - {:has_results => @flag} | |
| 65 | - end | |
| 66 | - | |
| 67 | - def result_response | |
| 68 | - {:project_result => @result.to_hash} | |
| 69 | - end | |
| 70 | - | |
| 71 | 58 | end |
| 72 | 59 | \ No newline at end of file | ... | ... |