oddb.org 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. data/.gemtest +0 -0
  2. data/Guide.txt +23 -17
  3. data/{README → INSTALL_from_Source.txt} +64 -75
  4. data/Manifest.txt +110 -4
  5. data/README.txt +4 -2
  6. data/Rakefile +5 -0
  7. data/doc/favicon.ico +0 -0
  8. data/doc/index.rbx +15 -0
  9. data/doc/resources/anthroposophy/favicon.ico +0 -0
  10. data/doc/resources/anthroposophy/logo.png +0 -0
  11. data/doc/resources/atupri/logo.gif +0 -0
  12. data/doc/resources/desitin/logo.jpg +0 -0
  13. data/doc/resources/downloads/datadesc/analysis.csv.txt +57 -0
  14. data/doc/resources/downloads/datadesc/doctors.csv.txt +43 -0
  15. data/doc/resources/downloads/datadesc/doctors.yaml.txt +52 -0
  16. data/doc/resources/downloads/datadesc/fachinfo.yaml.txt +107 -0
  17. data/doc/resources/downloads/datadesc/generics.xls.txt +42 -0
  18. data/doc/resources/downloads/datadesc/index_therapeuticus.txt +38 -0
  19. data/doc/resources/downloads/datadesc/interactions.yaml.txt +78 -0
  20. data/doc/resources/downloads/datadesc/migel.csv.txt +84 -0
  21. data/doc/resources/downloads/datadesc/narcotics.csv.txt +49 -0
  22. data/doc/resources/downloads/datadesc/narcotics.yaml.txt +40 -0
  23. data/doc/resources/downloads/datadesc/oddb.csv.txt +98 -0
  24. data/doc/resources/downloads/datadesc/oddb.yaml.txt +255 -0
  25. data/doc/resources/downloads/datadesc/oddb2.csv.txt +94 -0
  26. data/doc/resources/downloads/datadesc/oddbdat.txt +228 -0
  27. data/doc/resources/downloads/datadesc/patents.xls.txt +29 -0
  28. data/doc/resources/downloads/datadesc/patinfo.yaml.txt +79 -0
  29. data/doc/resources/downloads/datadesc/price_history.csv.txt +43 -0
  30. data/doc/resources/downloads/datadesc/price_history.yaml.txt +55 -0
  31. data/doc/resources/downloads/datadesc/s31x.txt +40 -0
  32. data/doc/resources/downloads/datadesc/swissdrug-update.xls.txt +59 -0
  33. data/doc/resources/downloads/examples/Inderal.Preisvergleich.csv +19 -0
  34. data/doc/resources/downloads/examples/analysis.csv +35 -0
  35. data/doc/resources/downloads/examples/compendium_ch.oddb.org.firefox.epub +0 -0
  36. data/doc/resources/downloads/examples/compendium_ch.oddb.org.htc.prc +0 -0
  37. data/doc/resources/downloads/examples/compendium_ch.oddb.org.kindle.mobi +0 -0
  38. data/doc/resources/downloads/examples/compendium_ch.oddb.org.stanza.epub +0 -0
  39. data/doc/resources/downloads/examples/doctors.csv +13 -0
  40. data/doc/resources/downloads/examples/doctors.yaml +238 -0
  41. data/doc/resources/downloads/examples/fachinfo.yaml +1255 -0
  42. data/doc/resources/downloads/examples/fachinfos_de.pdf +51565 -0
  43. data/doc/resources/downloads/examples/fachinfos_fr.pdf +52072 -0
  44. data/doc/resources/downloads/examples/generics.xls +0 -0
  45. data/doc/resources/downloads/examples/index_therapeuticus.tar.gz +0 -0
  46. data/doc/resources/downloads/examples/interactions.yaml +161 -0
  47. data/doc/resources/downloads/examples/migel.csv +36 -0
  48. data/doc/resources/downloads/examples/narcotics.yaml +92 -0
  49. data/doc/resources/downloads/examples/oddb.csv +1378 -0
  50. data/doc/resources/downloads/examples/oddb.yaml +14976 -0
  51. data/doc/resources/downloads/examples/oddb2.csv +1566 -0
  52. data/doc/resources/downloads/examples/oddbdat.tar.gz +0 -0
  53. data/doc/resources/downloads/examples/patents.xls +0 -0
  54. data/doc/resources/downloads/examples/patinfo.yaml +2505 -0
  55. data/doc/resources/downloads/examples/price_history.csv +99 -0
  56. data/doc/resources/downloads/examples/price_history.yaml +431 -0
  57. data/doc/resources/downloads/examples/swissdrug-update.xls +0 -0
  58. data/doc/resources/errors/appdown.html +50 -0
  59. data/doc/resources/errors/logo.png +0 -0
  60. data/doc/resources/errors/logo_de.gif +0 -0
  61. data/doc/resources/gcc/banner.gif +0 -0
  62. data/doc/resources/gcc/logo.png +0 -0
  63. data/doc/resources/gcc/logo_de.gif +0 -0
  64. data/doc/resources/gcc/logo_doc.gif +0 -0
  65. data/doc/resources/gcc/logo_fr.gif +0 -0
  66. data/doc/resources/gcc/logo_rss.png +0 -0
  67. data/doc/resources/generika/favicon.ico +0 -0
  68. data/doc/resources/generika/logo.gif +0 -0
  69. data/doc/resources/generika/logo_de.gif +0 -0
  70. data/doc/resources/generika/logo_fr.gif +0 -0
  71. data/doc/resources/homeopathy/favicon.ico +0 -0
  72. data/doc/resources/homeopathy/logo.png +0 -0
  73. data/doc/resources/icon_twitter.gif +0 -0
  74. data/doc/resources/innova/logo.gif +0 -0
  75. data/doc/resources/innova/logo_de.gif +0 -0
  76. data/doc/resources/javascript/admin.js +14 -0
  77. data/doc/resources/javascript/autofill.js +21 -0
  78. data/doc/resources/javascript/bit.ly.js +29 -0
  79. data/doc/resources/javascript/company.js +22 -0
  80. data/doc/resources/javascript/dojo/Editor.js +219 -0
  81. data/doc/resources/javascript/dojo/HtmlEditorToolbar.html +163 -0
  82. data/doc/resources/javascript/dojo/sigma.gif +0 -0
  83. data/doc/resources/javascript/widget/SymbolPalette.js +162 -0
  84. data/doc/resources/javascript/widget/Tooltip.js +85 -0
  85. data/doc/resources/javascript/widget/__package__.js +2 -0
  86. data/doc/resources/livemarks16.png +0 -0
  87. data/doc/resources/mail.gif +0 -0
  88. data/doc/resources/mobile/logo.png +0 -0
  89. data/doc/resources/paypal_donate.gif +0 -0
  90. data/doc/resources/phyto-pharma/favicon.ico +0 -0
  91. data/doc/resources/phyto-pharma/logo.png +0 -0
  92. data/doc/resources/plugins/Generika.cc.gif +0 -0
  93. data/doc/resources/plugins/Generika.cc.html +34 -0
  94. data/doc/resources/plugins/Generika.cc.src +34 -0
  95. data/doc/resources/plugins/oddb.org.gif +0 -0
  96. data/doc/resources/plugins/oddb.org.html +34 -0
  97. data/doc/resources/plugins/oddb.org.src +34 -0
  98. data/doc/resources/print.css +33 -0
  99. data/doc/resources/provita/logo_de.gif +0 -0
  100. data/doc/resources/santesuisse/logo_de.gif +0 -0
  101. data/doc/resources/schoenenberger/logo_de.gif +0 -0
  102. data/doc/resources/swissmedic/logo.png +0 -0
  103. data/doc/resources/swissmedic/logo_de.gif +0 -0
  104. data/doc/resources/swissmedic/logo_doc.gif +0 -0
  105. data/doc/resources/swissmedic/logo_fr.gif +0 -0
  106. data/doc/resources/sympany/logo.gif +0 -0
  107. data/doc/robots.txt +29 -0
  108. data/ext/export/src/generics_xls.rb +29 -5
  109. data/ext/export/src/oddbdat.rb +1 -1
  110. data/ext/export/test/test_generics_xls.rb +216 -0
  111. data/ext/export/test/test_oddbdat.rb +880 -0
  112. data/lib/oddb.org.rb +1 -1
  113. data/src/model/package.rb +3 -2
  114. data/src/plugin/analysis.rb +2 -0
  115. data/src/plugin/bsv_xml.rb +1 -1
  116. data/src/plugin/hospitals.rb +1 -0
  117. data/src/plugin/oddbdat_export.rb +12 -2
  118. data/src/plugin/text_info.rb +16 -29
  119. data/src/util/exporter.rb +21 -1
  120. data/src/util/log.rb +3 -0
  121. data/src/util/oddbapp.rb +1 -1
  122. data/src/util/oddbconfig.rb +1 -1
  123. data/src/util/updater.rb +9 -1
  124. data/test/data/html/interaction/flockhart/prepared_table.asp +820 -0
  125. data/test/data/html/interaction/flockhart/table.asp +820 -0
  126. data/test/data/html/text_info/News.html +18 -93
  127. data/test/suite.rb +78 -4
  128. data/test/test_model/package.rb +38 -0
  129. data/test/test_plugin/bsv_xml.rb +4 -2
  130. data/test/test_plugin/flockhart.rb +1 -1
  131. data/test/test_plugin/oddbdat_export.rb +79 -658
  132. data/test/test_plugin/ouwerkerk.rb +2 -2
  133. data/test/test_plugin/suite.rb +8 -6
  134. data/test/test_plugin/text_info.rb +40 -52
  135. data/test/test_plugin/{doctors.rb → zdoctor.rb} +0 -0
  136. data/test/test_util/exporter.rb +500 -0
  137. data/test/test_util/suite.rb +8 -6
  138. data/test/test_util/{log.rb → zlog.rb} +19 -0
  139. data/test/test_view/{search.rb → asearch.rb} +0 -0
  140. data/test/test_view/suite.rb +8 -6
  141. metadata +143 -14
