opentox-client 0.0.1pre → 0.0.2pre

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,107 @@
1
+ require 'test/unit'
2
+ $LOAD_PATH << File.join(File.dirname(__FILE__),'..','lib')
3
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','lib','opentox-client.rb'))
4
+ TEST_URI = "http://only_a_test/test/" + rand(1000000).to_s
5
+ AA ||= "https://opensso.in-silico.ch"
6
+ AA_USER = "guest"
7
+ AA_PASS = "guest"
8
+ @@subjectid = OpenTox::Authorization.authenticate(AA_USER,AA_PASS)
9
+
10
+ class TestOpenToxAuthorizationBasic < Test::Unit::TestCase
11
+
12
+ def test_01_server
13
+ assert_equal(AA, OpenTox::Authorization.server)
14
+ end
15
+
16
+ def test_02_get_token
17
+ assert_not_nil @@subjectid
18
+ end
19
+
20
+ def test_03_is_valid_token
21
+ tok = login
22
+ assert_not_nil tok
23
+ assert OpenTox::Authorization.is_token_valid(tok)
24
+ logout(tok)
25
+ end
26
+
27
+ def test_04_logout
28
+ tok = login
29
+ assert logout(tok)
30
+ assert_equal false, OpenTox::Authorization.is_token_valid(tok)
31
+ end
32
+
33
+ def test_05_list_policies
34
+ assert_kind_of Array, OpenTox::Authorization.list_policies(@@subjectid)
35
+ end
36
+
37
+ end
38
+
39
+ class TestOpenToxAuthorizationLDAP < Test::Unit::TestCase
40
+
41
+ def test_01_list_user_groups
42
+ assert_kind_of Array, OpenTox::Authorization.list_user_groups(AA_USER, @@subjectid)
43
+ end
44
+
45
+ def test_02_get_user
46
+ assert_equal AA_USER, OpenTox::Authorization.get_user(@@subjectid)
47
+ end
48
+
49
+ end
50
+
51
+ class TestOpenToxAuthorizationLDAP < Test::Unit::TestCase
52
+
53
+ def test_01_create_check_delete_default_policies
54
+ res = OpenTox::Authorization.send_policy(TEST_URI, @@subjectid)
55
+ assert res
56
+ assert OpenTox::Authorization.uri_has_policy(TEST_URI, @@subjectid)
57
+ policies = OpenTox::Authorization.list_uri_policies(TEST_URI, @@subjectid)
58
+ assert_kind_of Array, policies
59
+ policies.each do |policy|
60
+ assert OpenTox::Authorization.delete_policy(policy, @@subjectid)
61
+ end
62
+ assert_equal false, OpenTox::Authorization.uri_has_policy(TEST_URI, @@subjectid)
63
+ end
64
+
65
+ def test_02_check_policy_rules
66
+ tok_anonymous = OpenTox::Authorization.authenticate("anonymous","anonymous")
67
+ assert_not_nil tok_anonymous
68
+ res = OpenTox::Authorization.send_policy(TEST_URI, @@subjectid)
69
+ assert res
70
+ assert OpenTox::Authorization.uri_has_policy(TEST_URI, @@subjectid)
71
+ owner_rights = {"GET" => true, "POST" => true, "PUT" => true, "DELETE" => true}
72
+ groupmember_rights = {"GET" => true, "POST" => nil, "PUT" => nil, "DELETE" => nil}
73
+ owner_rights.each do |request, right|
74
+ assert_equal right, OpenTox::Authorization.authorize(TEST_URI, request, @@subjectid), "#{AA_USER} requests #{request} to #{TEST_URI}"
75
+ end
76
+ groupmember_rights.each do |request, r|
77
+ assert_equal r, OpenTox::Authorization.authorize(TEST_URI, request, tok_anonymous), "anonymous requests #{request} to #{TEST_URI}"
78
+ end
79
+
80
+ policies = OpenTox::Authorization.list_uri_policies(TEST_URI, @@subjectid)
81
+ assert_kind_of Array, policies
82
+ policies.each do |policy|
83
+ assert OpenTox::Authorization.delete_policy(policy, @@subjectid)
84
+ end
85
+ logout(tok_anonymous)
86
+ end
87
+
88
+ def test_03_check_different_uris
89
+ res = OpenTox::Authorization.send_policy(TEST_URI, @@subjectid)
90
+ assert OpenTox::Authorization.uri_has_policy(TEST_URI, @@subjectid)
91
+ assert OpenTox::Authorization.authorize(TEST_URI, "GET", @@subjectid), "GET request"
92
+ policies = OpenTox::Authorization.list_uri_policies(TEST_URI, @@subjectid)
93
+ policies.each do |policy|
94
+ assert OpenTox::Authorization.delete_policy(policy, @@subjectid)
95
+ end
96
+
97
+ end
98
+ end
99
+
100
+
101
+ def logout (token)
102
+ OpenTox::Authorization.logout(token)
103
+ end
104
+
105
+ def login
106
+ OpenTox::Authorization.authenticate(AA_USER,AA_PASS)
107
+ end
data/test/dataset.rb CHANGED
@@ -1,44 +1,79 @@
1
1
  require 'test/unit'
