Browse Source

Scheme and Location import rake tasks

Rename our fixture import folder
pull/727/head
Stéphane Meny 3 years ago
parent
commit
e8e161732a
No known key found for this signature in database
GPG Key ID: 9D0AFEA988527923
  1. 24
      app/services/imports/scheme_import_service.rb
  2. 24
      app/services/imports/scheme_location_import_service.rb
  3. 6
      lib/tasks/data_import.rake
  4. 0
      spec/fixtures/imports/case_logs/00d2343e-d5fa-4c89-8400-ec3854b0f2b4.xml
  5. 0
      spec/fixtures/imports/case_logs/0ead17cb-1668-442d-898c-0d52879ff592.xml
  6. 0
      spec/fixtures/imports/case_logs/166fc004-392e-47a8-acb8-1c018734882b.xml
  7. 0
      spec/fixtures/imports/case_logs/5ybz29dj-l33t-k1l0-hj86-n4k4ma77xkcd.xml
  8. 0
      spec/fixtures/imports/case_logs/893ufj2s-lq77-42m4-rty6-ej09gh585uy1.xml
  9. 0
      spec/fixtures/imports/data_protection_confirmations/7c5bd5fb549c09a2c55d7cb90d7ba84927e64618.xml
  10. 0
      spec/fixtures/imports/organisation_rent_periods/ebd22326d33e389e9f1bfd546979d2c05f9e68d6.xml
  11. 0
      spec/fixtures/imports/organisations/7c5bd5fb549c09a2c55d7cb90d7ba84927e64618.xml
  12. 0
      spec/fixtures/imports/users/10c887710550844e2551b3e0fb88dc9b4a8a642b.xml
  13. 0
      spec/fixtures/imports/users/9ed81a262215a1634f0809effa683e38924d8bcb.xml
  14. 0
      spec/fixtures/imports/users/b7829b1a5dfb68bb1e01c08445830c0add40907c.xml
  15. 0
      spec/fixtures/imports/users/d4729b1a5dfb68bb1e01c08445830c0add40907c.xml
  16. 0
      spec/fixtures/imports/users/d6717836154cd9a58f9e2f1d3077e3ab81e07613.xml
  17. 0
      spec/fixtures/imports/users/fc7625a02b24ae16162aa63ae7cb33feeec0c373.xml
  18. 46
      spec/lib/tasks/data_import_spec.rb
  19. 2
      spec/lib/tasks/date_import_field_spec.rb
  20. 2
      spec/services/imports/case_logs_field_import_service_spec.rb
  21. 2
      spec/services/imports/case_logs_import_service_spec.rb
  22. 2
      spec/services/imports/data_protection_confirmation_import_service_spec.rb
  23. 2
      spec/services/imports/organisation_import_service_spec.rb
  24. 2
      spec/services/imports/organisation_rent_period_import_service_spec.rb
  25. 2
      spec/services/imports/user_import_service_spec.rb

24
app/services/imports/scheme_import_service.rb

@ -0,0 +1,24 @@
module Imports
class SchemeImportService < ImportService
def create_schemes(folder)
import_from(folder, :create_scheme)
end
private
def create_scheme(xml_document)
old_visible_id = scheme_field_value(xml_document, "visible-id")
Scheme.create!(
old_id: scheme_field_value(xml_document, "id"),
old_visible_id:
)
rescue ActiveRecord::RecordNotUnique
name = scheme_field_value(xml_document, "name")
@logger.warn("Scheme #{name} is already present with old visible ID #{old_visible_id}, skipping.")
end
def scheme_field_value(xml_document, field)
field_value(xml_document, "mgmtgroup", field)
end
end
end

24
app/services/imports/scheme_location_import_service.rb

@ -0,0 +1,24 @@
module Imports
class SchemeLocationImportService < ImportService
def create_scheme_locations(folder)
import_from(folder, :create_scheme_location)
end
private
def create_scheme_location(xml_document)
old_visible_id = location_field_value(xml_document, "visible-id")
Scheme.create!(
old_id: location_field_value(xml_document, "id"),
old_visible_id:
)
rescue ActiveRecord::RecordNotUnique
name = location_field_value(xml_document, "name")
@logger.warn("Location #{name} is already present with old visible ID #{old_visible_id}, skipping.")
end
def location_field_value(xml_document, field)
field_value(xml_document, "scheme", field)
end
end
end

