Skip to content

Commit

Permalink
Add test for removing stale xml files
Browse files Browse the repository at this point in the history
Co-authored-by: Jane Sandberg <[email protected]>
  • Loading branch information
Beck-Davis and sandbergja committed Apr 5, 2024
1 parent 32689e4 commit 435d7ef
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
8 changes: 7 additions & 1 deletion app/jobs/scsb_import_full_job.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class ScsbImportFullJob < ApplicationJob
def perform
FileUtils.rm Dir.glob("#{ENV['SCSB_PARTNER_UPDATE_DIRECTORY']}/*.zip")
delete_stale_files

Event.record do |event|
event.dump = created_dump
event.save!
Expand All @@ -18,4 +19,9 @@ def dump_type
def created_dump
Dump.create!(dump_type:)
end

def delete_stale_files
FileUtils.rm Dir.glob("#{ENV['SCSB_PARTNER_UPDATE_DIRECTORY']}/*.zip")
FileUtils.rm Dir.glob("#{ENV['SCSB_PARTNER_UPDATE_DIRECTORY']}/*.xml")
end
end
6 changes: 6 additions & 0 deletions spec/fixtures/scsb_updates/scsb_update_20240108_183400_1.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version='1.0'?>
<collection xmlns='http://www.loc.gov/MARC21/slim'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd">
<record><leader>02152cam a2200493 i 4500</leader><controlfield tag='001'>SCSB-2170814</controlfield><controlfield tag='003'>NNC</controlfield><controlfield tag='005'>20240105113043.0</controlfield><controlfield tag='008'>810220s1976 txu 000 0beng </controlfield><controlfield tag='009'>39998</controlfield><datafield ind1=' ' ind2=' ' tag='010'><subfield code='a'> 76620048 </subfield></datafield><datafield ind1=' ' ind2=' ' tag='035'><subfield code='a'>(OCoLC)ocm03111350</subfield></datafield><datafield ind1=' ' ind2=' ' tag='040'><subfield code='a'>DLC</subfield><subfield code='b'>eng</subfield><subfield code='c'>DLC</subfield><subfield code='d'>OCL</subfield><subfield code='d'>OCLCQ</subfield><subfield code='d'>BAKER</subfield><subfield code='d'>BTCTA</subfield><subfield code='d'>YDXCP</subfield><subfield code='d'>OCLCG</subfield><subfield code='d'>NLE</subfield><subfield code='d'>HEBIS</subfield><subfield code='d'>OCLCO</subfield><subfield code='d'>OCLCQ</subfield><subfield code='d'>OCLCF</subfield><subfield code='d'>OCLCO</subfield><subfield code='d'>FC@</subfield><subfield code='d'>OCLCA</subfield><subfield code='d'>NLC</subfield><subfield code='d'>TYC</subfield><subfield code='d'>OCLCQ</subfield><subfield code='d'>OCL</subfield><subfield code='d'>UKMGB</subfield><subfield code='d'>OCLCQ</subfield><subfield code='d'>OCLCO</subfield><subfield code='d'>OCL</subfield><subfield code='d'>NIU</subfield><subfield code='d'>GZN</subfield><subfield code='d'>OCLCO</subfield><subfield code='d'>OCLCL</subfield></datafield><datafield ind1=' ' ind2=' ' tag='015'><subfield code='a'>781538947</subfield><subfield code='2'>can</subfield></datafield><datafield ind1=' ' ind2=' ' tag='020'><subfield code='a'>087959022X</subfield></datafield><datafield ind1=' ' ind2=' ' tag='020'><subfield code='a'>9780879590222</subfield></datafield><datafield ind1=' ' ind2=' ' tag='035'><subfield code='a'>(OCoLC)3111350</subfield></datafield><datafield ind1='0' ind2='0' tag='050'><subfield code='a'>PR5366</subfield><subfield code='b'>.L38 1976</subfield></datafield><datafield ind1='0' ind2='0' tag='082'><subfield code='a'>822/.9/12</subfield><subfield code='2'>18</subfield></datafield><datafield ind1='1' ind2='4' tag='082'><subfield code='a'>B</subfield></datafield><datafield ind1=' ' ind2=' ' tag='084'><subfield code='a'>cci1icc</subfield><subfield code='2'>lacc</subfield></datafield><datafield ind1=' ' ind2=' ' tag='049'><subfield code='a'>ZCUA</subfield></datafield><datafield ind1='1' ind2=' ' tag='100'><subfield code='a'>Laurence, Dan H.</subfield></datafield><datafield ind1='1' ind2='0' tag='245'><subfield code='a'>Shaw, books, and libraries /</subfield><subfield code='c'>Dan H. Laurence.</subfield></datafield><datafield ind1=' ' ind2=' ' tag='260'><subfield code='a'>[Austin] :</subfield><subfield code='b'>Humanities Research Center, University of Texas at Austin,</subfield><subfield code='c'>©1976.</subfield></datafield><datafield ind1=' ' ind2=' ' tag='300'><subfield code='a'>28 pages ;</subfield><subfield code='c'>23 cm</subfield></datafield><datafield ind1=' ' ind2=' ' tag='336'><subfield code='a'>text</subfield><subfield code='b'>txt</subfield><subfield code='2'>rdacontent</subfield></datafield><datafield ind1=' ' ind2=' ' tag='337'><subfield code='a'>unmediated</subfield><subfield code='b'>n</subfield><subfield code='2'>rdamedia</subfield></datafield><datafield ind1=' ' ind2=' ' tag='338'><subfield code='a'>volume</subfield><subfield code='b'>nc</subfield><subfield code='2'>rdacarrier</subfield></datafield><datafield ind1='1' ind2=' ' tag='490'><subfield code='a'>Bibliographical monograph series ;</subfield><subfield code='v'>no. 9</subfield></datafield><datafield ind1=' ' ind2=' ' tag='500'><subfield code='a'>&quot;Five hundred copies have been printed on Curtis Rag. The type is Intertype Baskerville. Design by William R. Holman&quot;--Colophon.</subfield></datafield><datafield ind1='1' ind2='0' tag='600'><subfield code='a'>Shaw, Bernard,</subfield><subfield code='d'>1856-1950</subfield><subfield code='v'>Books and reading.</subfield></datafield><datafield ind1=' ' ind2='0' tag='650'><subfield code='a'>Dramatists, Irish</subfield><subfield code='y'>20th century</subfield><subfield code='v'>Biography.</subfield></datafield><datafield ind1=' ' ind2='0' tag='650'><subfield code='a'>Dramatists, English</subfield><subfield code='y'>20th century</subfield><subfield code='x'>Biography.</subfield></datafield><datafield ind1='1' ind2='7' tag='600'><subfield code='a'>Shaw, Bernard,</subfield><subfield code='d'>1856-1950</subfield><subfield code='2'>fast</subfield><subfield code='1'>https://id.oclc.org/worldcat/entity/E39PBJfmqrHfjT8qvwDyYWVKVC</subfield><subfield code='0'>(OCoLC)fst00030129</subfield></datafield><datafield ind1=' ' ind2='7' tag='650'><subfield code='a'>Dramatists, English</subfield><subfield code='2'>fast</subfield><subfield code='0'>(OCoLC)fst00897581</subfield></datafield><datafield ind1=' ' ind2='7' tag='650'><subfield code='a'>Dramatists, Irish</subfield><subfield code='2'>fast</subfield><subfield code='0'>(OCoLC)fst00897608</subfield></datafield><datafield ind1=' ' ind2='7' tag='648'><subfield code='a'>1900-1999</subfield><subfield code='2'>fast</subfield></datafield><datafield ind1=' ' ind2=' ' tag='653'><subfield code='a'>American cinema films</subfield><subfield code='a'>Shaw, Bernard</subfield><subfield code='a'>1856-1950</subfield></datafield><datafield ind1=' ' ind2='7' tag='655'><subfield code='a'>Biographies</subfield><subfield code='2'>fast</subfield><subfield code='0'>(OCoLC)fst01919896</subfield></datafield><datafield ind1='1' ind2=' ' tag='700'><subfield code='a'>Holman, William Roger,</subfield><subfield code='e'>designer.</subfield></datafield><datafield ind1='0' ind2='8' tag='776'><subfield code='i'>Online version:</subfield><subfield code='a'>Laurence, Dan H.</subfield><subfield code='t'>Shaw, books, and libraries.</subfield><subfield code='d'>[Austin] : Humanities Research Center, University of Texas at Austin, ©1976</subfield><subfield code='w'>(OCoLC)560755727</subfield></datafield><datafield ind1=' ' ind2='0' tag='830'><subfield code='a'>Bibliographical monograph ;</subfield><subfield code='v'>no. 9.</subfield></datafield><datafield ind1='0' ind2='0' tag='852'><subfield code='h'>PR5366 .L38 1976</subfield><subfield code='0'>2137624</subfield><subfield code='b'>scsbcul</subfield></datafield><datafield ind1=' ' ind2=' ' tag='876'><subfield code='0'>2137624</subfield><subfield code='a'>3304030</subfield><subfield code='j'>Available</subfield><subfield code='p'>CU55398863</subfield><subfield code='t'>1</subfield><subfield code='x'>Shared</subfield><subfield code='z'>CU</subfield><subfield code='l'>RECAP</subfield></datafield></record>
</collection>
7 changes: 4 additions & 3 deletions spec/jobs/scsb_import_full_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,17 @@
FileUtils.cp('spec/fixtures/scsb_updates/CUL_20210429_192300.zip', update_directory_path)
FileUtils.cp('spec/fixtures/scsb_updates/NYPL_20210430_015000.zip', update_directory_path)
FileUtils.cp('spec/fixtures/scsb_updates/HL_20210716_063500.zip', update_directory_path)
FileUtils.cp('spec/fixtures/scsb_updates/scsb_update_20240108_183400_1.xml', update_directory_path)
end

it 'removes stale files' do

expect { described_class.perform_now }.to change { Event.count }.by(1)

expect(File.file?(Rails.root.join("tmp", "specs", "update_directory", 'CUL_20210429_192300.zip'))).to be false
expect(File.file?(Rails.root.join("tmp", "specs", "update_directory", 'NYPL_20210430_015000.zip'))).to be false
expect(File.file?(Rails.root.join("tmp", "specs", "update_directory", 'HL_20210716_063500.zip'))).to be false
expect(File.file?(Rails.root.join("tmp", "specs", "update_directory", 'scsb_update_20240108_183400_1.xml'))).to be false
expect(Dir.exist?(Rails.root.join("tmp", "specs", "update_directory"))).to be true
end
end
end
end

0 comments on commit 435d7ef

Please sign in to comment.