aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/workers/workbench_import_worker.rb18
-rw-r--r--spec/support/random.rb2
-rw-r--r--spec/workers/workbench_import/workbench_import_with_corrupt_zip_spec.rb (renamed from spec/workers/workbench_import_with_corrupt_zip_spec.rb)0
-rw-r--r--spec/workers/workbench_import/workbench_import_worker_spec.rb (renamed from spec/workers/workbench_import_worker_spec.rb)37
4 files changed, 50 insertions, 7 deletions
diff --git a/app/workers/workbench_import_worker.rb b/app/workers/workbench_import_worker.rb
index b89ba19d8..ef95cad51 100644
--- a/app/workers/workbench_import_worker.rb
+++ b/app/workers/workbench_import_worker.rb
@@ -48,11 +48,19 @@ class WorkbenchImportWorker
raise
end
- def upload_entry_group entry_pair, element_count
- @workbench_import.update( current_step: element_count.succ )
- # status = retry_service.execute(&upload_entry_group_proc(entry_pair))
- eg_name = entry_pair.name
- eg_stream = entry_pair.stream
+ def update_object_state entry, count
+ @workbench_import.update( current_step: count )
+ # TODO: Determine the other attributes of the message, especially how to add the names
+ # of the spurious dirs entry.spurious
+ unless entry.spurious.empty?
+ @workbench_import.messages.create(criticity: :warning, message_key: 'xxx')
+ end
+ end
+ def upload_entry_group entry, element_count
+ update_object_state entry, element_count.succ
+ # status = retry_service.execute(&upload_entry_group_proc(entry))
+ eg_name = entry.name
+ eg_stream = entry.stream
FileUtils.mkdir_p(Rails.root.join('tmp', 'imports'))
diff --git a/spec/support/random.rb b/spec/support/random.rb
index 1d5d62ec8..0ebc2ee5e 100644
--- a/spec/support/random.rb
+++ b/spec/support/random.rb
@@ -25,7 +25,7 @@ module Support
def very_random(veryness=3, joiner: '-')
raise ArgumentError, 'not very random' unless veryness > 1
- 3.times.map{ SecureRandom.uuid }.join(joiner)
+ veryness.times.map{ SecureRandom.uuid }.join(joiner)
end
end
diff --git a/spec/workers/workbench_import_with_corrupt_zip_spec.rb b/spec/workers/workbench_import/workbench_import_with_corrupt_zip_spec.rb
index 344943ad7..344943ad7 100644
--- a/spec/workers/workbench_import_with_corrupt_zip_spec.rb
+++ b/spec/workers/workbench_import/workbench_import_with_corrupt_zip_spec.rb
diff --git a/spec/workers/workbench_import_worker_spec.rb b/spec/workers/workbench_import/workbench_import_worker_spec.rb
index 726dd7f8d..17cb7e16b 100644
--- a/spec/workers/workbench_import_worker_spec.rb
+++ b/spec/workers/workbench_import/workbench_import_worker_spec.rb
@@ -17,11 +17,13 @@ RSpec.describe WorkbenchImportWorker, type: [:worker, :request] do
let( :upload_path ) { api_v1_netex_imports_path(format: :json) }
+ let( :spurious ){ [[], [], []] }
let( :subdirs ) do
entry_count.times.map do |i|
ZipService::Subdir.new(
"subdir #{i}",
- double("subdir #{i}", rewind: 0, read: '')
+ double("subdir #{i}", rewind: 0, read: ''),
+ spurious[i]
)
end
end
@@ -103,8 +105,41 @@ RSpec.describe WorkbenchImportWorker, type: [:worker, :request] do
expect( import ).to receive(:update).with(current_step: 3, status: 'failed')
expect { worker.perform import.id }.to raise_error(StopIteration)
+ end
+ end
+
+ context 'multireferential zipfile with spurious directories' do
+ let( :entry_count ){ 2 }
+ let( :spurious1 ){ [random_string] }
+ let( :spurious2 ){ [random_string, random_string] }
+ let( :spurious ){ [spurious1, spurious2] }
+ let( :messages ){ double('messages') }
+
+ before do
+ allow(import).to receive(:messages).and_return(messages)
+ end
+
+ it 'downloads a zip file, cuts it, and uploads all pieces and adds messages' do
+
+ expect(HTTPService).to receive(:get_resource)
+ .with(host: host, path: path, params: {token: download_token})
+ .and_return( download_zip_response )
+
+ subdirs.each do |subdir|
+ mock_post subdir, post_response_ok
+ end
+
+ expect( import ).to receive(:update).with(total_steps: 2)
+ expect( import ).to receive(:update).with(current_step: 1)
+ expect( messages ).to receive(:create).with(criticity: :warning, message_key: 'xxx')
+ expect( import ).to receive(:update).with(current_step: 2)
+ expect( messages ).to receive(:create).with(criticity: :warning, message_key: 'xxx')
+ expect( import ).to receive(:update).with(ended_at: Time.now)
+
+ worker.perform import.id
end
+
end
def mock_post subdir, response