6
lib/tasks/data_import.rake

@ -10,12 +10,14 @@ namespace :core do
case type
when "organisation"
Imports::OrganisationImportService.new(storage_service).create_organisations(path)
when "scheme"
Imports::SchemeImportService.new(storage_service).create_schemes(path)
when "scheme-location"
Imports::SchemeLocationImportService.new(storage_service).create_scheme_locations(path)
when "user"
Imports::UserImportService.new(storage_service).create_users(path)
when "data-protection-confirmation"
Imports::DataProtectionConfirmationImportService.new(storage_service).create_data_protection_confirmations(path)
when "organisation-las"
Imports::OrganisationLaImportService.new(storage_service).create_organisation_las(path)
when "organisation-rent-periods"
Imports::OrganisationRentPeriodImportService.new(storage_service).create_organisation_rent_periods(path)
when "case-logs"

0
spec/fixtures/softwire_imports/case_logs/00d2343e-d5fa-4c89-8400-ec3854b0f2b4.xml → spec/fixtures/imports/case_logs/00d2343e-d5fa-4c89-8400-ec3854b0f2b4.xml vendored

0
spec/fixtures/softwire_imports/case_logs/0ead17cb-1668-442d-898c-0d52879ff592.xml → spec/fixtures/imports/case_logs/0ead17cb-1668-442d-898c-0d52879ff592.xml vendored

0
spec/fixtures/softwire_imports/case_logs/166fc004-392e-47a8-acb8-1c018734882b.xml → spec/fixtures/imports/case_logs/166fc004-392e-47a8-acb8-1c018734882b.xml vendored

0
spec/fixtures/softwire_imports/case_logs/5ybz29dj-l33t-k1l0-hj86-n4k4ma77xkcd.xml → spec/fixtures/imports/case_logs/5ybz29dj-l33t-k1l0-hj86-n4k4ma77xkcd.xml vendored

0
spec/fixtures/softwire_imports/case_logs/893ufj2s-lq77-42m4-rty6-ej09gh585uy1.xml → spec/fixtures/imports/case_logs/893ufj2s-lq77-42m4-rty6-ej09gh585uy1.xml vendored

0
spec/fixtures/softwire_imports/data_protection_confirmations/7c5bd5fb549c09a2c55d7cb90d7ba84927e64618.xml → spec/fixtures/imports/data_protection_confirmations/7c5bd5fb549c09a2c55d7cb90d7ba84927e64618.xml vendored

0
spec/fixtures/softwire_imports/organisation_rent_periods/ebd22326d33e389e9f1bfd546979d2c05f9e68d6.xml → spec/fixtures/imports/organisation_rent_periods/ebd22326d33e389e9f1bfd546979d2c05f9e68d6.xml vendored

0
spec/fixtures/softwire_imports/organisations/7c5bd5fb549c09a2c55d7cb90d7ba84927e64618.xml → spec/fixtures/imports/organisations/7c5bd5fb549c09a2c55d7cb90d7ba84927e64618.xml vendored

0
spec/fixtures/softwire_imports/users/10c887710550844e2551b3e0fb88dc9b4a8a642b.xml → spec/fixtures/imports/users/10c887710550844e2551b3e0fb88dc9b4a8a642b.xml vendored

0
spec/fixtures/softwire_imports/users/9ed81a262215a1634f0809effa683e38924d8bcb.xml → spec/fixtures/imports/users/9ed81a262215a1634f0809effa683e38924d8bcb.xml vendored

0
spec/fixtures/softwire_imports/users/b7829b1a5dfb68bb1e01c08445830c0add40907c.xml → spec/fixtures/imports/users/b7829b1a5dfb68bb1e01c08445830c0add40907c.xml vendored

0
spec/fixtures/softwire_imports/users/d4729b1a5dfb68bb1e01c08445830c0add40907c.xml → spec/fixtures/imports/users/d4729b1a5dfb68bb1e01c08445830c0add40907c.xml vendored

0
spec/fixtures/softwire_imports/users/d6717836154cd9a58f9e2f1d3077e3ab81e07613.xml → spec/fixtures/imports/users/d6717836154cd9a58f9e2f1d3077e3ab81e07613.xml vendored