2
2
  $LOAD_PATH << File.join(File.dirname(__FILE__),'..','lib')
3
3
  require File.join File.dirname(__FILE__),'..','lib','opentox-client.rb'
4
+ DATASET = "http://ot-dev.in-silico.ch/dataset"
5
+ AA ||= "https://opensso.in-silico.ch"
6
+ AA_USER = "guest"
7
+ AA_PASS = "guest"
8
+ @@subjectid = OpenTox::Authorization.authenticate(AA_USER,AA_PASS)
9
+
10
+ DATA_DIR = File.join(File.dirname(__FILE__),"data")
11
+ # TODO: add subjectids
12
+
4
13
 
5
14
  class DatasetTest < Test::Unit::TestCase
6
15
 
7
16
  def test_all
8
- datasets = OpenTox::Dataset.all "http://ot-dev.in-silico.ch/dataset"
17
+ puts @@subjectid
18
+ datasets = OpenTox::Dataset.all(DATASET, @@subjectid)
9
19
  assert_equal OpenTox::Dataset, datasets.first.class
10
20
  end
11
21
 
12
22
  def test_create_empty
13
- service_uri = "http://ot-dev.in-silico.ch/dataset"
14
- d = OpenTox::Dataset.create service_uri
23
+ d = OpenTox::Dataset.create(DATASET, @@subjectid)
15
24
  assert_equal OpenTox::Dataset, d.class
16
- assert_match /#{service_uri}/, d.uri.to_s
25
+ assert_match /#{DATASET}/, d.uri.to_s
17
26
  d.delete
18
27
  end
19
28
 
20
29
  def test_create_from_file
21
- d = OpenTox::Dataset.from_file "http://ot-dev.in-silico.ch/dataset", File.join(File.dirname(__FILE__),"data","EPAFHM.mini.csv")
30
+ d = OpenTox::Dataset.from_file DATASET, File.join(DATA_DIR,"EPAFHM.mini.csv"), @@subjectid
22
31
  assert_equal OpenTox::Dataset, d.class
32
+ assert_equal d.uri, d[RDF::XSD.anyURI]
33
+ assert_equal "EPAFHM.mini", d.metadata[RDF::URI("http://purl.org/dc/elements/1.1/title")].first.to_s # DC.title is http://purl.org/dc/terms/title
34
+ assert_equal "EPAFHM.mini", d[RDF::URI("http://purl.org/dc/elements/1.1/title")]
23
35
  d.delete
24
36
  assert_raise OpenTox::NotFoundError do
25
37
  d.get
26
38
  end
27
39
  end
28
40
 
41
+ def test_from_yaml
42
+ @dataset = OpenTox::Dataset.from_file DATASET, File.join(DATA_DIR,"hamster_carcinogenicity.yaml"), @@subjectid
43
+ assert_equal OpenTox::Dataset, @dataset.class
44
+ assert_equal "hamster_carcinogenicity", @dataset[RDF::URI("http://purl.org/dc/elements/1.1/title")]
45
+ hamster_carc?
46
+ @dataset.delete
47
+ end
29
48
 
30
49
  =begin
31
- def test_metadata
32
- d = OpenTox::Dataset.from_file "http://ot-dev.in-silico.ch/dataset", "data/EPAFHM.mini.csv"
33
- assert_equal OpenTox::Dataset, d.class
34
- # TODO fix metadata retrieval
35
- metadata = d.metadata
36
- assert_equal RDF::OT.Dataset, metadata[RDF.type]
37
- assert_equal dataset.uri, metadata[RDF::XSD.anyURI]
38
- d.delete
50
+ # TODO: fix (mime type??0 and add Egons example
51
+ def test_sdf_with_multiple_features
52
+ @dataset = OpenTox::Dataset.from_file DATASET, "#{DATA_DIR}/CPDBAS_v5c_1547_29Apr2008part.sdf"
53
+ assert_equal OpenTox::Dataset, @dataset.class
54
+ puts @dataset.features.size
55
+ puts @dataset.compounds.size
56
+ @dataset.delete
57
+ end
58
+ =end
59
+
60
+ def test_multicolumn_csv
61
+ @dataset = OpenTox::Dataset.from_file DATASET, "#{DATA_DIR}/multicolumn.csv", @@subjectid
62
+ assert_equal 5, @dataset.features.size
63
+ assert_equal 4, @dataset.compounds.size
64
+ @dataset.delete
39
65
  end
