summaryrefslogtreecommitdiff
path: root/test/toxbank-investigation-xls.rb
blob: 492d990a6aa00c85df522d661c6e9ea209bfb78c (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
62
require File.join(File.expand_path(File.dirname(__FILE__)),"setup.rb")

class UploadTest < Test::Unit::TestCase

  def setup
    @tmpdir = File.join(File.dirname(__FILE__),"tmp")
    FileUtils.mkdir_p @tmpdir
    FileUtils.rm_r Dir[File.join @tmpdir, '*']
  end

  def test_01_invalid_xls_upload 
    # upload
    file = File.join File.dirname(__FILE__), "data/toxbank-investigation/invalid/isa_TB_ACCUTOX.xls"
    response = `curl -Lk -X POST -i -F file="@#{file};type=application/vnd.ms-excel" -H "subjectid:#{@@subjectid}" #{$toxbank_investigation[:uri]}`.chomp
    assert_match /202/, response
    uri = response.split("\n")[-1]
    t = OpenTox::Task.new(uri)
    t.wait
    assert_match t.hasStatus, "Error"
  end
  
  def test_02_valid_xls_upload
    # upload
    file = File.join File.dirname(__FILE__), "data/toxbank-investigation/valid/isa_TB_BII.xls"
    response = `curl -Lk -X POST -i -F file="@#{file};type=application/vnd.ms-excel" -H "subjectid:#{@@subjectid}" #{$toxbank_investigation[:uri]}`.chomp
    assert_match /202/, response
    uri = response.split("\n")[-1]
    t = OpenTox::Task.new(uri)
    t.wait
    assert_equal true, t.completed?
    uri = t.resultURI
    
    # get zip file
    zip = File.join @tmpdir,"tmp.zip"
    `curl -Lk -H "Accept:application/zip" -H "subjectid:#{@@subjectid}" #{uri} > #{zip}`
    `unzip -o #{zip} -d #{@tmpdir}`
    [
      "i_Investigation.txt",
      "s_BII-S-1.txt",
      "s_BII-S-2.txt",
      "a_metabolome.txt",
      "a_microarray.txt",
      "a_proteome.txt",
      "a_transcriptome.txt",
    ].each{|f| assert_equal true, File.exists?(File.join(@tmpdir,f)) }

    # get isatab files
    `curl -Lk -H "Accept:text/uri-list" -H "subjectid:#{@@subjectid}" #{uri}`.split("\n").each do |u|
      if u.match(/txt$/)
        response = `curl -Lk -i -H Accept:text/tab-separated-values -H "subjectid:#{@@subjectid}" #{u}`
        assert_match /200/, response
      end
    end

    # delete
    response = `curl -Lk -i -X DELETE -H "subjectid:#{@@subjectid}" #{uri}`
    assert_match /200/, response
    response = `curl -Lk -i -H "Accept:text/uri-list" -H "subjectid:#{@@subjectid}" #{uri}`
    assert_match /404/, response
  end
  
end