0
spec/fixtures/softwire_imports/users/fc7625a02b24ae16162aa63ae7cb33feeec0c373.xml → spec/fixtures/imports/users/fc7625a02b24ae16162aa63ae7cb33feeec0c373.xml vendored

46
spec/lib/tasks/data_import_spec.rb

@ -22,7 +22,7 @@ describe "rake core:data_import", type: :task do
context "when importing organisation data" do
let(:type) { "organisation" }
let(:import_service) { instance_double(Imports::OrganisationImportService) }
let(:fixture_path) { "spec/fixtures/softwire_imports/organisations" }
let(:fixture_path) { "spec/fixtures/imports/organisations" }
before do
allow(Imports::OrganisationImportService).to receive(:new).and_return(import_service)
@ -40,7 +40,7 @@ describe "rake core:data_import", type: :task do
context "when importing user data" do
let(:type) { "user" }
let(:import_service) { instance_double(Imports::UserImportService) }
let(:fixture_path) { "spec/fixtures/softwire_imports/users" }
let(:fixture_path) { "spec/fixtures/imports/users" }
before do
allow(Imports::UserImportService).to receive(:new).and_return(import_service)
@ -58,7 +58,7 @@ describe "rake core:data_import", type: :task do
context "when importing data protection confirmation data" do
let(:type) { "data-protection-confirmation" }
let(:import_service) { instance_double(Imports::DataProtectionConfirmationImportService) }
let(:fixture_path) { "spec/fixtures/softwire_imports/data_protection_confirmations" }
let(:fixture_path) { "spec/fixtures/imports/data_protection_confirmations" }
before do
allow(Imports::DataProtectionConfirmationImportService).to receive(:new).and_return(import_service)
@ -76,7 +76,7 @@ describe "rake core:data_import", type: :task do
context "when importing organisation rent period data" do
let(:type) { "organisation-rent-periods" }
let(:import_service) { instance_double(Imports::OrganisationRentPeriodImportService) }
let(:fixture_path) { "spec/fixtures/softwire_imports/organisation_rent_periods" }
let(:fixture_path) { "spec/fixtures/imports/organisation_rent_periods" }
before do
allow(Imports::OrganisationRentPeriodImportService).to receive(:new).and_return(import_service)
@ -94,7 +94,7 @@ describe "rake core:data_import", type: :task do
context "when importing case logs" do
let(:type) { "case-logs" }
let(:import_service) { instance_double(Imports::CaseLogsImportService) }
let(:fixture_path) { "spec/fixtures/softwire_imports/case_logs" }
let(:fixture_path) { "spec/fixtures/imports/case_logs" }
before do
allow(Imports::CaseLogsImportService).to receive(:new).and_return(import_service)
@ -109,6 +109,42 @@ describe "rake core:data_import", type: :task do
end
end
context "when importing scheme data" do
let(:type) { "scheme" }
let(:import_service) { instance_double(Imports::SchemeImportService) }
let(:fixture_path) { "spec/fixtures/imports/schemes" }
before do
allow(Imports::SchemeImportService).to receive(:new).and_return(import_service)
end
it "creates a scheme from the given XML file" do
expect(StorageService).to receive(:new).with(paas_config_service, instance_name)
expect(Imports::SchemeImportService).to receive(:new).with(storage_service)
expect(import_service).to receive(:create_schemes).with(fixture_path)
task.invoke(type, fixture_path)
end
end
context "when importing scheme location data" do
let(:type) { "scheme-location" }
let(:import_service) { instance_double(Imports::SchemeLocationImportService) }
let(:fixture_path) { "spec/fixtures/imports/organisations" }
before do
allow(Imports::SchemeLocationImportService).to receive(:new).and_return(import_service)
end
it "creates a scheme location from the given XML file" do
expect(StorageService).to receive(:new).with(paas_config_service, instance_name)
expect(Imports::SchemeLocationImportService).to receive(:new).with(storage_service)
expect(import_service).to receive(:create_scheme_locations).with(fixture_path)
task.invoke(type, fixture_path)
end
end
it "raises an exception if no parameters are provided" do
expect { task.invoke }.to raise_error(/Usage/)
end

2
spec/lib/tasks/date_import_field_spec.rb

