Commit 9de1db8c74145426d9edd6f401c0c54ee8d2a641
1 parent
a8dd4325
Exists in
staging
and in
4 other branches
fix saving last_harvest to settings
Showing
2 changed files
with
31 additions
and
7 deletions
Show diff stats
plugins/virtuoso/lib/virtuoso_plugin/dspace_harvest.rb
... | ... | @@ -65,10 +65,9 @@ class VirtuosoPlugin::DspaceHarvest |
65 | 65 | end |
66 | 66 | |
67 | 67 | def save_harvest_time_settings(harvest_time) |
68 | - dspace_settings = {"dspace_uri" => dspace_uri, "last_harvest" => last_harvest} | |
69 | 68 | settings.dspace_servers.each do |s| |
70 | 69 | if s["dspace_uri"] == dspace_uri |
71 | - settings.dspace_servers.delete(dspace_settings) | |
70 | + settings.dspace_servers.delete(s) | |
72 | 71 | end |
73 | 72 | end |
74 | 73 | @dspace_settings = {"dspace_uri" => dspace_uri, "last_harvest" => harvest_time} | ... | ... |
plugins/virtuoso/test/unit/dspace_harvest_test.rb
... | ... | @@ -40,8 +40,12 @@ class DspaceHarvestTest < ActiveSupport::TestCase |
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 | - Noosfero::Plugin::Settings.new(environment.reload, VirtuosoPlugin) | |
44 | 43 | assert harvest.last_harvest, 10 |
44 | + settings = Noosfero::Plugin::Settings.new(environment, VirtuosoPlugin) | |
45 | + dspace_server = settings.dspace_servers[4] | |
46 | + settings = Noosfero::Plugin::Settings.new(environment.reload, VirtuosoPlugin) | |
47 | + dspace_server = settings.dspace_servers[4] | |
48 | + assert_equal 10, dspace_server["last_harvest"] | |
45 | 49 | end |
46 | 50 | |
47 | 51 | should 'create delayed job when start' do |
... | ... | @@ -81,8 +85,9 @@ class DspaceHarvestTest < ActiveSupport::TestCase |
81 | 85 | settings.save! |
82 | 86 | VirtuosoPlugin::DspaceHarvest.harvest_all(environment, false) |
83 | 87 | end |
84 | - | |
88 | + | |
85 | 89 | should 'update last_harvest after harvert' do |
90 | + time = Time.now.utc | |
86 | 91 | settings = |
87 | 92 | { :virtuoso_uri=>"http://virtuoso", |
88 | 93 | :virtuoso_username=>"username", |
... | ... | @@ -90,16 +95,36 @@ class DspaceHarvestTest < ActiveSupport::TestCase |
90 | 95 | :virtuoso_readonly_username=>"username", |
91 | 96 | :virtuoso_readonly_password=>"password", |
92 | 97 | :dspace_servers=>[ |
93 | - {"dspace_uri"=>"http://dspace","last_harvest" => Time.now.utc } | |
98 | + {"dspace_uri"=>"http://dspace","last_harvest" => time } | |
94 | 99 | ] |
95 | - } | |
100 | + } | |
96 | 101 | @settings = Noosfero::Plugin::Settings.new(environment, VirtuosoPlugin, settings) |
97 | - harvest = VirtuosoPlugin::DspaceHarvest.new(environment, {"dspace_uri"=>"http://virtuoso" }) | |
102 | + harvest = VirtuosoPlugin::DspaceHarvest.new(environment, {"dspace_uri"=>"http://dspace" }) | |
98 | 103 | dspace_client = mock |
99 | 104 | harvest.expects(:dspace_client).returns(dspace_client) |
100 | 105 | dspace_client.expects(:list_records).returns([]) |
101 | 106 | harvest.run |
102 | 107 | assert_not_equal harvest.last_harvest, nil |
108 | + Noosfero::Plugin::Settings.new(environment.reload, VirtuosoPlugin) | |
109 | + assert_not_equal harvest.last_harvest, nil | |
110 | + assert_not_equal harvest.last_harvest, Time.now.utc | |
103 | 111 | end |
104 | 112 | |
113 | + should 'list records' do | |
114 | + settings = | |
115 | + { :virtuoso_uri=>"http://hom.virtuoso.participa.br", | |
116 | + :virtuoso_username=>"dba", | |
117 | + :virtuoso_password=>"dba", | |
118 | + :virtuoso_readonly_username=>"dba", | |
119 | + :virtuoso_readonly_password=>"dba", | |
120 | + :dspace_servers=>[ | |
121 | + {"dspace_uri"=>"http://hom.dspace.participa.br"} | |
122 | + ] | |
123 | + } | |
124 | + settings = Noosfero::Plugin::Settings.new(environment, VirtuosoPlugin, settings) | |
125 | + harvest = VirtuosoPlugin::DspaceHarvest.new(environment, {"dspace_uri"=>"http://hom.dspace.participa.br"}) | |
126 | + params = harvest.last_harvest ? {:from => harvest.last_harvest.utc} : {} | |
127 | + records = harvest.dspace_client.list_records(params) | |
128 | + assert_not_equal records.count, 0 | |
129 | + end | |
105 | 130 | end |
106 | 131 | \ No newline at end of file | ... | ... |