66
+
67
+ def test_from_csv
68
+ @dataset = OpenTox::Dataset.from_file DATASET, "#{DATA_DIR}/hamster_carcinogenicity.csv", @@subjectid
69
+ assert_equal OpenTox::Dataset, @dataset.class
70
+ hamster_carc?
71
+ @dataset.delete
72
+ end
73
+
74
+ =begin
40
75
  def test_save
41
- d = OpenTox::Dataset.create "http://ot-dev.in-silico.ch/dataset"
76
+ d = OpenTox::Dataset.create DATASET
42
77
  d.metadata
43
78
  d.metadata[RDF::DC.title] = "test"
44
79
  d.save
@@ -48,6 +83,17 @@ class DatasetTest < Test::Unit::TestCase
48
83
  d.delete
49
84
  end
50
85
  =end
86
+ =begin
87
+ =end
51
88
 
52
89
 
90
+ def hamster_carc?
91
+ assert_kind_of OpenTox::Dataset, @dataset
92
+ #require 'yaml'
93
+ #puts @dataset.data_entries.to_yaml
94
+ assert_equal 85, @dataset.data_entries.size
95
+ assert_equal 85, @dataset.compounds.size
96
+ assert_equal 1, @dataset.features.size
97
+ assert_equal @dataset.uri, @dataset[RDF::XSD.anyURI]
98
+ end
53
99
  end
data/test/feature.rb CHANGED
@@ -16,8 +16,8 @@ class FeatureTest < Test::Unit::TestCase
16
16
  def test_feature
17
17
  @features.each do |uri|
18
18
  f = OpenTox::Feature.new(uri)
19
- assert_equal [RDF::OT1.TUM_CDK_nAtom], f[RDF::OWL.sameAs]
20
- assert_equal RDF::OT1.TUM_CDK_nAtom, f.metadata[RDF::OWL.sameAs].first
19
+ assert_equal RDF::OT1.TUM_CDK_nAtom, f[RDF::OWL.sameAs]
20
+ assert_equal RDF::OT1.TUM_CDK_nAtom, f.metadata[RDF::OWL.sameAs].first.to_s
21
21
  assert_equal [RDF::OT1.Feature,RDF::OT1.NumericFeature].sort, f[RDF.type].sort
22
22
  end
23
23
  end