@ -21,7 +21,7 @@ describe "rake core:data_import_field", type: :task do
context "when importing a case log field" do
let(:import_service) { instance_double(Imports::CaseLogsFieldImportService) }
let(:fixture_path) { "spec/fixtures/softwire_imports/case_logs" }
let(:fixture_path) { "spec/fixtures/imports/case_logs" }
before do
allow(Imports::CaseLogsFieldImportService).to receive(:new).and_return(import_service)

2
spec/services/imports/case_logs_field_import_service_spec.rb

@ -7,7 +7,7 @@ RSpec.describe Imports::CaseLogsFieldImportService do
let(:logger) { instance_double(ActiveSupport::Logger) }
let(:real_2021_2022_form) { Form.new("config/forms/2021_2022.json", "2021_2022") }
let(:fixture_directory) { "spec/fixtures/softwire_imports/case_logs" }
let(:fixture_directory) { "spec/fixtures/imports/case_logs" }
let(:case_log_id) { "0ead17cb-1668-442d-898c-0d52879ff592" }
let(:case_log_file) { open_file(fixture_directory, case_log_id) }

2
spec/services/imports/case_logs_import_service_spec.rb

@ -8,7 +8,7 @@ RSpec.describe Imports::CaseLogsImportService do
let(:real_2021_2022_form) { Form.new("config/forms/2021_2022.json", "2021_2022") }
let(:real_2022_2023_form) { Form.new("config/forms/2022_2023.json", "2022_2023") }
let(:fixture_directory) { "spec/fixtures/softwire_imports/case_logs" }
let(:fixture_directory) { "spec/fixtures/imports/case_logs" }
let(:organisation) { FactoryBot.create(:organisation, old_visible_id: "1", provider_type: "PRP") }
def open_file(directory, filename)

2
spec/services/imports/data_protection_confirmation_import_service_spec.rb

@ -1,7 +1,7 @@
require "rails_helper"
RSpec.describe Imports::DataProtectionConfirmationImportService do
let(:fixture_directory) { "spec/fixtures/softwire_imports/data_protection_confirmations" }
let(:fixture_directory) { "spec/fixtures/imports/data_protection_confirmations" }
let(:old_org_id) { "7c5bd5fb549c09a2c55d7cb90d7ba84927e64618" }
let(:old_id) { old_org_id }
let(:import_file) { File.open("#{fixture_directory}/#{old_id}.xml") }

2
spec/services/imports/organisation_import_service_spec.rb

@ -5,7 +5,7 @@ RSpec.describe Imports::OrganisationImportService do
let(:logger) { instance_double(Rails::Rack::Logger) }
let(:folder_name) { "organisations" }
let(:filenames) { %w[my_folder/my_file1.xml my_folder/my_file2.xml] }
let(:fixture_directory) { "spec/fixtures/softwire_imports/organisations" }
let(:fixture_directory) { "spec/fixtures/imports/organisations" }
def create_organisation_file(fixture_directory, visible_id, name = nil)
file = File.open("#{fixture_directory}/7c5bd5fb549c09a2c55d7cb90d7ba84927e64618.xml")

2
spec/services/imports/organisation_rent_period_import_service_spec.rb

@ -1,7 +1,7 @@
require "rails_helper"
RSpec.describe Imports::OrganisationRentPeriodImportService do
let(:fixture_directory) { "spec/fixtures/softwire_imports/organisation_rent_periods" }
let(:fixture_directory) { "spec/fixtures/imports/organisation_rent_periods" }
let(:old_org_id) { "44026acc7ed5c29516b26f2a5deb639e5e37966d" }
let(:old_id) { "ebd22326d33e389e9f1bfd546979d2c05f9e68d6" }
let(:import_file) { File.open("#{fixture_directory}/#{old_id}.xml") }

2
spec/services/imports/user_import_service_spec.rb

@ -1,7 +1,7 @@
require "rails_helper"
RSpec.describe Imports::UserImportService do
let(:fixture_directory) { "spec/fixtures/softwire_imports/users" }
let(:fixture_directory) { "spec/fixtures/imports/users" }
let(:old_user_id) { "fc7625a02b24ae16162aa63ae7cb33feeec0c373" }
let(:old_org_id) { "7c5bd5fb549c09a2c55d7cb90d7ba84927e64618" }
let(:user_file) { File.open("#{fixture_directory}/#{old_user_id}.xml") }

Loading…
Cancel
Save