@@ -13,6 +13,7 @@ require 'model/indication'
13
13
  require 'model/activeagent'
14
14
  require 'model/composition'
15
15
  require 'mock'
16
+ require 'fileutils'
16
17
 
17
18
  module ODDB
18
19
  class OuwerkerkPlugin < Plugin
@@ -83,8 +84,7 @@ class TestOuwerkerkPlugin < Test::Unit::TestCase
83
84
  end
84
85
  def teardown
85
86
  if(File.exists? @plugin.file_path)
86
- #puts @plugin.file_path
87
- #File.delete(@plugin.file_path)
87
+ FileUtils.rm_f(@plugin.file_path)
88
88
  end
89
89
  ODBA.storage = nil
90
90
  end
@@ -1,10 +1,12 @@
1
1
  #!/usr/bin/env ruby
2
- # OneDirSuite -- oddb -- 20.10.2003 -- mhuggler@ywesee.com
2
+ # OneDirSuite -- oddb -- 08.02.2011 -- mhatakeyama@ywesee.com
3
3
 
4
4
  $: << File.expand_path(File.dirname(__FILE__))
5
5
 
6
- Dir.foreach(File.dirname(__FILE__)) { |file|
7
- if /.*\.rb$/o.match(file)&&file!='suite.rb'
8
- require file
9
- end
10
- }
6
+ Dir.open(File.dirname(__FILE__)) do |dir|
7
+ dir.sort.each do |file|
8
+ if /.*\.rb$/o.match(file)&&file!='suite.rb'
9
+ require file
10
+ end
11
+ end
12
+ end
@@ -616,74 +616,70 @@ Parse Errors: 0
616
616
  assert_nothing_raised do
617
617
  news = @plugin.fachinfo_news agent
618
618
  end
619
- assert_equal 248, news.size
620
- assert_equal ["13e742d9-f404-4681-ab82-71d347acfb93",
621
- "Abseamed®"], news.first
619
+ assert_equal 7, news.size
620
+ assert_equal "Abilify\302\256", news.first
622
621
  end
623
622
  def test_old_fachinfo_news
624
623
  ## no file means no news
625
624
  assert_equal [], @plugin.old_fachinfo_news
626
625
  File.open File.join(@vardir, 'fachinfo.txt'), 'w' do |fh|
627
626
  fh.puts <<-EOS
628
- c413ce2d-a88e-4d71-b6b9-1c55e021edc0 Amiodarone Winthrop\302\256/- Mite
629
- 1e5d1ba9-3073-47cb-8ebb-ecd3f88ecacf
627
+ Amiodarone Winthrop\302\256/- Mite
628
+ AcetaPhos\302\256 750 mg
630
629
  EOS
631
630
  end
632
631
  ## the file is parsed properly
633
632
  news = @plugin.old_fachinfo_news
634
633
  assert_equal 2, news.size
635
- assert_equal ["c413ce2d-a88e-4d71-b6b9-1c55e021edc0",
636
- "Amiodarone Winthrop\302\256/- Mite"], news.first
637
- ## the file is also parsed properly when names aren't included
638
- assert_equal ["1e5d1ba9-3073-47cb-8ebb-ecd3f88ecacf"], news.last
634
+ assert_equal "Amiodarone Winthrop\302\256/- Mite", news.first
639
635
  end
640
636
  def test_true_news
641
637
  ## there are no news
642
638
  news = [
643
- ["13e742d9-f404-4681-ab82-71d347acfb93", "Abseamed\302\256"],
644
- ["8a7f708c-c738-4425-a9a5-5ad294f20be4", "Aclasta\302\256"],
645
- ["01de437e-6568-4667-a3a6-00035098f59a", "Alcacyl\302\256 500 Instant-Pulver"],
646
- ["3ac0c14d-8c1a-4aed-9db6-f2dba58bc964", "Aldurazyme\302\256"],
647
- ["70893844-a876-4776-a61f-156e8465e47a", "Allopur\302\256"],
648
- ["3d808e28-3445-46e1-be00-68f053499bc1", "Allopurinol - 1 A Pharma100 mg/300 mg"],
649
- ["b287ecf9-84c2-48f0-b0c0-2dd9cff30d1f", "Amavita Acetylcystein 600"],
650
- ["78163fd4-6cf0-40ea-91b8-06c258722a7d", "Amavita Carbocistein"],
651
- ["1885f45a-b9df-4462-adb9-c46140859835", "Amavita Ibuprofen 400"],
652
- ["0a717d39-a873-4bff-87ab-b6b08b861da0", "Amavita Paracetamol 500"]
639
+ "Abseamed\302\256",
640
+ "Aclasta\302\256",
641
+ "Alcacyl\302\256 500 Instant-Pulver",
642
+ "Aldurazyme\302\256",
643
+ "Allopur\302\256",
644
+ "Allopurinol - 1 A Pharma100 mg/300 mg",
645
+ "Amavita Acetylcystein 600",
646
+ "Amavita Carbocistein",
647
+ "Amavita Ibuprofen 400",
648
+ "Amavita Paracetamol 500"
653
649
  ]
654
650
  old_news = [
655
- ["13e742d9-f404-4681-ab82-71d347acfb93", "Abseamed\302\256"],
656
- ["8a7f708c-c738-4425-a9a5-5ad294f20be4", "Aclasta\302\256"],
651
+ "Abseamed\302\256",
652
+ "Aclasta\302\256",
657
653
  ]
658
- assert_equal [], @plugin.true_news(news, old_news)
654
+ expected_news = [
655
+ "Alcacyl\302\256 500 Instant-Pulver",
656
+ "Aldurazyme\302\256",
657
+ "Allopur\302\256",
658
+ "Allopurinol - 1 A Pharma100 mg/300 mg",
659
+ "Amavita Acetylcystein 600",
660
+ "Amavita Carbocistein",
661
+ "Amavita Ibuprofen 400",
662
+ "Amavita Paracetamol 500"
663
+ ]
664
+ assert_equal expected_news, @plugin.true_news(news, old_news)
659
665
  ## clean disection
660
666
  old_news = [
661
- ["3d808e28-3445-46e1-be00-68f053499bc1", "Allopurinol - 1 A Pharma100 mg/300 mg"],
662
- ["b287ecf9-84c2-48f0-b0c0-2dd9cff30d1f", "Amavita Acetylcystein 600"],
663
- ["78163fd4-6cf0-40ea-91b8-06c258722a7d", "Amavita Carbocistein"],
664
- ["1885f45a-b9df-4462-adb9-c46140859835", "Amavita Ibuprofen 400"],
665
- ["0a717d39-a873-4bff-87ab-b6b08b861da0", "Amavita Paracetamol 500"]
667
+ "Allopurinol - 1 A Pharma100 mg/300 mg",
668
+ "Amavita Acetylcystein 600",
669
+ "Amavita Carbocistein",
670
+ "Amavita Ibuprofen 400",
671
+ "Amavita Paracetamol 500"
666
672
  ]
667
673
  expected = [
668
- ["13e742d9-f404-4681-ab82-71d347acfb93", "Abseamed\302\256"],
669
- ["8a7f708c-c738-4425-a9a5-5ad294f20be4", "Aclasta\302\256"],
670
- ["01de437e-6568-4667-a3a6-00035098f59a", "Alcacyl\302\256 500 Instant-Pulver"],
671
- ["3ac0c14d-8c1a-4aed-9db6-f2dba58bc964", "Aldurazyme\302\256"],
672
- ["70893844-a876-4776-a61f-156e8465e47a", "Allopur\302\256"],
673
- ]
674
- assert_equal expected, @plugin.true_news(news, old_news)
675
- ## disection also works for ids recorded without name
676
- old_news = [
677
- ["3d808e28-3445-46e1-be00-68f053499bc1"],
678
- ["b287ecf9-84c2-48f0-b0c0-2dd9cff30d1f"],
679
- ["78163fd4-6cf0-40ea-91b8-06c258722a7d"],
680
- ["1885f45a-b9df-4462-adb9-c46140859835"],
681
- ["0a717d39-a873-4bff-87ab-b6b08b861da0"]
674
+ "Abseamed\302\256",
675
+ "Aclasta\302\256",
676
+ "Alcacyl\302\256 500 Instant-Pulver",
677
+ "Aldurazyme\302\256",
678
+ "Allopur\302\256",
682
679
  ]
683
680
  assert_equal expected, @plugin.true_news(news, old_news)
684
681
  ## recorded news don't appear on the news-page
685
- old_news = [["c413ce2d-a88e-4d71-b6b9-1c55e021edc0",
686
- "Amiodarone Winthrop\302\256/- Mite"]]
682
+ old_news = ["Amiodarone Winthrop\302\256/- Mite"]
687
683
  assert_equal news, @plugin.true_news(news, old_news)
688
684
  end
689
685
  def test_search_product
@@ -766,18 +762,10 @@ c413ce2d-a88e-4d71-b6b9-1c55e021edc0 Amiodarone Winthrop\302\256/- Mite
766
762
  @parser.should_receive(:parse_patinfo_html).and_return PatinfoDocument.new
767
763
  @app.should_receive(:sorted_fachinfos).and_return []
768
764
  success = @plugin.import_news agent
769
- expected = <<-EOS
770
- 13e742d9-f404-4681-ab82-71d347acfb93 Abseamed®
771
- 8a7f708c-c738-4425-a9a5-5ad294f20be4 Aclasta®
772
- EOS
765
+ expected = "Abilify\302\256\nAbilify\302\256 Injektionsl\303\266sung\nAbseamed\302\256\nAceril\302\256- mite\nAcetaPhos\302\256 750 mg\nAcimethin\302\256\nAclasta\302\256"
773
766
  assert_equal 5, @pages.size
774
767
  assert_equal expected, File.read(logfile)
775
768
  assert_equal true, success
776
769
  end
777
- def test_extract_fachinfo_id
778
- href = 'http://textinfo.ch/Monographie.aspx?Id=3914c196-70d8-43b7-816d-8fe923649740&lang=de&MonType=fi'
779
- assert_equal '3914c196-70d8-43b7-816d-8fe923649740',
780
- @plugin.extract_fachinfo_id(href)
781
- end
782
770
  end
783
771
  end
