summaryrefslogtreecommitdiff
path: root/lib/test_util.rb
diff options
context:
space:
mode:
authorMartin Gütlein <martin.guetlein@gmail.com>2009-11-13 11:51:21 +0100
committerMartin Gütlein <martin.guetlein@gmail.com>2009-11-13 11:51:21 +0100
commit41e5d1e6160115356c54d2907552b9a943126ae1 (patch)
tree8b011c251ecfbd69d2435d07b91e275f56fc1682 /lib/test_util.rb
parent14904ee55e85000b97fa7b735c22a82529fbdf10 (diff)
merged reports into this rep
Diffstat (limited to 'lib/test_util.rb')
-rw-r--r--lib/test_util.rb51
1 files changed, 51 insertions, 0 deletions
diff --git a/lib/test_util.rb b/lib/test_util.rb
new file mode 100644
index 0000000..2916b55
--- /dev/null
+++ b/lib/test_util.rb
@@ -0,0 +1,51 @@
+
+require 'test/unit'
+
+module Lib
+ # test utitily, to be included rack unit tests
+ module TestUtil
+
+ # updloads a dataset
+ def upload_data(ws, name, file)
+ data_uri = RestClient.post ws, :name => name
+ puts "created dataset "+data_uri.to_s
+ add_resource(data_uri)
+
+ assert data_uri==ext("curl -X PUT -F 'file=@"+file.path+";type=text/csv' -F compound_format=smiles "+data_uri+"/import",nil)
+ return data_uri
+ end
+
+ # adds a resource to delete it later on
+ def add_resource(res)
+ @to_delete = [] unless @to_delete
+ @to_delete.push(res)
+ end
+
+ # deletes all resources
+ def delete_resources
+ if @to_delete
+ @to_delete.each do |d|
+ puts "deleting "+d.to_s
+ if d.to_s =~ /^http.*/
+ ext("curl -X DELETE "+d.to_s)
+ else
+ delete d.to_s
+ end
+ end
+ end
+ end
+
+ # execute an external program like curl
+ def ext(call, indent=" ")
+ response = ""
+ IO.popen(call.to_s+" 2> /dev/null") do |f|
+ while line = f.gets
+ response += indent.to_s+line
+ end
+ end
+ assert $?==0
+ return response
+ end
+
+ end
+end