data/test/policy.rb ADDED
@@ -0,0 +1,120 @@
1
+ require 'test/unit'
2
+ $LOAD_PATH << File.join(File.dirname(__FILE__),'..','lib')
3
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','lib','opentox-client.rb'))
4
+
5
+ TEST_URI = "http://only_a_test/test/" + rand(1000000).to_s
6
+ USER_TYPE = "LDAPUsers"
7
+ USER_VALUE = "uid=guest,ou=people,dc=opentox,dc=org"
8
+ USER_GROUP = "member"
9
+ GROUP_TYPE = "LDAPGroups"
10
+ GROUP_VALUE = "cn=member,ou=groups,dc=opentox,dc=org"
11
+ POLICY_NAME = "test_policy_#{rand(100000)}"
12
+ RULE_NAME = "test_rule_#{rand(100000)}"
13
+ SUBJECT_NAME = "test_subject_#{rand(100000)}"
14
+
15
+ AA ||= "https://opensso.in-silico.ch"
16
+ AA_USER = "guest"
17
+ AA_PASS = "guest"
18
+
19
+ @@subjectid = OpenTox::Authorization.authenticate(AA_USER,AA_PASS)
20
+
21
+ class PolicyTest < Test::Unit::TestCase
22
+
23
+ def test_01_class
24
+ policies = OpenTox::Policies.new()
25
+ assert_equal(policies.class, OpenTox::Policies)
26
+ assert_kind_of Array, policies.names
27
+ assert_kind_of Array, policies.uris
28
+ assert_kind_of Array, policies.names
29
+ end
30
+
31
+ def test_02_subclasses
32
+ policies = OpenTox::Policies.new()
33
+ policies.new_policy(POLICY_NAME)
34
+ assert_equal(policies.names[0], POLICY_NAME)
35
+ assert_equal(policies.policies[policies.names[0]].class, OpenTox::Policy)
36
+ policy = policies.policies[policies.names[0]]
37
+ policy.rule.name = RULE_NAME
38
+ policy.uri = TEST_URI
39
+ assert_equal(policy.rule.class, OpenTox::Policy::Rule)
40
+ assert_equal(policy.rule.name, RULE_NAME)
41
+ assert_equal(policy.rule.uri, TEST_URI)
42
+ assert_equal(policy.uri, TEST_URI)
43
+ policy.subject.name = SUBJECT_NAME
44
+ policy.type = USER_TYPE
45
+ policy.value = USER_VALUE
46
+ assert_equal(policy.subject.class, OpenTox::Policy::Subject)
47
+ assert_equal(policy.subject.name, SUBJECT_NAME)
48
+ assert_equal(policy.subject.type, USER_TYPE)
49
+ assert_equal(policy.type, USER_TYPE)
50
+ assert_equal(policy.subject.value, USER_VALUE)
51
+ assert_equal(policy.value, USER_VALUE)
52
+ end
53
+
54
+ def test_03_read_readwrite
55
+ policies = OpenTox::Policies.new()
56
+ policies.new_policy(POLICY_NAME)
57
+ policy = policies.policies[policies.names[0]]
58
+ policy.rule.name = RULE_NAME
59
+ policy.uri = TEST_URI
60
+ policy.rule.get = "allow"
61
+ assert policy.rule.read
62
+ assert !policy.rule.readwrite
63
+ policy.rule.post = "allow"
64
+ policy.rule.put = "allow"
65
+ assert !policy.rule.read
66
+ assert policy.rule.readwrite
67
+ end
68
+
69
+ def test_04_group_user
70
+ policies = OpenTox::Policies.new()
71
+ policies.load_default_policy(AA_USER, TEST_URI, "member")
72
+ assert_equal "member", policies.policies["policy_group"].group
73
+ assert_equal AA_USER, policies.policies["policy_user"].user
74
+ end
75
+
76
+ def test_05_DN
77
+ policies = OpenTox::Policies.new()
78
+ policies.new_policy(POLICY_NAME)
79
+ policy = policies.policies[policies.names[0]]
80
+ policy.set_ot_user(AA_USER)
81
+ assert_equal USER_VALUE, policy.value
82
+ assert_equal USER_TYPE, policy.type
83
+ policy.set_ot_group(USER_GROUP)
84
+ assert_equal GROUP_VALUE, policy.value
85
+ assert_equal GROUP_TYPE, policy.type
86
+ end
87
+
88
+ def test_06_load_xml_and_check_defaults
89
+ policies = OpenTox::Policies.new()
90
+ xml = File.read(File.join(File.dirname(__FILE__), "../lib/templates/default_policy.xml"))
91
+ policies.load_xml(xml)
92
+ # check user policy
93
+ policy = policies.policies["policy_user"]
94
+ assert policy.name == "policy_user"
95
+ assert policy.rule.name == "rule_user"
96
+ assert policy.rule.uri == "uri"
97
+ assert policy.rule.get == "allow"
98
+ assert policy.rule.post == "allow"
99
+ assert policy.rule.delete == "allow"
100
+ assert policy.rule.put == "allow"
101
+ assert policy.subject_group == "subjects_user"
102
+ assert policy.subject.name == "subject_user"
103
+ assert policy.subject.type == USER_TYPE
104
+ assert policy.subject.value == USER_VALUE
105
+ # check group policy
106
+ policy = policies.policies["policy_group"]
107
+ assert policy.name == "policy_group"
108
+ assert policy.rule.name == "rule_group"
109
+ assert policy.rule.uri == "uri"
110
+ assert policy.rule.get == "allow"
111
+ assert !policy.rule.post
112
+ assert !policy.rule.delete
113
+ assert !policy.rule.put
114
+ assert policy.subject_group == "subjects_group"
115
+ assert policy.subject.name == "subject_group"
116
+ assert policy.subject.type == GROUP_TYPE
117
+ assert policy.subject.value == GROUP_VALUE
118
+ end
119
+
120
+ end
data/test/task.rb CHANGED
@@ -17,7 +17,7 @@ class TaskTest < Test::Unit::TestCase
17
17
  assert_equal Array, all.class
18
18
  t = all.last
19
19
  assert_equal OpenTox::Task, t.class
20
- assert_equal RDF::OT1.Task, t[RDF.type].first
20
+ assert_equal RDF::OT1.Task, t[RDF.type]
21
21
  end
