<commit_before>require 'test_helper'

class NetworksControllerTest < ActionController::TestCase
  
  test "should get index" do
    get :index
    assert_response :success
    assert_not_nil assigns(:networks)
  end

  test "should get new" do
    get :new
    assert_response :success
  end

  test "should get search page" do
    get :search, :network => { :name => 'Barabsi'}
    assert_response :success
    assert_template "search"
  end
  
  test "should get view page" do
    get :view, :id => networks(:barabasi).id
    assert_response :success
    assert_template "view"
  end
  
  test "should get network" do
    get :get_network, :id => networks(:barabasi).id
    assert_response :success
    assert_template "applet_small"
    assert_not_nil assigns(:network)
  end
  
  test "should raise error on get network with invalid id" do
    get :get_network, :id => 0
    assert_response :success
    assert_template ""
    # TODO test error (before define an error template)
  end

  test "should create network" do
    network_hash = { 
      :name => 'pippo',
      :description => 'blablabla'
    }
    assert_difference('Network.count') do
      post :create, :network => network_hash,
        :edgefile => { :uploaded_data => fixture_file_upload("../storage/edgefiles/barabasi.txt", "text/plain") },
        :configfile => { :uploaded_data => fixture_file_upload("../storage/configfiles/barabasi.xml", "text/xml") },
        :annotationfile => { :uploaded_data => fixture_file_upload("../storage/annotationfiles/hprdmap.txt", "text/plain") }
    end

    newbie = Network.find(:all, :order => "id DESC", :limit =>  1)[0] 
    expected = Network.new(network_hash);
    assert_equal(newbie.name, expected.name)
    assert_equal(newbie.description, expected.description)
    assert_not_nil newbie.edgefile
    assert_not_nil newbie.configfile
    assert_not_nil newbie.annotationfile
    assert_equal("barabasi.txt", newbie.edgefile.filename)
    assert_equal("text/plain", newbie.edgefile.content_type)
    assert_equal("barabasi.xml", newbie.configfile.filename)
    assert_equal("text/xml", newbie.configfile.content_type)
    assert_equal("hprdmap.txt", newbie.annotationfile.filename)
    assert_equal("text/plain", newbie.annotationfile.content_type)<commit_msg>Fied a bug in test<commit_after>require 'test_helper'

class NetworksControllerTest < ActionController::TestCase
  
  test "should get index" do
    get :index
    assert_response :success
    assert_not_nil assigns(:networks)
  end

  test "should get new" do
    get :new
    assert_response :success
  end

  test "should get search page" do
    get :search, :network => { :name => 'Barabsi'}
    assert_response :success
    assert_template "search"
  end
  
  test "should get view page" do
    get :view, :id => networks(:barabasi).id
    assert_response :success
    assert_template "view"
  end
  
  test "should get network" do
    get :get_network, :id => networks(:barabasi).id
    assert_response :success
    assert_template "applet_small"
    assert_not_nil assigns(:network)
  end
  
  test "should raise error on get network with invalid id" do
    get :get_network, :id => 0
    assert_redirected_to networks_path
  end

  test "should create network" do
    network_hash = { 
      :name => 'pippo',
      :description => 'blablabla'
    }
    assert_difference('Network.count') do
      post :create, :network => network_hash,
        :edgefile => { :uploaded_data => fixture_file_upload("../storage/edgefiles/barabasi.txt", "text/plain") },
        :configfile => { :uploaded_data => fixture_file_upload("../storage/configfiles/barabasi.xml", "text/xml") },
        :annotationfile => { :uploaded_data => fixture_file_upload("../storage/annotationfiles/hprdmap.txt", "text/plain") }
    end

    newbie = Network.find(:all, :order => "id DESC", :limit =>  1)[0] 
    expected = Network.new(network_hash);
    assert_equal(newbie.name, expected.name)
    assert_equal(newbie.description, expected.description)
    assert_not_nil newbie.edgefile
    assert_not_nil newbie.configfile
    assert_not_nil newbie.annotationfile
    assert_equal("barabasi.txt", newbie.edgefile.filename)
    assert_equal("text/plain", newbie.edgefile.content_type)
    assert_equal("barabasi.xml", newbie.configfile.filename)
    assert_equal("text/xml", newbie.configfile.content_type)
    assert_equal("hprdmap.txt", newbie.annotationfile.filename)
    assert_equal("text/plain", newbie.annotationfile.content_type)
{'fraction_non_alphanumeric': 0.11353517364203028, 'fraction_numerical': 0.0013357079252003562, 'mean_word_length': 3.810492505353319, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, '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': '7139984', 'n_tokens_mistral': 1419, 'n_tokens_neox': 1391, 'n_words': 316}