<commit_before>shared_context "job_body_util" do
  let(:default_payload) {
    {
      "command" => "sleep 1",
      "nodes" => ["DONKEY"],
      "quorum" => 1,
      "run_timeout" => 3600
    }
  }

  let(:default_result) {
    {
      "command" => "sleep 1",
      "nodes" => {"unavailable" => ["DONKEY"]},
      "id" => /^[0-9a-f]{32}$/,
      "run_timeout" => 3600,
      "status" => "quorum_failed"
    }
  }

  def make_payload(payload, overwrite_variables)
    result = payload
    overwrite_variables.each do |variable,value|
      if value == :delete
        result.delete(variable)
      else
        if (result[variable])
          result[variable] = value
        end
      end
    end
    return result
  end

  def self.fails_with_value(variable, value, pending = false)
    if (pending)
      it "with #{variable} = #{value} it reports 400", :validation, :pending do
      end
    else
      it "with #{variable} = #{value} it reports 400", :validation do
        response = post(api_url("/pushy/jobs"), admin_user,
                        :payload => make_payload(default_payload, variable => value))
      end
    end
  end

  def self.succeeds_with_value(variable, value, expected_value = nil, pending = false)
    expected_value ||= value
    if (pending)
      it "with #{variable} = #{value} it succeeds", :pending do
      end
    else
      it "with #{variable} = #{value} it succeeds" do
        response = post(api_url("/pushy/jobs"), admin_user,
                        :payload => make_payload(default_payload, variable => value))
        list = JSON.parse(response.body)
        new_job_uri = list["uri"]
        response.should look_like({
                                    :status => 201,
                                    :body_exact => {
                                      "uri" => new_job_uri
                                    }})
        response = get(new_job_uri, admin_user)
        response.
          should look_like({
                             :status => 200,
                             :body_exact => make_payload(default_result,
                                                         variable => expected_value) })
      end
    end
  end
end<commit_msg>Fixed delete issue for test<commit_after>shared_context "job_body_util" do
  let(:default_payload) {
    {
      "command" => "sleep 1",
      "nodes" => ["DONKEY"],
      "quorum" => 1,
      "run_timeout" => 3600
    }
  }

  let(:default_result) {
    {
      "command" => "sleep 1",
      "nodes" => {"unavailable" => ["DONKEY"]},
      "id" => /^[0-9a-f]{32}$/,
      "run_timeout" => 3600,
      "status" => "quorum_failed"
    }
  }

  def make_payload(payload, overwrite_variables)
    result = payload
    if (overwrite_variables[:skip_delete])
      overwrite_variables.delete(:skip_delete)
      skip_delete = true
    end
    overwrite_variables.each do |variable,value|
      if value == :delete
        if (!skip_delete)
          result.delete(variable)
        end
      else
        if (result[variable])
          result[variable] = value
        end
      end
    end
    return result
  end

  def self.fails_with_value(variable, value, pending = false)
    if (pending)
      it "with #{variable} = #{value} it reports 400", :validation, :pending do
      end
    else
      it "with #{variable} = #{value} it reports 400", :validation do
        response = post(api_url("/pushy/jobs"), admin_user,
                        :payload => make_payload(default_payload, variable => value))
      end
    end
  end

  def self.succeeds_with_value(variable, value, expected_value = nil, pending = false)
    expected_value ||= value
    if (pending)
      it "with #{variable} = #{value} it succeeds", :pending do
      end
    else
      it "with #{variable} = #{value} it succeeds" do
        response = post(api_url("/pushy/jobs"), admin_user,
                        :payload => make_payload(default_payload, variable => value))
        list = JSON.parse(response.body)
        new_job_uri = list["uri"]
        response.should look_like({
                                    :status => 201,
                                    :body_exact => {
                                      "uri" => new_job_uri
                                    }})
        response = get(new_job_uri, admin_user)
        response.
          should look_like({
                             :status => 200,
                             :body_exact => make_payload(default_result,
                                                         variable => expected_value,
                                                         :skip_delete => true) })
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.11683041435284067, 'fraction_numerical': 0.011533532678342588, 'mean_word_length': 1.6577752553916005, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1055897', 'n_tokens_mistral': 1376, 'n_tokens_neox': 1291, 'n_words': 312}