From 398c6231d1e46a697f5e485fc9b19db4800d19b2 Mon Sep 17 00:00:00 2001 From: taitus Date: Thu, 11 Apr 2024 11:33:52 +0200 Subject: [PATCH] WIP: #run_machine_learning_scripts --- spec/models/machine_learning_spec.rb | 76 ++++++++++++++-------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/spec/models/machine_learning_spec.rb b/spec/models/machine_learning_spec.rb index 2ae37871c32..b58c5703faf 100644 --- a/spec/models/machine_learning_spec.rb +++ b/spec/models/machine_learning_spec.rb @@ -377,44 +377,44 @@ def full_sanitizer(string) end end - # describe "#run_machine_learning_scripts" do - # it "returns true if python script executed correctly" do - # machine_learning = MachineLearning.new(job) - # - # command = "cd #{MachineLearning::SCRIPTS_FOLDER} && python script.py 2>&1" - # expect(machine_learning).to receive(:`).with(command) do - # Process.waitpid Process.fork { exit 0 } - # end - # - # expect(Mailer).not_to receive(:machine_learning_error) - # - # expect(machine_learning.send(:run_machine_learning_scripts)).to be true - # - # job.reload - # expect(job.finished_at).not_to be_present - # expect(job.error).not_to be_present - # end - # - # it "returns false if python script errored" do - # machine_learning = MachineLearning.new(job) - # - # command = "cd #{MachineLearning::SCRIPTS_FOLDER} && python script.py 2>&1" - # expect(machine_learning).to receive(:`).with(command) do - # Process.waitpid Process.fork { abort "error message" } - # end - # - # mailer = double("mailer") - # expect(mailer).to receive(:deliver_later) - # expect(Mailer).to receive(:machine_learning_error).and_return mailer - # - # expect(machine_learning.send(:run_machine_learning_scripts)).to be false - # - # job.reload - # expect(job.finished_at).to be_present - # expect(job.error).not_to eq "error message" - # end - # end - # + describe "#run_machine_learning_scripts" do + it "returns true if python script executed correctly" do + machine_learning = MachineLearning.new(job) + + command = "cd #{MachineLearning::SCRIPTS_FOLDER} && python script.py 2>&1" + expect(machine_learning).to receive(:`).with(command) do + Process.waitpid Process.fork { exit 0 } + end + + expect(Mailer).not_to receive(:machine_learning_error) + + expect(machine_learning.send(:run_machine_learning_scripts)).to be true + + job.reload + expect(job.finished_at).not_to be_present + expect(job.error).not_to be_present + end + + it "returns false if python script errored" do + machine_learning = MachineLearning.new(job) + + command = "cd #{MachineLearning::SCRIPTS_FOLDER} && python script.py 2>&1" + expect(machine_learning).to receive(:`).with(command) do + Process.waitpid Process.fork { abort "error message" } + end + + mailer = double("mailer") + expect(mailer).to receive(:deliver_later) + expect(Mailer).to receive(:machine_learning_error).and_return mailer + + expect(machine_learning.send(:run_machine_learning_scripts)).to be false + + job.reload + expect(job.finished_at).to be_present + expect(job.error).not_to eq "error message" + end + end + # describe "#import_ml_proposals_comments_summary" do # it "feeds the database using content from the JSON file generated by the machine learning script" do # machine_learning = MachineLearning.new(job)