summaryrefslogtreecommitdiff
path: root/test/aop-curl.rb
blob: 57627965b5572b425fc0b5f720593a54377e0f80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require_relative "./setup.rb"

begin
  puts "Service URI is: #{$aop[:uri]}"
rescue
  puts "Configuration Error: $aop[:uri] is not defined in: " + File.join(ENV["HOME"],".opentox","config","test.rb")
  exit
end


class JsonTest < MiniTest::Test
  
  # check response from service with header application/json
  # @note expect code 200
  def test_01_response
    response = `curl -i -H accept:application/json #{$aop[:uri]}`
    assert_match /200/, response
  end

  # check response for json data with header application/json
  # @note expect code 200
  def test_02
    response = `curl -i -H accept:application/json #{$aop[:uri]}/cid/1234/assays/active/1234-assays-active.json`
    assert_match /200/, response
  end

  # check json data for content
  def test_03
    response = `curl -H accept:application/json #{$aop[:uri]}/cid/1234/prediction/assays/active/1234-assays-active.json`.chomp
    result = JSON[response]
    #puts result
    aid = result.collect{|x| x['AID']}
    assert_includes aid.to_s, "42314"
    p_active = result.collect{|x| x['p_active']}
    assert_includes p_active.to_s, "0.9701425001453319"
    p_inactive = result.collect{|x| x['p_inactive']}
    assert_includes p_inactive.to_s, "0.029857499854668124"
    assay_name = result.collect{|x| x['Assay Name']}
    assert_includes assay_name.to_s, "Ability to inhibit [3H]-PK 11195 binding to peripheral-type benzodiazepine receptor(PBR) in rat cerebral cortex homogenate."
  end

end

class CsvTest < MiniTest::Test

  # check response for csv data with header text/csv
  # @note expect code 200
  def test_01
    response = `curl -i -H accept:text/csv #{$aop[:uri]}/cid/1234/assays/active/1234-assays-active.csv`
    assert_match /200/, response
  end
  
  # check csv data for content
  def test_02
    response = `curl -H accept:text/csv #{$aop[:uri]}/cid/1234/prediction/assays/active/1234-assays-active.csv`.chomp
    result = CSV.parse(response, {:col_sep => ";"})
    assert_equal result[0].size, 4
  end

end