<commit_before>require 'sidekiq/testing'
Sidekiq::Testing.fake!

describe FeedEaterFeedWorker do
  before(:each) do
    @feedids = ['f-9q9-caltrain', 'f-9q9-bayarearapidtransit']
    @feeds = @feedids.map {|feedid| Feed.new(onestop_id:feedid)}
  end

  it 'accept single onestop_id' do
    expect {
      FeedEaterFeedWorker.perform_async(@feedids.first)
    }.to change(FeedEaterFeedWorker.jobs, :size).by(1)  
    Sidekiq::Worker.clear_all    
  end
  
  it 'returns if feed matches previous hash' do
    allow(Feed).to receive(:find_by) { @feeds.first }
    allow_any_instance_of(Feed).to receive(:fetch_and_check_for_updated_version) { false }
    FeedEaterFeedWorker.perform_async(@feedids.first)
    FeedEaterFeedWorker.drain
    Sidekiq::Worker.clear_all    
  end
    
  it 'creates FeedImport record' do
    allow(Feed).to receive(:find_by) { @feeds.first }
    allow_any_instance_of(Feed).to receive(:fetch_and_check_for_updated_version) { true }
    allow_any_instance_of(FeedEaterFeedWorker).to receive(:run_python) { false }
    FeedEaterFeedWorker.perform_async(@feedids.first)
    # Check we created a FeedImport record
    expect {
      FeedEaterFeedWorker.drain
    }.to change(FeedImport, :count).by(1)
    Sidekiq::Worker.clear_all
  end

  # TODO: Additional testing
  #   failure cases
  #   log file upload
  
end<commit_msg>Mock out Feed file_sha1_hash; file won't exist.<commit_after>require 'sidekiq/testing'
Sidekiq::Testing.fake!

describe FeedEaterFeedWorker do
  before(:each) do
    @feedids = ['f-9q9-caltrain', 'f-9q9-bayarearapidtransit']
    @feeds = @feedids.map {|feedid| Feed.new(onestop_id:feedid)}
  end

  it 'accept single onestop_id' do
    expect {
      FeedEaterFeedWorker.perform_async(@feedids.first)
    }.to change(FeedEaterFeedWorker.jobs, :size).by(1)  
    Sidekiq::Worker.clear_all    
  end
  
  it 'returns if feed matches previous hash' do
    allow(Feed).to receive(:find_by) { @feeds.first }
    allow_any_instance_of(Feed).to receive(:fetch_and_check_for_updated_version) { false }
    FeedEaterFeedWorker.perform_async(@feedids.first)
    FeedEaterFeedWorker.drain
    Sidekiq::Worker.clear_all    
  end
    
  it 'creates FeedImport record' do
    allow(Figaro.env).to receive(:transitland_feed_data_path) { 'abcd' }
    allow(Feed).to receive(:find_by) { @feeds.first }
    allow_any_instance_of(Feed).to receive(:fetch_and_check_for_updated_version) { true }
    allow_any_instance_of(Feed).to receive(:file_sha1_hash) { 'abcd1234' }
    allow_any_instance_of(FeedEaterFeedWorker).to receive(:run_python) { false }
    FeedEaterFeedWorker.perform_async(@feedids.first)
    # Check we created a FeedImport record
    expect {
      FeedEaterFeedWorker.drain
    }.to change(FeedImport, :count).by(1)
    Sidekiq::Worker.clear_all
  end

  # TODO: Additional testing
  #   failure cases
  #   log file upload
  
end
{'fraction_non_alphanumeric': 0.10562890896455872, 'fraction_numerical': 0.006254343293954135, 'mean_word_length': 4.150268336314848, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5097305', 'n_tokens_mistral': 1038, 'n_tokens_neox': 998, 'n_words': 177}