Commit 1023c3a5a7f07cb5ba4f463647396e2a5e855e71
1 parent
0467a627
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
new unit test
Showing
1 changed file
with
32 additions
and
13 deletions
Show diff stats
plugins/virtuoso/test/unit/dspace_harvest_test.rb
| @@ -15,11 +15,11 @@ class DspaceHarvestTest < ActiveSupport::TestCase | @@ -15,11 +15,11 @@ class DspaceHarvestTest < ActiveSupport::TestCase | ||
| 15 | :virtuoso_readonly_username=>"readonly_username", | 15 | :virtuoso_readonly_username=>"readonly_username", |
| 16 | :virtuoso_readonly_password=>"readonly_password", | 16 | :virtuoso_readonly_password=>"readonly_password", |
| 17 | :dspace_servers=>[ | 17 | :dspace_servers=>[ |
| 18 | - {"dspace_uri"=>"http://dspace1.noosfero.com","last_harvest" => 5 }, | 18 | + {"dspace_uri"=>"http://dspace1.noosfero.com","last_harvest" => Time.now.utc }, |
| 19 | {"dspace_uri"=>"http://dspace2.noosfero.com"}, | 19 | {"dspace_uri"=>"http://dspace2.noosfero.com"}, |
| 20 | - {"dspace_uri"=>"http://dspace3.noosfero.com", "last_harvest" => 0}, | 20 | + {"dspace_uri"=>"http://dspace3.noosfero.com", "last_harvest" => Time.now.utc}, |
| 21 | {"dspace_uri"=>"http://dspace4.noosfero.com", "last_harvest" => nil}, | 21 | {"dspace_uri"=>"http://dspace4.noosfero.com", "last_harvest" => nil}, |
| 22 | - {"dspace_uri"=>"http://dspace5.noosfero.com", "last_harvest" => 9}, | 22 | + {"dspace_uri"=>"http://dspace5.noosfero.com", "last_harvest" => Time.now.utc}, |
| 23 | ] | 23 | ] |
| 24 | } | 24 | } |
| 25 | end | 25 | end |
| @@ -36,17 +36,17 @@ class DspaceHarvestTest < ActiveSupport::TestCase | @@ -36,17 +36,17 @@ class DspaceHarvestTest < ActiveSupport::TestCase | ||
| 36 | end | 36 | end |
| 37 | 37 | ||
| 38 | should 'save_harvest_time_settings' do | 38 | should 'save_harvest_time_settings' do |
| 39 | - @settings = Noosfero::Plugin::Settings.new(environment, VirtuosoPlugin, mock_settings) | 39 | + Noosfero::Plugin::Settings.new(environment, VirtuosoPlugin, mock_settings) |
| 40 | harvest = VirtuosoPlugin::DspaceHarvest.new(environment, {"dspace_uri"=>"http://dspace5.noosfero.com", "last_harvest" => 9}) | 40 | harvest = VirtuosoPlugin::DspaceHarvest.new(environment, {"dspace_uri"=>"http://dspace5.noosfero.com", "last_harvest" => 9}) |
| 41 | assert harvest.last_harvest, 9 | 41 | assert harvest.last_harvest, 9 |
| 42 | harvest.save_harvest_time_settings(10) | 42 | harvest.save_harvest_time_settings(10) |
| 43 | - @settings = Noosfero::Plugin::Settings.new(environment.reload, VirtuosoPlugin) | 43 | + Noosfero::Plugin::Settings.new(environment.reload, VirtuosoPlugin) |
| 44 | assert harvest.last_harvest, 10 | 44 | assert harvest.last_harvest, 10 |
| 45 | end | 45 | end |
| 46 | 46 | ||
| 47 | should 'create delayed job when start' do | 47 | should 'create delayed job when start' do |
| 48 | - @settings = Noosfero::Plugin::Settings.new(environment, VirtuosoPlugin, mock_settings) | ||
| 49 | - @settings.save! | 48 | + settings = Noosfero::Plugin::Settings.new(environment, VirtuosoPlugin, mock_settings) |
| 49 | + settings.save! | ||
| 50 | harvest = VirtuosoPlugin::DspaceHarvest.new(environment, {"dspace_uri"=>"http://dspace1.noosfero.com", "last_harvest" => 5}) | 50 | harvest = VirtuosoPlugin::DspaceHarvest.new(environment, {"dspace_uri"=>"http://dspace1.noosfero.com", "last_harvest" => 5}) |
| 51 | assert !harvest.find_job.present? | 51 | assert !harvest.find_job.present? |
| 52 | harvest.start | 52 | harvest.start |
| @@ -54,8 +54,8 @@ class DspaceHarvestTest < ActiveSupport::TestCase | @@ -54,8 +54,8 @@ class DspaceHarvestTest < ActiveSupport::TestCase | ||
| 54 | end | 54 | end |
| 55 | 55 | ||
| 56 | should 'not duplicate harvest job' do | 56 | should 'not duplicate harvest job' do |
| 57 | - @settings = Noosfero::Plugin::Settings.new(environment, VirtuosoPlugin, mock_settings) | ||
| 58 | - @settings.save! | 57 | + settings = Noosfero::Plugin::Settings.new(environment, VirtuosoPlugin, mock_settings) |
| 58 | + settings.save! | ||
| 59 | harvest = VirtuosoPlugin::DspaceHarvest.new(environment, {"dspace_uri"=>"http://dspace1.noosfero.com", "last_harvest" => 5}) | 59 | harvest = VirtuosoPlugin::DspaceHarvest.new(environment, {"dspace_uri"=>"http://dspace1.noosfero.com", "last_harvest" => 5}) |
| 60 | assert_difference "harvest.find_job.count", 1 do | 60 | assert_difference "harvest.find_job.count", 1 do |
| 61 | 5.times { harvest.start } | 61 | 5.times { harvest.start } |
| @@ -67,8 +67,8 @@ class DspaceHarvestTest < ActiveSupport::TestCase | @@ -67,8 +67,8 @@ class DspaceHarvestTest < ActiveSupport::TestCase | ||
| 67 | end | 67 | end |
| 68 | 68 | ||
| 69 | should 'try to harvest all dspaces from start with mock configuration' do | 69 | should 'try to harvest all dspaces from start with mock configuration' do |
| 70 | - @settings = Noosfero::Plugin::Settings.new(environment, VirtuosoPlugin, mock_settings) | ||
| 71 | - @settings.save! | 70 | + settings = Noosfero::Plugin::Settings.new(environment, VirtuosoPlugin, mock_settings) |
| 71 | + settings.save! | ||
| 72 | VirtuosoPlugin::DspaceHarvest.harvest_all(environment, true) | 72 | VirtuosoPlugin::DspaceHarvest.harvest_all(environment, true) |
| 73 | end | 73 | end |
| 74 | 74 | ||
| @@ -77,9 +77,28 @@ class DspaceHarvestTest < ActiveSupport::TestCase | @@ -77,9 +77,28 @@ class DspaceHarvestTest < ActiveSupport::TestCase | ||
| 77 | end | 77 | end |
| 78 | 78 | ||
| 79 | should 'try to harvest all dspaces with mock configuration' do | 79 | should 'try to harvest all dspaces with mock configuration' do |
| 80 | - @settings = Noosfero::Plugin::Settings.new(environment, VirtuosoPlugin, mock_settings) | ||
| 81 | - @settings.save! | 80 | + settings = Noosfero::Plugin::Settings.new(environment, VirtuosoPlugin, mock_settings) |
| 81 | + settings.save! | ||
| 82 | VirtuosoPlugin::DspaceHarvest.harvest_all(environment, false) | 82 | VirtuosoPlugin::DspaceHarvest.harvest_all(environment, false) |
| 83 | end | 83 | end |
| 84 | + | ||
| 85 | + should 'update last_harvest after harvert from start' do | ||
| 86 | + settings = | ||
| 87 | + { :virtuoso_uri=>"http://virtuoso.set_at_etc_hosts", | ||
| 88 | + :virtuoso_username=>"dba", | ||
| 89 | + :virtuoso_password=>"dba", | ||
| 90 | + :virtuoso_readonly_username=>"dba", | ||
| 91 | + :virtuoso_readonly_password=>"dba", | ||
| 92 | + :dspace_servers=>[ | ||
| 93 | + {"dspace_uri"=>"http://dspace.set_at_etc_hosts","last_harvest" => Time.now.utc } | ||
| 94 | + ] | ||
| 95 | + } | ||
| 96 | + @settings = Noosfero::Plugin::Settings.new(environment, VirtuosoPlugin, settings) | ||
| 97 | + harvest = VirtuosoPlugin::DspaceHarvest.new(environment, {"dspace_uri"=>"http://virtuoso.set_at_etc_hosts" }) | ||
| 98 | + puts "last_harvest before #{harvest.last_harvest}" | ||
| 99 | + harvest.run | ||
| 100 | + puts "last_harvest after #{harvest.last_harvest}" | ||
| 101 | + asser | ||
| 102 | + end | ||
| 84 | 103 | ||
| 85 | end | 104 | end |