Commit 53e9b32e810e60efb0bc6cbfe2f251c4d328f2f2
1 parent
c9535c80
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
test fixes
Showing
3 changed files
with
65 additions
and
18 deletions
Show diff stats
plugins/virtuoso/lib/virtuoso_plugin/dspace_harvest.rb
| @@ -55,10 +55,12 @@ class VirtuosoPlugin::DspaceHarvest | @@ -55,10 +55,12 @@ class VirtuosoPlugin::DspaceHarvest | ||
| 55 | 55 | ||
| 56 | def self.harvest_all(environment, from_start) | 56 | def self.harvest_all(environment, from_start) |
| 57 | settings = Noosfero::Plugin::Settings.new(environment, VirtuosoPlugin) | 57 | settings = Noosfero::Plugin::Settings.new(environment, VirtuosoPlugin) |
| 58 | - settings.dspace_servers.each do |k, v| | ||
| 59 | - harvest = VirtuosoPlugin::DspaceHarvest.new(environment, k[:dspace_uri]) | ||
| 60 | - harvest.start(from_start) | ||
| 61 | - end | 58 | + if defined?(settings.dspace_servers) |
| 59 | + settings.dspace_servers.each do |k, v| | ||
| 60 | + harvest = VirtuosoPlugin::DspaceHarvest.new(environment, k[:dspace_uri]) | ||
| 61 | + harvest.start(from_start) | ||
| 62 | + end | ||
| 63 | + end | ||
| 62 | end | 64 | end |
| 63 | 65 | ||
| 64 | def start(from_start = false) | 66 | def start(from_start = false) |
plugins/virtuoso/test/functional/virtuoso_plugin_admin_controller_test.rb
| @@ -3,39 +3,42 @@ require File.dirname(__FILE__) + '/../test_helper' | @@ -3,39 +3,42 @@ require File.dirname(__FILE__) + '/../test_helper' | ||
| 3 | class VirtuosoPluginAdminControllerTest < ActionController::TestCase | 3 | class VirtuosoPluginAdminControllerTest < ActionController::TestCase |
| 4 | 4 | ||
| 5 | attr_reader :environment | 5 | attr_reader :environment |
| 6 | - | 6 | + |
| 7 | def setup | 7 | def setup |
| 8 | @environment = Environment.default | 8 | @environment = Environment.default |
| 9 | @profile = create_user('profile').person | 9 | @profile = create_user('profile').person |
| 10 | login_as(@profile.identifier) | 10 | login_as(@profile.identifier) |
| 11 | post :index, :settings => mock_settings | 11 | post :index, :settings => mock_settings |
| 12 | end | 12 | end |
| 13 | - | 13 | + |
| 14 | def mock_settings | 14 | def mock_settings |
| 15 | - { | ||
| 16 | - :virtuoso_uri=>"http://virtuoso.noosfero.com", | ||
| 17 | - :virtuoso_username=>"username", :virtuoso_password=>"password", | ||
| 18 | - :virtuoso_readonly_username=>"username", | ||
| 19 | - :virtuoso_readonly_password=>"password", | ||
| 20 | - :dspace_servers=>[ | ||
| 21 | - {"dspace_uri"=>"http://dspace1.noosfero.com"}, | ||
| 22 | - {"dspace_uri"=>"http://dspace2.noosfero.com"}, | ||
| 23 | - {"dspace_uri"=>"http://dspace3.noosfero.com"} | ||
| 24 | - ] | 15 | + { :virtuoso_uri=>"http://virtuoso.noosfero.com", |
| 16 | + :virtuoso_username=>"username", | ||
| 17 | + :virtuoso_password=>"password", | ||
| 18 | + :virtuoso_readonly_username=>"readonly_username", | ||
| 19 | + :virtuoso_readonly_password=>"readonly_password", | ||
| 20 | + :dspace_servers=>[ | ||
| 21 | + {"dspace_uri"=>"http://dspace1.noosfero.com"}, | ||
| 22 | + {"dspace_uri"=>"http://dspace2.noosfero.com"}, | ||
| 23 | + {"dspace_uri"=>"http://dspace3.noosfero.com"} | ||
| 24 | + ] | ||
| 25 | } | 25 | } |
| 26 | - end | 26 | + end |
| 27 | 27 | ||
| 28 | should 'save virtuoso plugin settings' do | 28 | should 'save virtuoso plugin settings' do |
| 29 | @settings = Noosfero::Plugin::Settings.new(environment.reload, VirtuosoPlugin) | 29 | @settings = Noosfero::Plugin::Settings.new(environment.reload, VirtuosoPlugin) |
| 30 | assert_equal 'http://virtuoso.noosfero.com', @settings.settings[:virtuoso_uri] | 30 | assert_equal 'http://virtuoso.noosfero.com', @settings.settings[:virtuoso_uri] |
| 31 | assert_equal 'username', @settings.settings[:virtuoso_username] | 31 | assert_equal 'username', @settings.settings[:virtuoso_username] |
| 32 | assert_equal 'password', @settings.settings[:virtuoso_password] | 32 | assert_equal 'password', @settings.settings[:virtuoso_password] |
| 33 | + assert_equal 'readonly_username', @settings.settings[:virtuoso_readonly_username] | ||
| 34 | + assert_equal 'readonly_password', @settings.settings[:virtuoso_readonly_password] | ||
| 33 | assert_equal 'http://dspace1.noosfero.com', @settings.settings[:dspace_servers][0][:dspace_uri] | 35 | assert_equal 'http://dspace1.noosfero.com', @settings.settings[:dspace_servers][0][:dspace_uri] |
| 34 | assert_equal 'http://dspace2.noosfero.com', @settings.settings[:dspace_servers][1][:dspace_uri] | 36 | assert_equal 'http://dspace2.noosfero.com', @settings.settings[:dspace_servers][1][:dspace_uri] |
| 35 | assert_equal 'http://dspace3.noosfero.com', @settings.settings[:dspace_servers][2][:dspace_uri] | 37 | assert_equal 'http://dspace3.noosfero.com', @settings.settings[:dspace_servers][2][:dspace_uri] |
| 36 | assert_redirected_to :action => 'index' | 38 | assert_redirected_to :action => 'index' |
| 37 | end | 39 | end |
| 38 | 40 | ||
| 41 | + | ||
| 39 | should 'redirect to index after save' do | 42 | should 'redirect to index after save' do |
| 40 | post :index, :settings => mock_settings | 43 | post :index, :settings => mock_settings |
| 41 | assert_redirected_to :action => 'index' | 44 | assert_redirected_to :action => 'index' |
| @@ -55,4 +58,8 @@ class VirtuosoPluginAdminControllerTest < ActionController::TestCase | @@ -55,4 +58,8 @@ class VirtuosoPluginAdminControllerTest < ActionController::TestCase | ||
| 55 | assert_equal nil, harvest.settings.last_harvest | 58 | assert_equal nil, harvest.settings.last_harvest |
| 56 | end | 59 | end |
| 57 | 60 | ||
| 58 | -end | 61 | + should 'force harvest_all from start' do |
| 62 | + get :force_harvest, :from_start => true | ||
| 63 | + end | ||
| 64 | + | ||
| 65 | +end | ||
| 59 | \ No newline at end of file | 66 | \ No newline at end of file |
plugins/virtuoso/test/unit/dspace_harvest_test.rb
| @@ -7,6 +7,20 @@ class DspaceHarvestTest < ActiveSupport::TestCase | @@ -7,6 +7,20 @@ class DspaceHarvestTest < ActiveSupport::TestCase | ||
| 7 | end | 7 | end |
| 8 | 8 | ||
| 9 | attr_reader :environment | 9 | attr_reader :environment |
| 10 | + | ||
| 11 | + def mock_settings | ||
| 12 | + { :virtuoso_uri=>"http://virtuoso.noosfero.com", | ||
| 13 | + :virtuoso_username=>"username", | ||
| 14 | + :virtuoso_password=>"password", | ||
| 15 | + :virtuoso_readonly_username=>"readonly_username", | ||
| 16 | + :virtuoso_readonly_password=>"readonly_password", | ||
| 17 | + :dspace_servers=>[ | ||
| 18 | + {"dspace_uri"=>"http://dspace1.noosfero.com"}, | ||
| 19 | + {"dspace_uri"=>"http://dspace2.noosfero.com"}, | ||
| 20 | + {"dspace_uri"=>"http://dspace3.noosfero.com"} | ||
| 21 | + ] | ||
| 22 | + } | ||
| 23 | + end | ||
| 10 | 24 | ||
| 11 | should 'create delayed job when start' do | 25 | should 'create delayed job when start' do |
| 12 | harvest = VirtuosoPlugin::DspaceHarvest.new(environment) | 26 | harvest = VirtuosoPlugin::DspaceHarvest.new(environment) |
| @@ -21,5 +35,29 @@ class DspaceHarvestTest < ActiveSupport::TestCase | @@ -21,5 +35,29 @@ class DspaceHarvestTest < ActiveSupport::TestCase | ||
| 21 | 5.times { harvest.start } | 35 | 5.times { harvest.start } |
| 22 | end | 36 | end |
| 23 | end | 37 | end |
| 38 | + | ||
| 39 | + should 'harvest all dspaces from start' do | ||
| 40 | + VirtuosoPlugin::DspaceHarvest.harvest_all(environment, true) | ||
| 41 | + end | ||
| 42 | + | ||
| 43 | + should 'try to harvest all dspaces from start without any setting' do | ||
| 44 | + VirtuosoPlugin::DspaceHarvest.harvest_all(environment, true) | ||
| 45 | + end | ||
| 46 | + | ||
| 47 | + should 'try to harvest all dspaces from start with mock configuration' do | ||
| 48 | + @settings = Noosfero::Plugin::Settings.new(environment, VirtuosoPlugin, mock_settings) | ||
| 49 | + @settings.save! | ||
| 50 | + VirtuosoPlugin::DspaceHarvest.harvest_all(environment, true) | ||
| 51 | + end | ||
| 52 | + | ||
| 53 | + should 'try to harvest all dspaces without any setting' do | ||
| 54 | + VirtuosoPlugin::DspaceHarvest.harvest_all(environment, false) | ||
| 55 | + end | ||
| 56 | + | ||
| 57 | + should 'try to harvest all dspaces with mock configuration' do | ||
| 58 | + @settings = Noosfero::Plugin::Settings.new(environment, VirtuosoPlugin, mock_settings) | ||
| 59 | + @settings.save! | ||
| 60 | + VirtuosoPlugin::DspaceHarvest.harvest_all(environment, false) | ||
| 61 | + end | ||
| 24 | 62 | ||
| 25 | end | 63 | end |