22
22
 
23
23
  def test_create_and_complete
@@ -46,7 +46,7 @@ class TaskTest < Test::Unit::TestCase
46
46
 
47
47
  def test_create_and_fail
48
48
  task = OpenTox::Task.create TASK_SERVICE_URI, :description => "test failure", :creator => "http://test.org/fake_creator" do
49
- sleep 0.5
49
+ sleep 1
50
50
  raise "A runtime error occured"
51
51
  end
52
52
  assert task.running?
@@ -58,7 +58,7 @@ class TaskTest < Test::Unit::TestCase
58
58
 
59
59
  def test_create_and_fail_with_opentox_error
60
60
  task = OpenTox::Task.create TASK_SERVICE_URI, :description => "test failure", :creator => "http://test.org/fake_creator" do
61
- sleep 0.5
61
+ sleep 1
62
62
  raise OpenTox::Error.new 500, "An OpenTox::Error occured"
63
63
  end
64
64
  assert task.running?
@@ -68,9 +68,10 @@ class TaskTest < Test::Unit::TestCase
68
68
  assert_equal "Error", task.hasStatus
69
69
  end
70
70
 
71
+ =begin
71
72
  def test_wrong_result_uri
72
73
  task = OpenTox::Task.create TASK_SERVICE_URI, :description => "test wrong result uri", :creator => "http://test.org/fake_creator" do
73
- sleep 0.5
74
+ sleep 1
74
75
  "Asasadasd"
75
76
  end
76
77
  assert task.running?
@@ -79,7 +80,6 @@ class TaskTest < Test::Unit::TestCase
79
80
  assert task.error?
80
81
  assert_equal "Error", task.hasStatus
81
82
  end
82
- =begin
83
83
  =end
84
84
 
85
85
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opentox-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1pre
4
+ version: 0.0.2pre
5
5
  prerelease: 5
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-09 00:00:00.000000000 Z
12
+ date: 2012-04-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
- requirement: &82129140 !ruby/object:Gem::Requirement
16
+ requirement: &76175050 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *82129140
24
+ version_requirements: *76175050
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rest-client
27
- requirement: &82128400 !ruby/object:Gem::Requirement
27
+ requirement: &76185830 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *82128400
35
+ version_requirements: *76185830
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rdf
38
- requirement: &82127910 !ruby/object:Gem::Requirement
38
+ requirement: &76706430 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *82127910
46
+ version_requirements: *76706430
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rdf-raptor
49
- requirement: &82127560 !ruby/object:Gem::Requirement
49
+ requirement: &76705970 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *82127560
57
+ version_requirements: *76705970
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: open4
60
- requirement: &82127200 !ruby/object:Gem::Requirement
60
+ requirement: &76705540 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *82127200
68
+ version_requirements: *76705540
69
69
  description: Ruby wrapper for the OpenTox REST API (http://www.opentox.org)
70
70
  email:
71
71
  - helma@in-silico.ch
@@ -94,6 +94,7 @@ files:
94
94
  - lib/templates/default_guest_policy.xml
95
95
  - lib/templates/default_policy.xml
96
96
  - opentox-client.gemspec
97
+ - test/authorization.rb
97
98
  - test/compound.rb
98
99
  - test/data/CPDBAS_v5c_1547_29Apr2008part.sdf
99
100
  - test/data/EPAFHM.csv
@@ -112,11 +113,13 @@ files:
112
113
  - test/dataset.rb
113
114
  - test/error.rb
114
115
  - test/feature.rb
116
+ - test/policy.rb
115
117
  - test/task.rb
116
118
  homepage: http://github.com/opentox/opentox-client
117
119
  licenses:
118
120
  - GPL-3
119
- post_install_message:
121
+ post_install_message: Please check the version of your libraptor library, if installation
122
+ of rdf.rb fails
120
123
  rdoc_options: []
121
124
  require_paths:
122
125
  - lib
@@ -128,14 +131,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
128
131
  version: '0'
129
132
  segments:
130
133
  - 0
131
- hash: -394211199
134
+ hash: -571051053
132
135
  required_rubygems_version: !ruby/object:Gem::Requirement
133
136
  none: false
134
137
  requirements:
135
138
  - - ! '>'
136
139
  - !ruby/object:Gem::Version
137
140
  version: 1.3.1
138
- requirements: []
141
+ requirements:
142
+ - libraptor-dev
139
143
  rubyforge_project: opentox-client
140
144
  rubygems_version: 1.8.11
141
145
  signing_key: