summaryrefslogtreecommitdiff
path: root/test/compound.rb
blob: cacd292c514f488e4a0d85a6f179244becde4ac6 (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
require_relative "setup.rb"

$compound_uri = "#{$host}/compound"
$compound = ["InChI=1S/C6H6/c1-2-4-6-5-3-1/h1-6H"]

class CompoundTest < MiniTest::Test

  def test_00_get_inchi
    res = RestClientWrapper.get File.join($compound_uri, $compound[0]), {}, {:accept => 'chemical/x-inchi'}
    assert_equal res.code, 200
    assert_equal res, "InChI=1S/C6H6/c1-2-4-6-5-3-1/h1-6H"
  end

  def test_01_get_smiles
    res = RestClientWrapper.get File.join($compound_uri, $compound[0]), {}, {:accept => "chemical/x-daylight-smiles"}
    assert_equal res.code, 200
    assert_equal res, "c1ccccc1"
  end

  def test_02_get_sdf
    res = RestClientWrapper.get File.join($compound_uri, $compound[0]), {}, {:accept => "chemical/x-mdl-sdfile"}
    assert_equal res.code, 200
    assert res.include?("  6 12  1  0  0  0  0\nM  END\n$$$")
  end

  def test_03_get_png
    res = RestClientWrapper.get File.join($compound_uri, $compound[0]), {}, {:accept => "image/png"}
    assert_equal res.code, 200
    assert_equal "image/png", res.headers[:content_type]
  end

  def test_04_get_svg
    res = RestClientWrapper.get File.join($compound_uri, $compound[0]), {}, {:accept => "image/svg+xml"}
    assert_equal res.code, 200
    assert res.include?("<svg version=")
  end

  def test_05_get_json
    res = RestClientWrapper.get File.join($compound_uri, $compound[0]), {}, {:accept => "application/json"}
    assert_equal res.code, 200
    js = JSON.parse res
    assert_equal js["chemblid"], "CHEMBL277500"
    assert_equal js["names"].first, "BENZENE"
    assert_equal js["names"][6], "71-43-2"
  end

  def test_06_get_names
    res = RestClientWrapper.get File.join($compound_uri, $compound[0]), {}, {:accept => "text/plain"}
    assert_equal res.code, 200
    assert res.include?("Benzene")
    assert res.include?("401765_ALDRICH")
  end

end