Class: ODDB::TestInteractionPlugin

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
test/test_plugin/interaction.rb

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Object) add_types(cyt)



51
52
53
54
55
56
57
58
59
60
61
62
# File 'test/test_plugin/interaction.rb', line 51

def TestInteractionPlugin.add_types(cyt)
  (1..2).each { |dig|
    cyt.substrates.push(ODDB::Interaction::SubstrateConnection.new("sub_#{dig}"))
  }
  (1..3).each { |dig|
    cyt.inhibitors.push(ODDB::Interaction::InhibitorConnection.new("inh_#{dig}"))
  }
  (1..4).each { |dig|
    cyt.inducers.push(ODDB::Interaction::InducerConnection.new("ind_#{dig}"))
  }
  cyt
end

+ (Object) cyt_hsh(cyt_range, option = nil)



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
# File 'test/test_plugin/interaction.rb', line 23

def TestInteractionPlugin.cyt_hsh(cyt_range, option=nil)
  cyts = {}
  cyt_range.each { |dig|
    cyts.store("cyt_#{dig}", ODDB::Interaction::Cytochrome.new("cyt_#{dig}"))
  }
  cyts.each { |key, value|
    TestInteractionPlugin.add_types(value)
  }
  if(option=="links")
    cyts.values.each { |cyt|
      ODDB::Interaction::InteractionPlugin::INTERACTION_TYPES.each { |type|
        cyt.send(type).each { |conn|
          conn.add_link("conn_link")
        }
      }
    }
  end
  if(option=="categories")
    cyts.values.each { |cyt|
      ODDB::Interaction::InteractionPlugin::INTERACTION_TYPES.each { |type|
        cyt.send(type).each { |conn|
          conn.category="conn_cat"
        }
      }
    }
  end
  cyts
end

Instance Method Details

- (Object) setup



63
64
65
66
67
# File 'test/test_plugin/interaction.rb', line 63

def setup
  @app = Mock.new('app')
  @plugin = ODDB::Interaction::InteractionPlugin.new(@app)
  @mock_plugin = Mock.new('mock_plugin') 
end

- (Object) teardown



68
69
70
71
# File 'test/test_plugin/interaction.rb', line 68

def teardown
  @mock_plugin.__verify
  @app.__verify
end

- (Object) test_flock_conn_name



72
73
74
75
76
77
78
79
# File 'test/test_plugin/interaction.rb', line 72

def test_flock_conn_name
  flock_conn = Mock.new('flock_conn')
  flock_conn.__next(:name) {
    "acetaminophen="
  }
  result = @plugin.flock_conn_name(flock_conn)
  assert_equal("acetaminophen", result)
end

- (Object) test_flock_conn_name2



80
81
82
83
84
85
86
87
# File 'test/test_plugin/interaction.rb', line 80

def test_flock_conn_name2
  flock_conn = Mock.new('flock_conn')
  flock_conn.__next(:name) {
    "acetaminophen (in part)"
  }
  result = @plugin.flock_conn_name(flock_conn)
  assert_equal("acetaminophen", result)
end

- (Object) test_parse_hayes



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'test/test_plugin/interaction.rb', line 88

def test_parse_hayes
  interaction = Mock.new('interaction')
  cytochrome = Mock.new('cytochrome')
  connection = Mock.new('connection')
  @mock_plugin.__next(:parse_substrate_table) {
    { 'foo' => cytochrome }
  }
  @mock_plugin.__next(:parse_interaction_table) {
    { 'foo' => interaction }
  }
  interaction.__next(:inhibitors) {
    [ connection ]
  }
  cytochrome.__next(:add_connection) { |param|
    assert_equal(connection, param)
  }
  interaction.__next(:inducers) {
    [ connection ]
  }
  cytochrome.__next(:add_connection) { |param|
    assert_equal(connection, param)
  }
  @plugin.parse_hayes(@mock_plugin)
  interaction.__verify
  cytochrome.__verify
  connection.__verify
