-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Vfep 1478 - Adding/updating tests to increase coverage on GIBCT (#1134)
* add tests * refactoring and more tests * fix download_csv to not call externally and stub response correctly * temporary test to check why spec is failing * temporary test to check why spec is failing * temporary test to check why spec is failing * remove puts, add expect for hcm * adjust specs to try to fix sprockets issue. change dashboards controller spec * fix failing test for dashboards controller spec * fix failing test for dashboards controller spec * fix failing test for dashboards controller spec * fix failing test for dashboards controller spec * fix failing test for dashboards controller spec - nocov * fix unzipper spec * fix unzipper spec * fix unzipper spec * fix unzipper spec * fix unzipper spec * fix permissions on tmp * fix permissions on tmp * fix permissions on tmp * fix permissions on tmp * revert Dockerfile * Dockerfile see what filesystem looks lik * Dockerfile see what filesystem looks like * Dockerfile see what filesystem looks like * add comment to Dockerfile fix, add back in tests that were failing due to tmp permissions issue * remove comment from Dockerfile * ls -l in Dockerfile * remove fix for sprockets, revert Dockerfile to original
- Loading branch information
Showing
21 changed files
with
441 additions
and
135 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
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,35 @@ | ||
# frozen_string_literal: true | ||
|
||
# some older versions of Excel spreadsheets don't work well with Roo. | ||
module FileTypeConverters | ||
class XlsToCsv | ||
attr_accessor :xls_file_name, :csv_file_name | ||
|
||
def initialize(xls_file_name, csv_file_name) | ||
@xls_file_name = xls_file_name | ||
@csv_file_name = csv_file_name | ||
end | ||
|
||
def convert_xls_to_csv | ||
book = Spreadsheet.open(@xls_file_name) | ||
sheet = book.worksheet(0) | ||
|
||
CSV.open(@csv_file_name, 'wb') do |csv| | ||
sheet.each do |row| | ||
formatted_row = row.to_a.map do |cell| | ||
cell_value = cell.is_a?(Float) ? format('%.0f', cell) : cell.to_s.strip | ||
if cell_value =~ /^\d+$/ && cell_value.length <= 8 | ||
# Format the number to be exactly eight digits | ||
formatted_number = cell_value.rjust(8, '0') | ||
formatted_number | ||
else | ||
cell_value | ||
end | ||
end | ||
csv << formatted_row | ||
end | ||
end | ||
@csv_file_name | ||
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,65 @@ | ||
# frozen_string_literal: true | ||
|
||
module NoKeyApis | ||
class NoKeyApiDownloader | ||
# the most recent IPED data files are from 2022. This should be checked periodically. | ||
# the most recent Hcm data files are from 2020. This should be checked periodically. | ||
# changes will need to be made to both hashes when these change | ||
API_DOWNLOAD_CONVERSION_NAMES = { | ||
'AccreditationInstituteCampus' => 'tmp/InstitutionCampus.csv', | ||
'Hcm' => 'tmp/hcm.xlsx', | ||
'IpedsHd' => 'tmp/hd2022.csv', | ||
'IpedsIcAy' => 'tmp/ic2022_ay.csv', | ||
'IpedsIcPy' => 'tmp/ic2022_py.csv', | ||
'IpedsIc' => 'tmp/ic2022.csv' | ||
}.freeze | ||
|
||
API_NO_KEY_DOWNLOAD_SOURCES = { | ||
'Accreditation' => [' -X POST', 'https://ope.ed.gov/dapip/api/downloadFiles/accreditationDataFiles'], | ||
'AccreditationAction' => [' -X POST', 'https://ope.ed.gov/dapip/api/downloadFiles/accreditationDataFiles'], | ||
'AccreditationInstituteCampus' => [' -X POST', 'https://ope.ed.gov/dapip/api/downloadFiles/accreditationDataFiles'], | ||
'AccreditationRecord' => [' -X POST', 'https://ope.ed.gov/dapip/api/downloadFiles/accreditationDataFiles'], | ||
'EightKey' => [' -X GET', 'https://www2.ed.gov/documents/military/8-keys-sites.xls'], | ||
'Hcm' => ['', 'https://studentaid.gov/sites/default/files/Schools-on-HCM-December2023.xlsx'], | ||
'IpedsHd' => [' -X GET', 'https://nces.ed.gov/ipeds/datacenter/data/HD2022.zip'], | ||
'IpedsIc' => [' -X GET', 'https://nces.ed.gov/ipeds/datacenter/data/IC2022.zip'], | ||
'IpedsIcAy' => [' -X GET', 'https://nces.ed.gov/ipeds/datacenter/data/IC2022_AY.zip'], | ||
'IpedsIcPy' => [' -X GET', 'https://nces.ed.gov/ipeds/datacenter/data/IC2022_PY.zip'] | ||
}.freeze | ||
|
||
attr_accessor :class_nm, :curl_command | ||
|
||
def initialize(class_nm) | ||
@class_nm = class_nm | ||
rest_command, url = API_NO_KEY_DOWNLOAD_SOURCES[@class_nm] | ||
@curl_command = "curl#{rest_command} #{url} #{h_parm} #{o_parm}#{d_parm}" | ||
end | ||
|
||
def download_csv | ||
_stdout, _stderr, status = Open3.capture3(@curl_command) | ||
|
||
status.success? | ||
end | ||
|
||
private | ||
|
||
def h_parm | ||
return '-H "User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:125.0) Gecko/20100101 Firefox/125.0"' if @class_nm.eql?('Hcm') | ||
|
||
'-H \'Content-Type: application/json\'' | ||
end | ||
|
||
def o_parm | ||
return '-o tmp/hcm.xlsx' if @class_nm.eql?('Hcm') | ||
return '-o tmp/eight_key.xls' if @class_nm.eql?('EightKey') | ||
|
||
'-o tmp/download.zip' | ||
end | ||
|
||
def d_parm | ||
return '' unless @class_nm.start_with?('Accreditation') | ||
|
||
" -d '{\"CSVChecked\":true,\"ExcelChecked\":false}'" | ||
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,26 @@ | ||
# frozen_string_literal: true | ||
|
||
module ZipFileUtils | ||
class Unzipper | ||
attr_accessor :zip_file_name | ||
|
||
# default to tmp/download.zip if nothing's passed in | ||
def initialize(zip_file_name = 'tmp/download.zip') | ||
@zip_file_name = zip_file_name | ||
end | ||
|
||
def unzip_the_file | ||
Zip::File.open(@zip_file_name) do |zip_file| | ||
zip_file.each do |f| | ||
f_path = File.join('tmp', f.name) | ||
FileUtils.mkdir_p(File.dirname(f_path)) unless File.exist?(File.dirname(f_path)) | ||
File.delete(f_path) if File.exist?(f_path) | ||
zip_file.extract(f, f_path) | ||
end | ||
end | ||
true | ||
rescue StandardError => _e | ||
false | ||
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
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
Oops, something went wrong.