@@ -0,0 +1,500 @@
1
+ #!/usr/bin/env ruby
2
+ # TestExporter -- oddb -- 07.02.2011 -- mhatakeyama@ywesee.com
3
+
4
+ $: << File.expand_path("../../src", File.dirname(__FILE__))
5
+
6
+ require 'test/unit'
7
+ require 'flexmock'
8
+ require 'util/exporter'
9
+ require 'util/log'
10
+ require 'date'
11
+
12
+ module ODDB
13
+ include FlexMock::TestCase
14
+ class StubDRbObject
15
+ def clear
16
+ end
17
+ end
18
+ class Exporter
19
+ remove_const :EXPORT_SERVER
20
+ EXPORT_SERVER = StubDRbObject.new
21
+ end
22
+ class TestExporter < Test::Unit::TestCase
23
+ include FlexMock::TestCase
24
+ def test_test
25
+ assert(true)
26
+ end
27
+ def setup
28
+ @app = flexmock('app')
29
+ @exporter = ODDB::Exporter.new(@app)
30
+ flexstub(@exporter).should_receive(:sleep).and_return('sleep')
31
+ @log = flexmock('log') do |log|
32
+ log.should_receive(:report)
33
+ log.should_receive(:notify)
34
+ log.should_receive(:report=)
35
+ log.should_receive(:date_str=)
36
+ end
37
+
38
+ # plugins
39
+ # @plugins will be modifed depending on a test-case in each test method
40
+ @plugin = flexmock('plugin')
41
+ flexstub(OdbaExporter::OddbDatExport).should_receive(:new).and_return(@plugin)
42
+ flexstub(SwissmedicPlugin).should_receive(:new).and_return(@plugin)
43
+ flexstub(XlsExportPlugin).should_receive(:new).and_return(@plugin)
44
+ flexstub(CsvExportPlugin).should_receive(:new).and_return(@plugin)
45
+ flexstub(FiPDFExporter).should_receive(:new).and_return(@plugin)
46
+ flexstub(OuwerkerkPlugin).should_receive(:new).and_return(@plugin)
47
+ flexstub(YamlExporter).should_receive(:new).and_return(@plugin)
48
+ flexstub(DownloadInvoicer).should_receive(:new).and_return(@plugin)
49
+ flexstub(FachinfoInvoicer).should_receive(:new).and_return(@plugin)
50
+ flexstub(PatinfoInvoicer).should_receive(:new).and_return(@plugin)
51
+ end
52
+ def test_export_oddbdat__on_sunday
53
+ flexstub(@exporter, :today => Date.new(2011,1,2))
54
+ flexstub(Log) do |logclass|
55
+ # white box test: Log.new is never called
56
+ # if dose_missing_list is not empty or an error raises,
57
+ # Log.new will be called
58
+ logclass.should_receive(:new).times(0).and_return(@log)
59
+ end
60
+ flexstub(@plugin) do |exporter|
61
+ exporter.should_receive(:export).and_return([]) # this is the key point
62
+ end
63
+
64
+ # the 'nil' means 'if' condition runs, otherwise it may indicate an error
65
+ assert_equal(nil, @exporter.export_oddbdat)
66
+ end
67
+ def test_export_oddbdat__on_monday
68
+ flexstub(@exporter, :today => Date.new(2011,1,3)) # Monday
69
+ flexstub(Log) do |logclass|
70
+ logclass.should_receive(:new).times(0).and_return(@log)
71
+ end
72
+ flexstub(@plugin) do |exporter|
73
+ exporter.should_receive(:export).and_return([]) # this is the key point
74
+ exporter.should_receive(:export_fachinfos).once.with_no_args
75
+ end
76
+
77
+ assert_equal(nil, @exporter.export_oddbdat)
78
+ end
79
+ def test_export_oddbdat__dose_missing
80
+ flexstub(Log) do |logclass|
81
+ # white box test: Log.new is once called because of dose data missing
82
+ logclass.should_receive(:new).times(1).and_return(@log)
83
+ end
84
+ flexstub(@plugin) do |exporter|
85
+ exporter.should_receive(:export).and_return(['dose_missing']) # this is the key point
86
+ end
87
+
88
+ assert_equal(nil, @exporter.export_oddbdat)
89
+ end
90
+ def test_run__on_1st_day
91
+ # totally whilte box test
92
+ flexstub(@exporter) do |exp|
93
+ exp.should_receive(:today).and_return(Date.new(2011,1,1)) # Saturday
94
+ exp.should_receive(:mail_patinfo_invoices).once.with_no_args
95
+ exp.should_receive(:mail_fachinfo_log).once.with_no_args
96
+ exp.should_receive(:mail_download_invoices).once.with_no_args
97
+ exp.should_receive(:mail_download_stats).times(0).with_no_args
98
+ exp.should_receive(:mail_feedback_stats).times(0).with_no_args
99
+ exp.should_receive(:export_sl_pcodes).once.with_no_args
100
+ exp.should_receive(:export_yaml).once.with_no_args
101
+ exp.should_receive(:export_oddbdat).once.with_no_args
102
+ exp.should_receive(:export_csv).once.with_no_args
103
+ exp.should_receive(:export_doc_csv).once.with_no_args
104
+ exp.should_receive(:export_index_therapeuticus_csv).once.with_no_args
105
+ exp.should_receive(:export_price_history_csv).once.with_no_args
106
+ end
107
+ assert_equal(nil, @exporter.run)
108
+ end
109
+ def test_run__on_15th_day
110
+ flexstub(@exporter) do |exp|
111
+ exp.should_receive(:today).and_return(Date.new(2011,1,15)) # Saturday
112
+ exp.should_receive(:mail_patinfo_invoices).once.with_no_args
113
+ exp.should_receive(:mail_fachinfo_log).once.with_no_args
114
+ exp.should_receive(:mail_download_invoices).once.with_no_args
115
+ exp.should_receive(:mail_download_stats).times(0).with_no_args
116
+ exp.should_receive(:mail_feedback_stats).times(0).with_no_args
117
+ exp.should_receive(:export_sl_pcodes).once.with_no_args
118
+ exp.should_receive(:export_yaml).once.with_no_args
119
+ exp.should_receive(:export_oddbdat).once.with_no_args
120
+ exp.should_receive(:export_csv).once.with_no_args
121
+ exp.should_receive(:export_doc_csv).once.with_no_args
122
+ exp.should_receive(:export_index_therapeuticus_csv).once.with_no_args
123
+ exp.should_receive(:export_price_history_csv).once.with_no_args
124
+ end
125
+ assert_equal(nil, @exporter.run)
126
+ end
127
+ def test_run__on_sunday
128
+ flexstub(@exporter) do |exp|
129
+ exp.should_receive(:today).and_return(Date.new(2011,1,2)) # Sunday
130
+ exp.should_receive(:mail_patinfo_invoices).once.with_no_args
131
+ exp.should_receive(:mail_fachinfo_log).once.with_no_args
132
+ exp.should_receive(:mail_download_invoices).times(0).with_no_args
133
+ exp.should_receive(:mail_download_stats).once.with_no_args
134
+ exp.should_receive(:mail_feedback_stats).once.with_no_args
135
+ exp.should_receive(:export_sl_pcodes).once.with_no_args
136
+ exp.should_receive(:export_yaml).once.with_no_args
137
+ exp.should_receive(:export_oddbdat).once.with_no_args
138
+ exp.should_receive(:export_csv).once.with_no_args
139
+ exp.should_receive(:export_doc_csv).once.with_no_args
140
+ exp.should_receive(:export_index_therapeuticus_csv).once.with_no_args
141
+ exp.should_receive(:export_price_history_csv).once.with_no_args
142
+ end
143
+ assert_equal(nil, @exporter.run)
144
+ end
145
+ def test_export_helper
146
+ flexstub(Exporter::EXPORT_SERVER) do |exp|
147
+ exp.should_receive(:remote_safe_export).and_yield('path')
148
+ end
149
+ @exporter.export_helper('name') do |path|
150
+ assert_equal('path', path)
151
+ end
152
+ end
153
+ def test_export_all_csv
154
+ # totally white box test
155
+ flexstub(@exporter) do |exp|
156
+ exp.should_receive(:export_csv).once.with_no_args
157
+ exp.should_receive(:export_doc_csv).once.with_no_args
158
+ exp.should_receive(:export_index_therapeuticus_csv).once.with_no_args
159
+ exp.should_receive(:export_price_history_csv).once.with_no_args.and_return('export_price_history_csv')
160
+ end
161
+ assert_equal('export_price_history_csv', @exporter.export_all_csv)
162
+ end
163
+ def test_export_competition_xls
164
+ flexstub(@plugin) do |plug|
165
+ plug.should_receive(:export_competition)
166
+ end
167
+ assert_equal(@plugin, @exporter.export_competition_xls('company'))
168
+ end
169
+ def test_export_csv
170
+ flexstub(@plugin) do |plug|
171
+ plug.should_receive(:export_drugs)
172
+ plug.should_receive(:export_drugs_extended)
173
+ end
174
+ assert_equal('sleep', @exporter.export_csv)
175
+ end
176
+ def test_export_csv__errorcase1
177
+ flexstub(@plugin) do |plug|
178
+ plug.should_receive(:export_drugs).and_raise(StandardError)
179
+ plug.should_receive(:export_drugs_extended)
180
+ end
181
+ flexstub(Log) do |logclass|
182
+ # white box test: Log.new is once called because of error
183
+ logclass.should_receive(:new).times(1).and_return(@log)
184
+ end
185
+ assert_equal('sleep', @exporter.export_csv)
186
+ end
187
+ def test_export_csv__errorcase2
188
+ flexstub(@plugin) do |plug|
189
+ plug.should_receive(:export_drugs)
190
+ plug.should_receive(:export_drugs_extended).and_raise(StandardError)
191
+ end
192
+ flexstub(Log) do |logclass|
193
+ # white box test: Log.new is once called because of error
194
+ logclass.should_receive(:new).times(1).and_return(@log)
195
+ end
196
+ assert_equal('sleep', @exporter.export_csv)
197
+ end
198
+ def test_export_analysis_csv
199
+ flexstub(@plugin) do |plug|
200
+ plug.should_receive(:export_analysis)
201
+ end
202
+ assert_equal('sleep', @exporter.export_analysis_csv)
203
+ end
204
+ def test_export_doc_csv
205
+ flexstub(@plugin) do |plug|
206
+ plug.should_receive(:export_doctors)
207
+ end
208
+ assert_equal('sleep', @exporter.export_doc_csv)
209
+ end
210
+ def test_export_doc_csv__error
211
+ flexstub(@plugin) do |plug|
212
+ plug.should_receive(:export_doctors).and_raise(StandardError)
213
+ end
214
+ flexstub(Log) do |logclass|
215
+ # white box test: Log.new is once called because of error
216
+ logclass.should_receive(:new).times(1).and_return(@log)
217
+ end
218
+ assert_equal('sleep', @exporter.export_doc_csv)
219
+ end
220
+ def test_export_fachinfo_pdf
221
+ # this method will be removed
222
+ end
223
+ def test_export_generics_xls
224
+ flexstub(@plugin) do |plug|
225
+ plug.should_receive(:export_generics)
226
+ end
227
+ assert_equal(@plugin, @exporter.export_generics_xls)
228
+ end
229
+ def test_export_swissdrug_xls
230
+ flexstub(@plugin) do |plug|
231
+ plug.should_receive(:export_xls)
232
+ plug.should_receive(:file_path)
233
+ end
234
+ flexstub(FileUtils).should_receive(:cp)
235
+ flexstub(Exporter::EXPORT_SERVER).should_receive(:compress)
236
+ assert_equal(@plugin, @exporter.export_swissdrug_xls)
237
+ end
238
+ def test_export_index_therapeuticus_csv
239
+ flexstub(@plugin) do |plug|
240
+ plug.should_receive(:export_index_therapeuticus)
241
+ end
242
+ assert_equal('sleep', @exporter.export_index_therapeuticus_csv)
243
+ end
244
+ def test_export_index_therapeuticus_csv__error
245
+ flexstub(@plugin) do |plug|
246
+ plug.should_receive(:export_index_therapeuticus).and_raise(StandardError)
247
+ end
248
+ flexstub(Log) do |logclass|
249
+ # white box test: Log.new is once called because of error
250
+ logclass.should_receive(:new).times(1).and_return(@log)
251
+ end
252
+ assert_equal('sleep', @exporter.export_index_therapeuticus_csv)
253
+ end
254
+ def test_export_migel_csv
255
+ flexstub(@plugin) do |plug|
256
+ plug.should_receive(:export_migel)
257
+ end
258
+ assert_equal('sleep', @exporter.export_migel_csv)
259
+ end
260
+ def test_export_narcotics_csv
261
+ flexstub(@plugin) do |plug|
262
+ plug.should_receive(:export_narcotics)
263
+ end
264
+ assert_equal('sleep', @exporter.export_narcotics_csv)
265
+ end
266
+ def test_export_pdf
267
+ flexstub(@plugin) do |plug|
268
+ plug.should_receive(:run).and_return('run')
269
+ end
270
+ assert_equal('run', @exporter.export_pdf)
271
+ end
272
+ def test_export_sl_pcodes
273
+ flexstub(@app) do |app|
274
+ app.should_receive(:each_package).and_yield(flexmock('pac') do |pac|
275
+ pac.should_receive(:sl_entry).and_return(true)
276
+ pac.should_receive(:pharmacode).and_return('pharmacode')
277
+ end)
278
+ end
279
+
280
+ # test
281
+ expected = 'pharmacode'
282
+ fh = flexmock('file_pointer') do |file_pointer|
283
+ file_pointer.should_receive(:puts).with(expected)
284
+ end
285
+ flexstub(File) do |file|
286
+ file.should_receive(:open).and_yield(fh)
287
+ end
288
+ assert_equal(nil, @exporter.export_sl_pcodes)
289
+ end
290
+ def test_export_sl_pcodes__error
291
+ flexstub(File) do |file|
292
+ file.should_receive(:open).and_raise(StandardError)
293
+ end
294
+ flexstub(Log) do |logclass|
295
+ # white box test: Log.new is once called because of error
296
+ logclass.should_receive(:new).times(1).and_return(@log)
297
+ end
298
+ assert_equal('sleep', @exporter.export_sl_pcodes)
299
+ end
300
+ def test_export_patents_xls
301
+ flexstub(@plugin) do |plug|
302
+ plug.should_receive(:export_patents)
303
+ end
304
+ assert_equal(@plugin, @exporter.export_patents_xls)
305
+ end
306
+ def test_export_yaml__on_monday
307
+ flexstub(@exporter, :today => Date.new(2011,1,3)) # Monday
308
+ # totally white box test
309
+ flexstub(@plugin) do |plug|
310
+ plug.should_receive(:export).once.with_no_args
311
+ plug.should_receive(:export_atc_classes).once.with_no_args
312
+ plug.should_receive(:export_interactions).once.with_no_args
313
+ plug.should_receive(:export_narcotics).once.with_no_args
314
+ plug.should_receive(:export_prices).once.with_no_args
315
+ plug.should_receive(:export_fachinfos).times(0).with_no_args
316
+ plug.should_receive(:export_patinfos).times(0).with_no_args
317
+ plug.should_receive(:export_doctors).times(0).with_no_args
318
+ end
319
+ assert_equal('sleep', @exporter.export_yaml)
320
+ end
321
+ def test_export_yaml__on_tuesday
322
+ flexstub(@exporter, :today => Date.new(2011,1,4)) # Tuesday
323
+ # totally white box test
324
+ flexstub(@plugin) do |plug|
325
+ plug.should_receive(:export).once.with_no_args
326
+ plug.should_receive(:export_atc_classes).once.with_no_args
327
+ plug.should_receive(:export_interactions).once.with_no_args
328
+ plug.should_receive(:export_narcotics).once.with_no_args
329
+ plug.should_receive(:export_prices).once.with_no_args
330
+ plug.should_receive(:export_fachinfos).once.with_no_args
331
+ plug.should_receive(:export_patinfos).times(0).with_no_args
332
+ plug.should_receive(:export_doctors).times(0).with_no_args
333
+ end
334
+ assert_equal('sleep', @exporter.export_yaml)
335
+ end
336
+ def test_export_yaml__on_wednesday
337
+ flexstub(@exporter, :today => Date.new(2011,1,5)) # Wednesday
338
+ # totally white box test
339
+ flexstub(@plugin) do |plug|
340
+ plug.should_receive(:export).once.with_no_args
341
+ plug.should_receive(:export_atc_classes).once.with_no_args
342
+ plug.should_receive(:export_interactions).once.with_no_args
343
+ plug.should_receive(:export_narcotics).once.with_no_args
344
+ plug.should_receive(:export_prices).once.with_no_args
345
+ plug.should_receive(:export_fachinfos).times(0).with_no_args
346
+ plug.should_receive(:export_patinfos).once.with_no_args
347
+ plug.should_receive(:export_doctors).times(0).with_no_args
348
+ end
349
+ assert_equal('sleep', @exporter.export_yaml)
350
+ end
351
+ def test_export_yaml__on_thursday
352
+ flexstub(@exporter, :today => Date.new(2011,1,6)) # Tursday
353
+ # totally white box test
354
+ flexstub(@plugin) do |plug|
355
+ plug.should_receive(:export).once.with_no_args
356
+ plug.should_receive(:export_atc_classes).once.with_no_args
357
+ plug.should_receive(:export_interactions).once.with_no_args
358
+ plug.should_receive(:export_narcotics).once.with_no_args
359
+ plug.should_receive(:export_prices).once.with_no_args
360
+ plug.should_receive(:export_fachinfos).times(0).with_no_args
361
+ plug.should_receive(:export_patinfos).times(0).with_no_args
362
+ plug.should_receive(:export_doctors).once.with_no_args
363
+ end
364
+ assert_equal('sleep', @exporter.export_yaml)
365
+ end
366
+ def test_mail_download_stats
367
+ flexstub(Log) do |logclass|
368
+ # white box test: Log.new is once called in any case
369
+ logclass.should_receive(:new).times(1).and_return(@log)
370
+ end
371
+ flexstub(File).should_receive(:read)
372
+ flexstub(LogFile).should_receive(:filename).times(1).with('download', Date)
373
+ assert_equal(nil, @exporter.mail_download_stats)
374
+ end
375
+ def test_mail_download_invoices
376
+ flexstub(@plugin) do |plug|
377
+ plug.should_receive(:run).and_return('run')
378
+ end
379
+ assert_equal('run', @exporter.mail_download_invoices)
380
+ end
381
+ def test_mail_fachinfo_log__noreport
382
+ flexstub(@plugin) do |plug|
383
+ plug.should_receive(:run)
384
+ plug.should_receive(:report).and_return(nil)
385
+ end
386
+ assert_equal(nil, @exporter.mail_fachinfo_log)
387
+ end
388
+ def test_mail_fachinfo_log__report
389
+ flexstub(@plugin) do |plug|
390
+ plug.should_receive(:run)
391
+ plug.should_receive(:report).and_return('report')
392
+ end
393
+ flexstub(Log) do |logclass|
394
+ # white box test: Log.new is once called if there is a report
395
+ logclass.should_receive(:new).times(1).and_return(@log)
396
+ end
397
+ assert_equal(nil, @exporter.mail_fachinfo_log)
398
+ end
399
+
400
+ def test_mail_feedback_stats
401
+ flexstub(Log) do |logclass|
402
+ # white box test: Log.new is once called in any case
403
+ logclass.should_receive(:new).times(1).and_return(@log)
404
+ end
405
+ flexstub(File).should_receive(:read)
406
+ flexstub(LogFile).should_receive(:filename).times(1).with('feedback', Date)
407
+ assert_equal(nil, @exporter.mail_feedback_stats)
408
+ end
409
+ def test_mail_notification_stats
410
+ flexstub(@app) do |app|
411
+ app.should_receive(:"notification_logger.create_csv").and_return('file')
412
+ end
413
+ flexstub(@log) do |log|
414
+ log.should_receive(:notify_attachment).with('file', Hash).and_return('notify_attachment')
415
+ end
416
+ flexstub(Log) do |logclass|
417
+ # white box test: Log.new is once called
418
+ logclass.should_receive(:new).times(1).and_return(@log)
419
+ end
420
+ assert_equal('notify_attachment', @exporter.mail_notification_stats)
421
+ end
422
+ def test_mail_patinfo_invoice
423
+ flexstub(@plugin) do |plug|
424
+ plug.should_receive(:run).and_return('run')
425
+ end
426
+ assert_equal('run', @exporter.mail_patinfo_invoices)
427
+ end
428
+ def test_export_price_history_csv
429
+ flexstub(@plugin) do |plug|
430
+ plug.should_receive(:export_price_history)
431
+ end
432
+ flexstub(Log) do |logclass|
433
+ # white box test: Log.new is never called
434
+ logclass.should_receive(:new).times(0).and_return(@log)
435
+ end
436
+ assert_equal('sleep', @exporter.export_price_history_csv)
437
+ end
438
+ def test_export_price_history_csv
439
+ flexstub(@plugin) do |plug|
440
+ plug.should_receive(:export_price_history).and_raise(StandardError)
441
+ end
442
+ flexstub(Log) do |logclass|
443
+ # white box test: Log.new is once called if there is an error
444
+ logclass.should_receive(:new).times(1).and_return(@log)
445
+ end
446
+ assert_equal('sleep', @exporter.export_price_history_csv)
447
+ end
448
+ def test_mail_stats__before_8th
449
+ flexstub(@exporter, :today => Date.new(2011,1,5))
450
+ flexstub(Log) do |logclass|
451
+ # white box test: Log.new is once called in any case
452
+ logclass.should_receive(:new).times(1).and_return(@log)
453
+ end
454
+ flexstub(File).should_receive(:read)
455
+
456
+ # test
457
+ expected_date = Date.new(2010,12,5)
458
+ flexstub(LogFile).should_receive(:filename).with('key', expected_date)
459
+ assert_equal(nil, @exporter.mail_stats('key'))
460
+ end
461
+ def test_mail_stats__after_8th
462
+ flexstub(@exporter, :today => Date.new(2011,1,10))
463
+ flexstub(Log) do |logclass|
464
+ # white box test: Log.new is once called in any case
465
+ logclass.should_receive(:new).times(1).and_return(@log)
466
+ end
467
+ flexstub(File).should_receive(:read)
468
+
469
+ # test
470
+ expected_date = Date.new(2011,1,10)
471
+ flexstub(LogFile).should_receive(:filename).with('key', expected_date)
472
+ assert_equal(nil, @exporter.mail_stats('key'))
473
+ end
474
+ def test_mail_swissmedic_notifications
475
+ flexstub(@plugin) do |plug|
476
+ plug.should_receive(:mail_notifications).and_return('mail_notifications')
477
+ end
478
+ assert_equal('mail_notifications', @exporter.mail_swissmedic_notifications)
479
+ end
480
+ def test_safe_export
481
+ flexstub(Log) do |logclass|
482
+ # white box test: Log.new is never called if there is no error
483
+ logclass.should_receive(:new).times(0).and_return(@log)
484
+ end
485
+ @exporter.safe_export('test_safe_export') do
486
+ 'no error'
487
+ end
488
+ end
489
+ def test_safe_export__error
490
+ flexstub(Log) do |logclass|
491
+ # white box test: Log.new is never called if there is no error
492
+ logclass.should_receive(:new).times(1).and_return(@log)
493
+ end
494
+ @exporter.safe_export('test_safe_export') do
495
+ raise
496
+ end
497
+ end
498
+ end
499
+ end
500
+