end

- (Object) test_report

def test_parse_flockhart

      table_cytochrome = Mock.new('table_cytochrome')
      detail_cytochrome = Mock.new('detail_cytochrome')
      table_connection = Mock.new('table_connection')
      detail_connection = Mock.new('detail_connection')
      @mock_plugin.__next(:parse_table) {
        { "foo" =>  table_cytochrome }
      }
      @mock_plugin.__next(:parse_detail_pages) {
        { "foo" =>  detail_cytochrome }  
      }
      detail_cytochrome.__next(:substrates) {
        [ detail_connection ]
      }
      table_cytochrome.__next(:substrates) {
        [ table_connection ]
      }
      table_connection.__next(:name) {
        'Bar Foo'
      }
      detail_connection.__next(:name) {
        'bar foo'
      }
      detail_connection.__next(:category=) { |param|
        assert_equal('foo_cat', param)
      }
      table_connection.__next(:category) {
        "foo_cat"
      }
      detail_cytochrome.__next(:inhibitors) {
        [ detail_connection ]
      }
      table_cytochrome.__next(:inhibitors) {
        [ table_connection ]
      }
      table_connection.__next(:name) {
        'Foo Bar'
      }
      detail_connection.__next(:name) {
        'bar foo'
      }
      detail_cytochrome.__next(:inducers) {
        [ detail_connection ]
      }
      table_cytochrome.__next(:inducers) {
        [ table_connection ]
      }
      table_connection.__next(:name) {
        'Foo Bar'
      }
      detail_connection.__next(:name) {
        'bar foo'
      }
      @plugin.parse_flockhart(@mock_plugin)
      table_cytochrome.__verify
      detail_cytochrome.__verify
      table_connection.__verify
      detail_connection.__verify
    end


176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'test/test_plugin/interaction.rb', line 176

def test_report
  @plugin.flock_conn_not_found = 3 
  @plugin.hayes_conn_not_found = 2 
  @plugin.hayes = { 
    'foo' =>  'foobar',
    'bar' =>  'foobar',
  }
  @plugin.flockhart = { 
    'foobar'  => 'foobar',
    'barfoo'  => 'foobar',
  }
  result = @plugin.report.split("\n").sort
  expected = [
    "found hayes cytochromes: 2",
    "bar, foo",
    "found flock cytochromes: 2",
    "barfoo, foobar",
    "There are no matching hayes connections for 2 flockhart connections",
    "There are no matching flockhart connections for 3 hayes connections",
  ]
  assert_equal(expected.sort, result)
end

- (Object) test_report2



198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'test/test_plugin/interaction.rb', line 198

def test_report2
  @plugin.flock_conn_not_found = 3 
  @plugin.hayes_conn_not_found = 2 
  @plugin.update_reports = {
    :cyp450_created     =>  [ 'cyp450', 'cyp450_2' ],
    :substance_created  => [ 'substance' ],
    :inhibitors_created =>  [ 'inhibitor updated' ],
    :inhibitors_deleted =>  [ 'inhibitor deleted' ],
    :inducers_created   => [ 'inducer updated' ],
    :inducers_deleted   => [ 'inducer deleted' ],
    :substrates_created =>  [ 'substrate updated' ],
    :substrates_deleted =>  [ 'substrate deleted' ],
  }
  @plugin.hayes = { 
    'foo' =>  'foobar',
    'bar' =>  'foobar',
  }
  @plugin.flockhart = { 
    'foobar'  => 'foobar',
    'barfoo'  => 'foobar',
  }
  result = @plugin.report.split("\n").sort
  expected = [
    "found hayes cytochromes: 2",
    "bar, foo",
    "found flock cytochromes: 2",
    "barfoo, foobar",
    "There are no matching hayes connections for 2 flockhart connections",
    "There are no matching flockhart connections for 3 hayes connections",
    ODDB::Interaction::InteractionPlugin::UPDATE_MESSAGES[:cyp450_created],
    "cyp450", "cyp450_2", 
    ODDB::Interaction::InteractionPlugin::UPDATE_MESSAGES[:substance_created],
    "substance",
    ODDB::Interaction::InteractionPlugin::UPDATE_MESSAGES[:inhibitors_created],
    "inhibitor updated",
    ODDB::Interaction::InteractionPlugin::UPDATE_MESSAGES[:inhibitors_deleted],
    "inhibitor deleted",
    ODDB::Interaction::InteractionPlugin::UPDATE_MESSAGES[:inducers_created],
    "inducer updated",
    ODDB::Interaction::InteractionPlugin::UPDATE_MESSAGES[:inducers_deleted],
    "inducer deleted",
    ODDB::Interaction::InteractionPlugin::UPDATE_MESSAGES[:substrates_created],
    "substrate updated",
    ODDB::Interaction::InteractionPlugin::UPDATE_MESSAGES[:substrates_deleted],
    "substrate deleted",
  ]
  assert_equal(expected.sort, result)
end

- (Object) test_similar_name



246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'test/test_plugin/interaction.rb', line 246

def test_similar_name
  subs = Mock.new('Substance')
  @app.__next(:substance) { |name| 
    assert_equal('astring', name)
    subs 
  }
  subs.__next(:same_as?) { |other|
    assert_equal('bstring', other)
    'result'
  }
  assert_equal('result', @plugin.similar_name?('astring', 'bstring'))
  subs.__verify
end

- (Object) test_update_oddb_create_substance



363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
# File 'test/test_plugin/interaction.rb', line 363

def test_update_oddb_create_substance
  connection = Mock.new("connection")
  substance = Mock.new("substance")
  connection.__next(:lang) { 'en' }
  connection.__next(:name) { 'not_yet_updated' }
  @app.__next(:update) { substance }
  #substance.__next(:substrate_connections) { [connection] }
  substance.__next(:name) { 'not_yet_updated' }
  expected = {
    substance =>  {},
  }
  @plugin.update_oddb_create_substance(connection)
  assert_equal(expected, 
    @plugin.instance_variable_get('@updated_substances'))
  connection.__verify
  substance.__verify
end

- (Object) test_update_oddb_cyp450

def test_update_oddb_cyp450_connections

      cytochrome = Mock.new('cytochrome')
      cyp450 = Mock.new('cyp450') 
      inhibitor = Mock.new('inhibitor')
      pointer = Mock.new('pointer')
      substance = Mock.new('substance')
      cyp450.__next(:inhibitors) {
        { 
          'key_1' =>  'value_1',
          'key_2' =>  'value_2',
        }
      }
      cytochrome.__next(:inhibitors) { [ inhibitor ] }
      cyp450.__next(:pointer) { pointer }
      inhibitor.__next(:name) { 'foo_name' }
      inhibitor.__next(:links) { [ 'link' ] }
      inhibitor.__next(:category) { 'category' }
      #inhibitor.__next(:name)  { 'key_3' }
      cyp450.__next(:inhibitors) { 
        { 
          'key_1' =>  'value_1',
          'key_2' =>  'value_2',
        }
      }
      cyp450.__next(:pointer) { pointer }
      pointer.__next(:+) { |params|
        assert_equal(Array, params.class)
        assert_equal(2, params.size)
        pointer
      }
      pointer.__next(:+) { |params|
        assert_equal(Array, params.class)
        assert_equal(2, params.size)
        pointer
      }
      #pointer.__next(:creator) { pointer }
      @app.__next(:substance_by_connection_key) { substance }
      substance.__next(:primary_connection_key) { 'key_1' }
      @app.__next(:update) { |create_pointer, args|
        assert_equal(Hash, args.class)
        assert_equal(3, args.size)
        assert_equal(pointer, create_pointer)
      }
      #inhibitor.__next(:name) { 'key_1' }
      #inhibitor.__next(:name) { 'key_1' }
      #inhibitor.__next(:name)  { 'foo_name' }
      #cyp450.__next(:pointer) { pointer }
  #=begin
      pointer.__next(:+) { |params|
        assert_equal('key_2', params.last)
        assert_equal(Array, params.class)
        pointer
      }
  #=end
      cyp450.__next(:cyp_id) { 'cyp45_id' }
  #=begin
      @app.__next(:delete) { |delete_pointer| 
        assert_equal(pointer, delete_pointer)
      }
      #cyp450.__next(:pointer) { pointer }
      pointer.__next(:+) { |params|
        assert_equal('key_1', params.last)
        assert_equal(Array, params.class)
        pointer
      }
  #=end
      @app.__next(:delete) { |delete_pointer| 
        assert_equal(pointer, delete_pointer)
      }
      #cyp450.__next(:cyp_id) { 'cyp45_id' }
      @plugin.update_oddb_cyp450_connections('foo_id', cytochrome, cyp450, :inhibitors)
      cytochrome.__verify
      cyp450.__verify
      inhibitor.__verify
      pointer.__verify
    end


