-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DEV-1019 Move ht_institutions cron job to OTIS (#213)
* DEV-1019 Move ht_institutions cron job to OTIS - Add `InstitutionsExport` class and rake task that invokes it. - Add three config values: - `ht_institutions_file` (currently with a `_test` suffix, see below) - `ht_saml_entity_ids_file` (ditto) - `export_files_directory` - Maintenance: - Annoying name collision fixed: rename `test/lib/tasks/daily_digest_test.rb` to `daily_digest_task_test.rb` - Call `Otis::Application.load_tasks` in test helper to keep rake tests from clobbering each other's coverage
- Loading branch information
Showing
8 changed files
with
114 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
# Used by DailyDigestMailer to report on action items requiring attention from | ||
# administrator. | ||
module Otis | ||
class InstitutionsExport | ||
attr_reader :institutions | ||
def initialize | ||
@institutions = HTInstitution.all.order(:inst_id) | ||
end | ||
|
||
# Returns a String with each line being "inst_id <TAB> name" | ||
def instid_data | ||
@instid_data ||= institutions.map { |i| "#{i.inst_id}\t#{i.name}" }.join("\n") | ||
end | ||
|
||
# Returns a String with each line being "entity_id <TAB> name" | ||
def entityid_data | ||
@entityid_data ||= institutions.map { |i| "#{i.entityID}\t#{i.name}" }.join("\n") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
namespace :otis do | ||
desc <<~DESC | ||
Creates ht_institutions.tsv (inst_id -> name) | ||
and ht_saml_entity_ids.tsv (entityID -> name) | ||
and copies them to Otis.config.export_files_directory | ||
(public/ for the purposes of testing and development, | ||
see config/settings.yml). | ||
DESC | ||
task institutions_export: :environment do | ||
ie = Otis::InstitutionsExport.new | ||
Dir.mktmpdir do |d| | ||
ht_institutions_temp = File.join(d, Otis.config.ht_institutions_file) | ||
ht_saml_entity_ids_temp = File.join(d, Otis.config.ht_saml_entity_ids_file) | ||
File.write(ht_institutions_temp, ie.instid_data) | ||
File.write(ht_saml_entity_ids_temp, ie.entityid_data) | ||
FileUtils.cp(ht_institutions_temp, Otis.config.export_files_directory) | ||
FileUtils.cp(ht_saml_entity_ids_temp, Otis.config.export_files_directory) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
require "test_helper" | ||
|
||
module Otis | ||
class InstitutionsExportTest < ActiveSupport::TestCase | ||
test "create functional InstitutionsExport" do | ||
ie = InstitutionsExport.new | ||
assert_not_nil ie | ||
assert_not_nil ie.institutions | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# frozen_string_literal: true | ||
|
||
require "test_helper" | ||
|
||
module Otis | ||
class InstitutionsExportTaskTest < ActiveSupport::TestCase | ||
def setup | ||
remove_generated_files | ||
5.times do | ||
create(:ht_institution) | ||
end | ||
end | ||
|
||
def teardown | ||
remove_generated_files | ||
end | ||
|
||
def remove_generated_files | ||
if File.exist? ht_institutions_file | ||
FileUtils.rm ht_institutions_file | ||
end | ||
if File.exist? ht_saml_entity_ids_file | ||
FileUtils.rm ht_saml_entity_ids_file | ||
end | ||
end | ||
|
||
def ht_institutions_file | ||
File.join(Otis.config.export_files_directory, Otis.config.ht_institutions_file) | ||
end | ||
|
||
def ht_saml_entity_ids_file | ||
File.join(Otis.config.export_files_directory, Otis.config.ht_saml_entity_ids_file) | ||
end | ||
|
||
test "task writes the expected files" do | ||
Rake::Task["otis:institutions_export"].invoke | ||
assert File.exist? ht_institutions_file | ||
assert File.exist? ht_saml_entity_ids_file | ||
ht_institutions_file_content = File.read(ht_institutions_file) | ||
ht_saml_entity_ids_file_content = File.read(ht_saml_entity_ids_file) | ||
HTInstitution.find_each do |inst| | ||
assert ht_institutions_file_content.include? [inst.inst_id, inst.name].join("\t") | ||
assert ht_saml_entity_ids_file_content.include? [inst.entityID, inst.name].join("\t") | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters