From 7f23294c582a34492cf907d8528af7c472798ac2 Mon Sep 17 00:00:00 2001 From: taitus Date: Thu, 11 Apr 2024 14:21:14 +0200 Subject: [PATCH] WIP: #run_machine_learning_scripts --- spec/models/machine_learning_spec.rb | 74 ++++++++++++++-------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/spec/models/machine_learning_spec.rb b/spec/models/machine_learning_spec.rb index c1360909106..173300eb1ee 100644 --- a/spec/models/machine_learning_spec.rb +++ b/spec/models/machine_learning_spec.rb @@ -377,43 +377,43 @@ 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