337
338
339
340
341
342
343
344
345
# File 'test/test_plugin/interaction.rb', line 337

def test_update_oddb_cyp450
  cyp450 = Mock.new('cyp450')
  @app.__next(:cyp450) { |param|
    assert_equal('foo_id', param)
    'cyp450'
  }
  @plugin.update_oddb_cyp450('foo_id', 'cytochrome')
  cyp450.__verify
end

- (Object) test_update_oddb_cyp4502



346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
# File 'test/test_plugin/interaction.rb', line 346

def test_update_oddb_cyp4502
  cytochrome = Mock.new('cytochrome')
  cyp450 = Mock.new('cyp450')
  @app.__next(:cyp450) { |param|
    assert_equal('foo_id', param)
  }
  @app.__next(:create) { |param|
    assert_equal(ODDB::Persistence::Pointer, param.class)
    cyp450
  }
  cyp450.__next(:cyp_id) {
    'cyp450_id'
  }
  @plugin.update_oddb_cyp450('foo_id', cytochrome)
  cytochrome.__verify
  cyp450.__verify
end

- (Object) test_update_oddb_substrates



380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
# File 'test/test_plugin/interaction.rb', line 380

def test_update_oddb_substrates
  cytochrome = Mock.new('cytochrome')
  substrate = Mock.new('substrate')
  substance = Mock.new('substance')
  connection = Mock.new('connection')
  pointer = Mock.new('pointer')
  @plugin.updated_substances = { 
    'found' =>  { 
      :connections  => { 
        'cyt_id'  => connection
      }
    }
  }
  cytochrome.__next(:substrates) { [ substrate ] }
  substrate.__next(:links) { 'links' }
  substrate.__next(:category) { 'category' }
  substrate.__next(:name) { 'substratename' }
  @app.__next(:substance_by_connection_key) { 
    substance 
  }
=begin
  substance.__next(:has_connection_key?) { |key|
    assert_equal('substratename', key) 
    true
  }
=end


  substance.__next(:primary_connection_key) { 
    'substratename'
  }
  substance.__next(:pointer) { pointer }
  pointer.__next(:+) { pointer }
  substance.__next(:cyp450substrate) { |param| 
    assert_equal('cyt_id', param) 
    false
  }
  pointer.__next(:creator) { 'creator' }
  substrate.__next(:name) { 'substratename' }
  #substance.__next(:connection_keys) { ['found'] }
  @app.__next(:update) {}
  @plugin.update_oddb_substrates('cyt_id', cytochrome)
  cytochrome.__verify
  substrate.__verify
  substance.__verify
  connection.__verify
  pointer.__verify
end