Class: ODDB::TestNarcoticPlugin

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

Instance Method Summary (collapse)

Instance Method Details

- (Object) setup



15
16
17
18
# File 'test/test_plugin/narcotic.rb', line 15

def setup
  @app = FlexMock.new
  @plugin = NarcoticPlugin.new(@app)
end

- (Object) test_casrns



19
20
21
22
23
24
25
26
27
28
# File 'test/test_plugin/narcotic.rb', line 19

def test_casrns
  row = ['NAME', nil, 'pcode', 'smcd']
  assert_equal(@plugin.casrns(row), [])
  row = ['NAME', '', 'pcode', 'smcd']
  assert_equal(@plugin.casrns(row), [])
  row = ['NAME', 'nil', 'pcode', 'smcd']
  assert_equal(@plugin.casrns(row), [])
  row = ['NAME', '11-11-11', 'pcode', 'smcd']
  assert_equal(['11-11-11'], @plugin.casrns(row))
end

- (Object) test_category



39
40
41
42
43
44
# File 'test/test_plugin/narcotic.rb', line 39

def test_category
  row = ['NAME', 'casrn', 'pcode', 'eancode', 'company', 'c']
  assert_equal('c', @plugin.category(row))
  row = ['NAME', 'casrn', 'pcode', 'eancode', 'company', '']
  assert_equal('a', @plugin.category(row))
end

- (Object) test_name



64
65
66
67
68
69
# File 'test/test_plugin/narcotic.rb', line 64

def test_name
  row = ['Codein', 'casrn', 'pcode', '7680543210079']
  assert_equal('Codein', @plugin.name(row))
  row = [nil, 'casrn', 'pcode', '7680543210079']
  assert_equal('', @plugin.name(row))
end

- (Object) test_name_substance



70
71
72
73
74
75
# File 'test/test_plugin/narcotic.rb', line 70

def test_name_substance
  row = ['Codein (unter Vorbehalt von)', 'casrn', 'pcode', '7680543210079']
  assert_equal('Codein', @plugin.strip_name(row).at(0).strip)
  row = ['Codein-Oxid-H2O', 'casrn', 'pcode', '7680543210079']
  assert_equal('Codein-Oxid-H2O', @plugin.strip_name(row).at(0))
end

- (Object) test_narcotic_text



58
59
60
61
62
63
# File 'test/test_plugin/narcotic.rb', line 58

def test_narcotic_text
  text = "Codeinhaltige"
  assert_equal("Codein", @plugin.text2name(text, :de))
  text = "Les préparations contenant du dextropropoxyphène sont" 
  assert_equal("dextropropoxyphène", @plugin.text2name(text, :fr))
end

- (Object) test_report_text



45
46
47
48
49
# File 'test/test_plugin/narcotic.rb', line 45

def test_report_text
  row = ['name','text1','text2','text3','text4']
  expected = "name\ntext1 | text2 | text3 | text4\n"
  assert_equal(expected, @plugin.report_text(row))
end

- (Object) test_smcd



29
30
31
32
33
34
35
36
37
38
# File 'test/test_plugin/narcotic.rb', line 29

def test_smcd
  row = ['NAME', 'casrn', 'pcode', '7680543210079']
  assert_equal('54321007', @plugin.smcd(row))
  row = ['NAME', 'casrn', 'pcode', nil]
  assert_nil(@plugin.smcd(row))
  row = ['NAME', 'casrn', 'pcode', ''] 
  assert_nil(@plugin.smcd(row))
  row = ['NAME', 'casrn', 'pcode', 'nil'] 
  assert_nil(@plugin.smcd(row))
end

- (Object) test_update_narcotic



50
51
52
53
54
55
56
57
# File 'test/test_plugin/narcotic.rb', line 50

def test_update_narcotic
  row = ["Dextropropoxyphenhaltige","- - - - -","- - - - -",
    "- - - - -","- - - - -","c"]
  res = @plugin.update_narcotic(row, 'casrn', :de)
  assert_nil res
  expected = { "Dextropropoxyphen" => "Dextropropoxyphenhaltige" }
  assert_equal expected, @plugin.instance_variable_get('@narcotic_texts')
end