Class: ODDB::TestFlockhartPlugin

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

Instance Method Summary (collapse)

Instance Method Details

- (Object) setup



436
437
438
439
# File 'test/test_plugin/interaction.rb', line 436

def setup
  @app = flexmock 'app'
  @plugin = ODDB::Interaction::FlockhartPlugin.new @app, false
end

- (Object) setup_mechanize(mapping = [])



440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
# File 'test/test_plugin/interaction.rb', line 440

def setup_mechanize mapping=[]
  agent = flexmock Mechanize.new
  mapping.each do |page, method, url, formname, page2|
    path = File.join @datadir, page
    page = setup_page url, path, agent
    if formname
      form = flexmock page.form(formname)
      action = form.action
      page = flexmock page
      page.should_receive(:form).with(formname).and_return(form)
      path2 = File.join @datadir, page2
      page2 = setup_page action, path2, agent
      form.should_receive(:submit).and_return page2
    end
    agent.should_receive(method).with(url).and_return(page)
  end
  agent
end

- (Object) setup_page(url, path, agent)



458
459
460
461
462
# File 'test/test_plugin/interaction.rb', line 458

def setup_page url, path, agent
  response = {'content-type' => 'text/html'}
  Mechanize::Page.new(URI.parse(url), response,
                      File.read(path), 200, agent)
end

- (Object) test_parse_detail



463
464
465
466
467
468
469
470
471
472
473
# File 'test/test_plugin/interaction.rb', line 463

def test_parse_detail
  path = File.expand_path('../data/html/interaction/flockhart/3A457.htm',
                          File.dirname(__FILE__))
  page = setup_page 'url', path, setup_mechanize
  cytochrome = @plugin.parse_detail_page '3A457', page
  assert_instance_of ODDB::Interaction::Cytochrome, cytochrome
  assert_equal 86, cytochrome.substrates.size
  assert_equal 31, cytochrome.inhibitors.size
  names = cytochrome.inhibitors.collect do |substr| substr.name end
  assert_equal 14, cytochrome.inducers.size
end