Commit 1023c3a5a7f07cb5ba4f463647396e2a5e855e71

Authored by Evandro Jr
1 parent 0467a627

new unit test

plugins/virtuoso/test/unit/dspace_harvest_test.rb
... ... @@ -15,11 +15,11 @@ class DspaceHarvestTest < ActiveSupport::TestCase
15 15 :virtuoso_readonly_username=>"readonly_username",
16 16 :virtuoso_readonly_password=>"readonly_password",
17 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 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 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 25 end
... ... @@ -36,17 +36,17 @@ class DspaceHarvestTest < ActiveSupport::TestCase
36 36 end
37 37  
38 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 40 harvest = VirtuosoPlugin::DspaceHarvest.new(environment, {"dspace_uri"=>"http://dspace5.noosfero.com", "last_harvest" => 9})
41 41 assert harvest.last_harvest, 9
42 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 44 assert harvest.last_harvest, 10
45 45 end
46 46  
47 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 50 harvest = VirtuosoPlugin::DspaceHarvest.new(environment, {"dspace_uri"=>"http://dspace1.noosfero.com", "last_harvest" => 5})
51 51 assert !harvest.find_job.present?
52 52 harvest.start
... ... @@ -54,8 +54,8 @@ class DspaceHarvestTest < ActiveSupport::TestCase
54 54 end
55 55  
56 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 59 harvest = VirtuosoPlugin::DspaceHarvest.new(environment, {"dspace_uri"=>"http://dspace1.noosfero.com", "last_harvest" => 5})
60 60 assert_difference "harvest.find_job.count", 1 do
61 61 5.times { harvest.start }
... ... @@ -67,8 +67,8 @@ class DspaceHarvestTest < ActiveSupport::TestCase
67 67 end
68 68  
69 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 72 VirtuosoPlugin::DspaceHarvest.harvest_all(environment, true)
73 73 end
74 74  
... ... @@ -77,9 +77,28 @@ class DspaceHarvestTest < ActiveSupport::TestCase
77 77 end
78 78  
79 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 82 VirtuosoPlugin::DspaceHarvest.harvest_all(environment, false)
83 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 104 end
... ...