Commit 53e9b32e810e60efb0bc6cbfe2f251c4d328f2f2

Authored by Evandro Jr
1 parent c9535c80

test fixes

plugins/virtuoso/lib/virtuoso_plugin/dspace_harvest.rb
... ... @@ -55,10 +55,12 @@ class VirtuosoPlugin::DspaceHarvest
55 55  
56 56 def self.harvest_all(environment, from_start)
57 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 64 end
63 65  
64 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 3 class VirtuosoPluginAdminControllerTest < ActionController::TestCase
4 4  
5 5 attr_reader :environment
6   -
  6 +
7 7 def setup
8 8 @environment = Environment.default
9 9 @profile = create_user('profile').person
10 10 login_as(@profile.identifier)
11 11 post :index, :settings => mock_settings
12 12 end
13   -
  13 +
14 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 28 should 'save virtuoso plugin settings' do
29 29 @settings = Noosfero::Plugin::Settings.new(environment.reload, VirtuosoPlugin)
30 30 assert_equal 'http://virtuoso.noosfero.com', @settings.settings[:virtuoso_uri]
31 31 assert_equal 'username', @settings.settings[:virtuoso_username]
32 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 35 assert_equal 'http://dspace1.noosfero.com', @settings.settings[:dspace_servers][0][:dspace_uri]
34 36 assert_equal 'http://dspace2.noosfero.com', @settings.settings[:dspace_servers][1][:dspace_uri]
35 37 assert_equal 'http://dspace3.noosfero.com', @settings.settings[:dspace_servers][2][:dspace_uri]
36 38 assert_redirected_to :action => 'index'
37 39 end
38 40  
  41 +
39 42 should 'redirect to index after save' do
40 43 post :index, :settings => mock_settings
41 44 assert_redirected_to :action => 'index'
... ... @@ -55,4 +58,8 @@ class VirtuosoPluginAdminControllerTest &lt; ActionController::TestCase
55 58 assert_equal nil, harvest.settings.last_harvest
56 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 66 \ No newline at end of file
... ...
plugins/virtuoso/test/unit/dspace_harvest_test.rb
... ... @@ -7,6 +7,20 @@ class DspaceHarvestTest &lt; ActiveSupport::TestCase
7 7 end
8 8  
9 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 25 should 'create delayed job when start' do
12 26 harvest = VirtuosoPlugin::DspaceHarvest.new(environment)
... ... @@ -21,5 +35,29 @@ class DspaceHarvestTest &lt; ActiveSupport::TestCase
21 35 5.times { harvest.start }
22 36 end
23 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 63 end
... ...