<commit_before>#
# More deep data structure checks
#

# Check these routes
# ----------------------------------------
#   get "/config" do 
#   get "/objects" do
#   get "/objects/:type" do |type|
#   get "/objects/:type/:name" do |type,name|
#   get "/status/:hostname/services/:service_name" do |hostname,service|
#   get "/status/:hostname/services" do |hostname|
#   get "/status/:hostname" do |hostname|
#   get "/status" do
#   get "/api" do 

require_relative '../app.rb'
require 'rack/test'
require 'pp'


describe Nagira do 

  set :environment, ENV['RACK_ENV'] || :test

  include Rack::Test::Methods
  
  def app
    @app ||= Nagira
  end

  #
  # GET /objects/...
  # ----------------------------------------
  context "/objects" do

    before :all do 
      get "/objects"
      @data = JSON.parse last_response.body

      # make sure these exist
      # Painful.... don't kow how to make it work
      # $allkeys =  (%w{host service contact timeperiod} + @data.keys).uniq
    end

      
    context 'hash key' do
      %w{host service contact timeperiod}.each do |obj|
        it "objects[#{obj}] should exist" do 
          @data[obj].should be_a_kind_of Hash
        end
      end
    end
      
    context 'HTTP route' do
      %w{host service contact timeperiod}.each do |obj|
        it "/objects/#{obj} should respond" do 
          get "/objects/#{obj}.json"
          last_response.should be_ok
          #        JSON.parse(last_response.body).should be_a_kind_of Hash
        end
      end
    end
  end 
  # /objects --------------------
  
end
<commit_msg>more specs for /status and /objects<commit_after>#
# More deep data structure checks
#

# Check these routes
# ----------------------------------------
#   get "/config" do 
#   get "/objects" do
#   get "/objects/:type" do |type|
#   get "/objects/:type/:name" do |type,name|
#   get "/status/:hostname/services/:service_name" do |hostname,service|
#   get "/status/:hostname/services" do |hostname|
#   get "/status/:hostname" do |hostname|
#   get "/status" do
#   get "/api" do 

require_relative '../app.rb'
require 'rack/test'
require 'pp'


describe Nagira do 

  set :environment, ENV['RACK_ENV'] || :test

  include Rack::Test::Methods
  
  def app
    @app ||= Nagira
  end

  #
  # GET /objects/...
  # ----------------------------------------
  context "/objects" do

    before :all do 
      get "/objects"
      @data = JSON.parse last_response.body

      # make sure these exist
      # Painful.... don't kow how to make it work
      # $allkeys =  (%w{host service contact timeperiod} + @data.keys).uniq
    end

      
    context 'hash key' do
      %w{host service contact timeperiod}.each do |obj|
        it "objects[#{obj}] should exist" do 
          @data[obj].should be_a_kind_of Hash
        end
      end
    end
      
      %w{host service contact timeperiod}.each do |obj|
      context "/objects/#{obj}" do
        
        it "should respond to HTTP resuest" do 
          get "/objects/#{obj}.json"
          last_response.should be_ok
        end
        
        it "response to /objects/#{obj} should be Hash" do 
          get "/objects/#{obj}.json"
          JSON.parse(last_response.body).should be_a_kind_of Hash
        end
      end
    end
  end 
  # /objects --------------------
  

  #
  # GET /status
  # -----------------------------

  context '/status' do 
    before :all do 
      get "/status"
      @data = JSON.parse last_response.body

      get "/status/list"
      @list = JSON.parse last_response.body

      get "/status/state"
      @state = JSON.parse last_response.body
    end
    
    context "list of hosts should be the same" do 
      it "full and state" do 
        @data.keys.should == @state.keys
      end

      it "list and state" do 
        @list.should == @state.keys
      end

      it "list and data" do 
        @list.should == @data.keys
      end
    end

  end
end

{'fraction_non_alphanumeric': 0.1729743459486919, 'fraction_numerical': 0.0, 'mean_word_length': 1.7347222222222223, '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': '6690166', 'n_tokens_mistral': 1225, 'n_tokens_neox': 1205, 'n_words': 360}