view · edit · sidebar · attach · print · history

20100913 test-import_gkv

<< Masa.20100914-test-import_gkv | 2010 | Masa.20100910-import_gkv-error >>


  1. ch.ODDB.org Report
  2. Check test/util/test_updater.rb
  3. Focus on test_run
  4. Check 2010-05-12 Hannes Wyss Add external Job for importing dimdi-data
  5. Read run_logged_job method
  6. Add test_import_dimdi
  7. Fix test_run__errors
  8. Fix test_run__later_errors
  9. Add test_import_gkv
  10. Flexmock Practice

Goal
  • test import_gkv / 100%
Milestones
  1. Check test/util/test_updater.rb 9:00
  2. Look at the diff / BraSt
  3. Fix test_updater.rb test_run 12:15
  4. Add test_import_dimdi method 14:00
  5. Fix test_updater.rb test_run__errors 15:30
  6. Fix test_updater.rb test_run__later_errors 15:30
  7. Add test_import_gkv method
Summary
Commits
ToDo Tomorrow
  1. 20100907 Ticket 242, Comment 9 - notification Mail
  2. Dimdi-Import-Error.
Keep in Mind
Attached Files

ch.ODDB.org Report Error

Nothing to Report.

Errno::ENOENT
No such file or directory - /var/www/oddb.org/log/download/2010/09.log
/var/www/oddb.org/src/util/exporter.rb:274:in `read'
/var/www/oddb.org/src/util/exporter.rb:274:in `mail_stats'
/var/www/oddb.org/src/util/exporter.rb:220:in `mail_download_stats'
/var/www/oddb.org/src/util/exporter.rb:289:in `call'
/var/www/oddb.org/src/util/exporter.rb:289:in `safe_export'
/var/www/oddb.org/src/util/exporter.rb:219:in `mail_download_stats'
/var/www/oddb.org/src/util/exporter.rb:45:in `run'
/var/www/oddb.org/src/util/schedule.rb:14:in `call'
/var/www/oddb.org/src/util/schedule.rb:14:in `run_on_weekday'
/var/www/oddb.org/src/util/exporter.rb:44:in `run'
/var/www/oddb.org/jobs/export_daily:13
/var/www/oddb.org/src/util/job.rb:17:in `call'
/var/www/oddb.org/src/util/job.rb:17:in `run'
/var/www/oddb.org/jobs/export_daily:12

This is not an error.

Davatz-san's mail

This is not an error. This means there was nothing donwloaded during the week. That is why it says "Nothing to report.

Check test/util/test_updater.rb

ruby test/util/test_updater.rb

masa@masa ~/ywesee/de.oddb.org $ ruby test/util/test_updater.rb 
/home/masa/ywesee/de.oddb.org/test/stub/model.rb:172: warning: already initialized constant Currency
Loaded suite test/util/test_updater
Started
FFF
Finished in 0.030296 seconds.

  1) Failure:
test_run(ODDB::Util::TestUpdater)
    [test/util/test_updater.rb:55:in `test_run'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation.rb:78:in `call'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation.rb:78:in `return_value'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation.rb:59:in `verify_call'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation_director.rb:42:in `call'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/core.rb:101:in `method_missing'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/core.rb:191:in `flexmock_wrap'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/core.rb:98:in `method_missing'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/partial_mock.rb:255:in `popen'
     /home/masa/ywesee/de.oddb.org/lib/oddb/util/updater.rb:150:in `run_logged_job'
     /home/masa/ywesee/de.oddb.org/lib/oddb/util/updater.rb:136:in `run'
     test/util/test_updater.rb:57:in `test_run']:
in mock 'flexmock(Class)': <"/home/masa/ywesee/de.oddb.org/jobs/import_gkv log_file=/home/masa/ywesee/de.oddb.org/log/import_gkv"> expected but was
<"/home/masa/ywesee/de.oddb.org/jobs/import_dimdi log_file=/home/masa/ywesee/de.oddb.org/log/import_dimdi">.

  2) Failure:
test_run__errors(ODDB::Util::TestUpdater) [test/util/test_updater.rb:78]:
<RuntimeError> exception expected but was
Class: <Test::Unit::AssertionFailedError>
Message: <"in mock 'flexmock(Class)': <\"/home/masa/ywesee/de.oddb.org/jobs/import_gkv log_file=/home/masa/ywesee/de.oddb.org/log/import_gkv\"> expected but was\n<\"/home/masa/ywesee/de.oddb.org/jobs/import_dimdi log_file=/home/masa/ywesee/de.oddb.org/log/import_dimdi\">.">
---Backtrace---
test/util/test_updater.rb:76:in `test_run__errors'
/usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation.rb:78:in `call'
/usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation.rb:78:in `return_value'
/usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation.rb:59:in `verify_call'
/usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation_director.rb:42:in `call'
/usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/core.rb:101:in `method_missing'
/usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/core.rb:191:in `flexmock_wrap'
/usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/core.rb:98:in `method_missing'
/usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/partial_mock.rb:255:in `popen'
/home/masa/ywesee/de.oddb.org/lib/oddb/util/updater.rb:150:in `run_logged_job'
/home/masa/ywesee/de.oddb.org/lib/oddb/util/updater.rb:136:in `run'
test/util/test_updater.rb:79:in `test_run__errors'
test/util/test_updater.rb:78:in `test_run__errors'
---------------

  3) Failure:
test_run__later_errors(ODDB::Util::TestUpdater)
    [test/util/test_updater.rb:102:in `test_run__later_errors'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation.rb:78:in `call'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation.rb:78:in `return_value'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation.rb:59:in `verify_call'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation_director.rb:42:in `call'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/core.rb:101:in `method_missing'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/core.rb:191:in `flexmock_wrap'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/core.rb:98:in `method_missing'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/partial_mock.rb:255:in `popen'
     /home/masa/ywesee/de.oddb.org/lib/oddb/util/updater.rb:150:in `run_logged_job'
     /home/masa/ywesee/de.oddb.org/lib/oddb/util/updater.rb:136:in `run'
     test/util/test_updater.rb:105:in `test_run__later_errors'
     test/util/test_updater.rb:104:in `test_run__later_errors']:
in mock 'flexmock(Class)': <"/home/masa/ywesee/de.oddb.org/jobs/import_gkv log_file=/home/masa/ywesee/de.oddb.org/log/import_gkv"> expected but was
<"/home/masa/ywesee/de.oddb.org/jobs/import_dimdi log_file=/home/masa/ywesee/de.oddb.org/log/import_dimdi">.

3 tests, 3 assertions, 3 failures, 0 errors

Search the commit that has not failure and no error.

Focus on test_run

masa@masa ~/ywesee/de.oddb.org $ ruby test/util/test_updater.rb 
/home/masa/ywesee/de.oddb.org/test/stub/model.rb:172: warning: already initialized constant Currency
Loaded suite test/util/test_updater
Started
F
Finished in 0.021089 seconds.

  1) Failure:
test_run(ODDB::Util::TestUpdater)
    [test/util/test_updater.rb:55:in `test_run'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation.rb:78:in `call'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation.rb:78:in `return_value'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation.rb:59:in `verify_call'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation_director.rb:42:in `call'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/core.rb:101:in `method_missing'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/core.rb:191:in `flexmock_wrap'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/core.rb:98:in `method_missing'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/partial_mock.rb:255:in `popen'
     /home/masa/ywesee/de.oddb.org/lib/oddb/util/updater.rb:150:in `run_logged_job'
     /home/masa/ywesee/de.oddb.org/lib/oddb/util/updater.rb:136:in `run'
     test/util/test_updater.rb:57:in `test_run']:
in mock 'flexmock(Class)': <"/home/masa/ywesee/de.oddb.org/jobs/import_gkv log_file=/home/masa/ywesee/de.oddb.org/log/import_gkv"> expected but was
<"/home/masa/ywesee/de.oddb.org/jobs/import_dimdi log_file=/home/masa/ywesee/de.oddb.org/log/import_dimdi">.

1 tests, 1 assertions, 1 failures, 0 errors

Modified

      def test_run
        today = Date.new(2006,10)
        flexmock(Util::Mail).should_receive(:notify_admins)\
          .with(String, Array).times(3)
        dimdi = flexmock(Import::Dimdi)
        dimdi.should_receive(:current_date).and_return today
        dimdi_files = %w{wirkkurz_011006.xls darform_011006.xls fb_011006.xls}
        download = StringIO.new('downloaded from dimdi')
        dimdi.should_receive(:download).times(3).and_return do |file, block|
          assert_equal dimdi_files.shift, file
          block.call download
        end
        flexmock(Import::Dimdi::GalenicForm).new_instances.should_receive(:import).with(download).times(1).and_return []
        flexmock(Import::Dimdi::Product).new_instances.should_receive(:import).with(download).times(1).and_return []
        flexmock(Import::Dimdi::Substance).new_instances.should_receive(:import).with(download).times(1).and_return []
        job_dir = File.join ODDB.config.oddb_dir, 'jobs'
        log_dir = File.join ODDB.config.oddb_dir, 'log'
        #cmds = %w{import_gkv import_pharmnet import_whocc}
        cmds = %w{import_dimdi import_gkv import_pharmnet import_whocc}
        flexmock(IO).should_receive(:popen).and_return do |popen, block|
          cmd = cmds.shift
          assert_equal "#{job_dir}/#{cmd} log_file=#{log_dir}/#{cmd}", popen
        end
        @updater.run(today)
      end

Result

masa@masa ~/ywesee/de.oddb.org $ ruby test/util/test_updater.rb 
/home/masa/ywesee/de.oddb.org/test/stub/model.rb:172: warning: already initialized constant Currency
Loaded suite test/util/test_updater
Started
F
Finished in 0.021333 seconds.

  1) Failure:
test_run(ODDB::Util::TestUpdater)
    [/usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/validators.rb:40:in `validate'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation.rb:123:in `flexmock_verify'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation.rb:122:in `each'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation.rb:122:in `flexmock_verify'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation_director.rb:64:in `flexmock_verify'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation_director.rb:63:in `each'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation_director.rb:63:in `flexmock_verify'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/core.rb:76:in `flexmock_verify'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/core.rb:75:in `each'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/core.rb:75:in `flexmock_verify'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/core.rb:191:in `flexmock_wrap'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/core.rb:74:in `flexmock_verify'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/mock_container.rb:41:in `flexmock_verify'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/mock_container.rb:40:in `each'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/mock_container.rb:40:in `flexmock_verify'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/mock_container.rb:32:in `flexmock_teardown'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/test_unit_integration.rb:37:in `teardown']:
in mock 'flexmock(Module)': method 'notify_admins(String, Array)' called incorrect number of times.
<3> expected but was
<0>.

1 tests, 4 assertions, 1 failures, 0 errors

It says, notify_admins method is NOT called.

Experiment

Modified 2010-05-12 Hannes Wyss We always need to have a Product assigned to a Sequence

      def test_run
        today = Date.new(2006,10)
        flexmock(Util::Mail).should_receive(:notify_admins)\
          .with(String, Array).times(3)
        dimdi = flexmock(Import::Dimdi)
        dimdi.should_receive(:current_date).and_return today
        #dimdi_files = %w{wirkkurz_011006.xls darform_011006.xls fb_011006.xls}
        dimdi_files = %w{wirkstoffkuerzel-200610.xls darreichungsformen-200610.xls festbetraege-200610.xls}
        download = StringIO.new('downloaded from dimdi')
        dimdi.should_receive(:download).times(3).and_return do |file, block|
          assert_equal dimdi_files.shift, file
          block.call download
        end
        flexmock(Import::Dimdi::GalenicForm).new_instances.should_receive(:import).with(download).times(1).and_return []
        flexmock(Import::Dimdi::Product).new_instances.should_receive(:import).with(download).times(1).and_return []
        flexmock(Import::Dimdi::Substance).new_instances.should_receive(:import).with(download).times(1).and_return []
        job_dir = File.join ODDB.config.oddb_dir, 'jobs'
        log_dir = File.join ODDB.config.oddb_dir, 'log'
        cmds = %w{import_gkv import_pharmnet import_whocc}
        flexmock(IO).should_receive(:popen).and_return do |popen, block|
          cmd = cmds.shift
          assert_equal "#{job_dir}/#{cmd} log_file=#{log_dir}/#{cmd}", popen
        end
        @updater.run(today)
      end

Result

masa@masa ~/work/de.oddb.org $ ruby test/util/test_updater.rb 
/home/masa/work/de.oddb.org/test/stub/model.rb:172: warning: already initialized constant Currency
Loaded suite test/util/test_updater
Started
.
Finished in 0.023203 seconds.

1 tests, 6 assertions, 0 failures, 0 errors

Modified the next commit 2010-05-12 Hannes Wyss Add external Job for importing dimdi-data

      def test_run
        today = Date.new(2006,10)
        flexmock(Util::Mail).should_receive(:notify_admins)\
          .with(String, Array).times(3)
        dimdi = flexmock(Import::Dimdi)
        dimdi.should_receive(:current_date).and_return today
        #dimdi_files = %w{wirkkurz_011006.xls darform_011006.xls fb_011006.xls}
        dimdi_files = %w{wirkstoffkuerzel-200610.xls darreichungsformen-200610.xls festbetraege-200610.xls}
        download = StringIO.new('downloaded from dimdi')
        dimdi.should_receive(:download).times(3).and_return do |file, block|
          assert_equal dimdi_files.shift, file
          block.call download
        end
        flexmock(Import::Dimdi::GalenicForm).new_instances.should_receive(:import).with(download).times(1).and_return []
        flexmock(Import::Dimdi::Product).new_instances.should_receive(:import).with(download).times(1).and_return []
        flexmock(Import::Dimdi::Substance).new_instances.should_receive(:import).with(download).times(1).and_return []
        job_dir = File.join ODDB.config.oddb_dir, 'jobs'
        log_dir = File.join ODDB.config.oddb_dir, 'log'
        #cmds = %w{import_gkv import_pharmnet import_whocc}
        cmds = %w{import_dimdi import_gkv import_pharmnet import_whocc}
        flexmock(IO).should_receive(:popen).and_return do |popen, block|
          cmd = cmds.shift
          assert_equal "#{job_dir}/#{cmd} log_file=#{log_dir}/#{cmd}", popen
        end
        @updater.run(today)
      end

Result

masa@masa ~/work/de.oddb.org $ ruby test/util/test_updater.rb 
/home/masa/work/de.oddb.org/test/stub/model.rb:172: warning: already initialized constant Currency
Loaded suite test/util/test_updater
Started
F
Finished in 0.021399 seconds.

  1) Failure:
test_run(ODDB::Util::TestUpdater)
    [/usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/validators.rb:40:in `validate'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation.rb:123:in `flexmock_verify'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation.rb:122:in `each'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation.rb:122:in `flexmock_verify'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation_director.rb:64:in `flexmock_verify'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation_director.rb:63:in `each'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation_director.rb:63:in `flexmock_verify'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/core.rb:76:in `flexmock_verify'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/core.rb:75:in `each'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/core.rb:75:in `flexmock_verify'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/core.rb:191:in `flexmock_wrap'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/core.rb:74:in `flexmock_verify'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/mock_container.rb:41:in `flexmock_verify'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/mock_container.rb:40:in `each'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/mock_container.rb:40:in `flexmock_verify'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/mock_container.rb:32:in `flexmock_teardown'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/test_unit_integration.rb:37:in `teardown']:
in mock 'flexmock(Module)': method 'notify_admins(String, Array)' called incorrect number of times.
<3> expected but was
<0>.

1 tests, 4 assertions, 1 failures, 0 errors

Therefore

  1. This commit makes the test_run fail 2010-05-12 Hannes Wyss Add external Job for importing dimdi-data
  2. I have to look at the diff carefully

Diff

diff --git a/lib/oddb/util/updater.rb b/lib/oddb/util/updater.rb
index c2b9e82..14a0036 100644 (file)
--- a/lib/oddb/util/updater.rb
+++ b/lib/oddb/util/updater.rb
@@ -119,7 +119,7 @@ module ODDB
         Mail.notify_admins(subject, lines)
       end
       def Updater.run(today = Date.today)
-        import_dimdi
+        run_logged_job 'import_dimdi'
         run_logged_job 'import_gkv'
         case today.day
         when 1

Expertiment

lib/oodb/util/updater.rb

      def Updater.run(today = Date.today)
        #import_dimdi
        #run_logged_job 'import_dimdi'
        run_logged_job 'import_gkv'
        case today.day
        when 1
          run_logged_job 'import_pharmnet'
          run_logged_job 'import_whocc'
        when 15
          update_prices
        end
      end

test/util/test_updater.b

      def test_run
        today = Date.new(2006,10)
        flexmock(Util::Mail).should_receive(:notify_admins)\
          .with(String, Array).times(3)
        dimdi = flexmock(Import::Dimdi)
        dimdi.should_receive(:current_date).and_return today
        #dimdi_files = %w{wirkkurz_011006.xls darform_011006.xls fb_011006.xls}
        dimdi_files = %w{wirkstoffkuerzel-200610.xls darreichungsformen-200610.xls festbetraege-200610.xls}
        download = StringIO.new('downloaded from dimdi')
        dimdi.should_receive(:download).times(3).and_return do |file, block|
          assert_equal dimdi_files.shift, file
          block.call download
        end
        flexmock(Import::Dimdi::GalenicForm).new_instances.should_receive(:import).with(download).times(1).and_return []
        flexmock(Import::Dimdi::Product).new_instances.should_receive(:import).with(download).times(1).and_return []
        flexmock(Import::Dimdi::Substance).new_instances.should_receive(:import).with(download).times(1).and_return []
        job_dir = File.join ODDB.config.oddb_dir, 'jobs'
        log_dir = File.join ODDB.config.oddb_dir, 'log'
        cmds = %w{import_gkv import_pharmnet import_whocc}
        #cmds = %w{import_dimdi import_gkv import_pharmnet import_whocc}
        flexmock(IO).should_receive(:popen).and_return do |popen, block|
          cmd = cmds.shift
          assert_equal "#{job_dir}/#{cmd} log_file=#{log_dir}/#{cmd}", popen
        end
        @updater.run(today)
      end

Result

masa@masa ~/work/de.oddb.org $ ruby test/util/test_updater.rb 
/home/masa/work/de.oddb.org/test/stub/model.rb:172: warning: already initialized constant Currency
Loaded suite test/util/test_updater
Started
F
Finished in 0.021247 seconds.

  1) Failure:
test_run(ODDB::Util::TestUpdater)
    [/usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/validators.rb:40:in `validate'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation.rb:123:in `flexmock_verify'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation.rb:122:in `each'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation.rb:122:in `flexmock_verify'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation_director.rb:64:in `flexmock_verify'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation_director.rb:63:in `each'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation_director.rb:63:in `flexmock_verify'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/core.rb:76:in `flexmock_verify'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/core.rb:75:in `each'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/core.rb:75:in `flexmock_verify'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/core.rb:191:in `flexmock_wrap'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/core.rb:74:in `flexmock_verify'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/mock_container.rb:41:in `flexmock_verify'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/mock_container.rb:40:in `each'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/mock_container.rb:40:in `flexmock_verify'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/mock_container.rb:32:in `flexmock_teardown'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/test_unit_integration.rb:37:in `teardown']:
in mock 'flexmock(Module)': method 'notify_admins(String, Array)' called incorrect number of times.
<3> expected but was
<0>.

1 tests, 3 assertions, 1 failures, 0 errors

Notes

  • import_dimdi and run_logged_job 'import_dimdi' looks calling different methods

Check 2010-05-12 Hannes Wyss Add external Job for importing dimdi-data

Set p / Success Case

lib/oddb/util/updater.rb

      def Updater.run(today = Date.today)
        import_dimdi
        #run_logged_job 'import_dimdi'
        run_logged_job 'import_gkv'
        case today.day
        when 1
          run_logged_job 'import_pharmnet'
          run_logged_job 'import_whocc'
        when 15
          update_prices
        end
      end

test/util/test_updater.rb

      def test_run
        today = Date.new(2006,10)
        flexmock(Util::Mail).should_receive(:notify_admins)\
          .with(String, Array).times(3)
        dimdi = flexmock(Import::Dimdi)
        dimdi.should_receive(:current_date).and_return today
        #dimdi_files = %w{wirkkurz_011006.xls darform_011006.xls fb_011006.xls}
        dimdi_files = %w{wirkstoffkuerzel-200610.xls darreichungsformen-200610.xls festbetraege-200610.xls}
        download = StringIO.new('downloaded from dimdi')
        dimdi.should_receive(:download).times(3).and_return do |file, block|
          assert_equal dimdi_files.shift, file
          block.call download
        end
        flexmock(Import::Dimdi::GalenicForm).new_instances.should_receive(:import).with(download).times(1).and_return []
        flexmock(Import::Dimdi::Product).new_instances.should_receive(:import).with(download).times(1).and_return []
        flexmock(Import::Dimdi::Substance).new_instances.should_receive(:import).with(download).times(1).and_return []
        job_dir = File.join ODDB.config.oddb_dir, 'jobs'
        log_dir = File.join ODDB.config.oddb_dir, 'log'
        cmds = %w{import_gkv import_pharmnet import_whocc}
        #cmds = %w{import_dimdi import_gkv import_pharmnet import_whocc}
        flexmock(IO).should_receive(:popen).and_return do |popen, block|
          cmd = cmds.shift
          assert_equal "#{job_dir}/#{cmd} log_file=#{log_dir}/#{cmd}", popen
        end
        @updater.run(today)
      end

Result

masa@masa ~/work/de.oddb.org $ ruby test/util/test_updater.rb 
/home/masa/work/de.oddb.org/test/stub/model.rb:172: warning: already initialized constant Currency
Loaded suite test/util/test_updater
Started
.
Finished in 0.023362 seconds.

1 tests, 6 assertions, 0 failures, 0 errors

lib/oddb/util/updater.rb

      def Updater.import_dimdi
p "get-in import_dimdi"
        if(date = Import::Dimdi.current_date(DIMDI_INDEX))
          import_dimdi_substances(date)
          import_dimdi_galenic_forms(date)
          import_dimdi_products(date)
        end
      end
      def Updater.import_dimdi_galenic_forms(date)
p "get-in import_dimdi_galenic_forms"
        file = date.strftime("darreichungsformen-%Y%m.xls")
        Import::Dimdi.download(file) { |io|
          reported_import(Import::Dimdi::GalenicForm.new(date), io,
                          :filetype => 'XLS')
        }
      end
      def Updater.import_dimdi_products(date)
p "get-in import_dimdi_products"
        file = date.strftime("festbetraege-%Y%m.xls")
        Import::Dimdi.download(file) { |io|
          reported_import(Import::Dimdi::Product.new(date), io,
                         :subject => "Update Festbeträge",
                         :filetype => 'XLS')
        }
      end
      def Updater.import_dimdi_substances(date)
p "get-in import_dimdi_substances"
        file = date.strftime("wirkstoffkuerzel-%Y%m.xls")
        Import::Dimdi.download(file) { |io|
          reported_import(Import::Dimdi::Substance.new(date), io,
                          :filetype => 'XLS')
        }
      end

Result

masa@masa ~/work/de.oddb.org $ ruby test/util/test_updater.rb 
/home/masa/work/de.oddb.org/test/stub/model.rb:172: warning: already initialized constant Currency
Loaded suite test/util/test_updater
Started
"get-in import_dimdi"
"get-in import_dimdi_substances"
"get-in import_dimdi_galenic_forms"
"get-in import_dimdi_products"
.
Finished in 0.023262 seconds.

1 tests, 6 assertions, 0 failures, 0 errors

Set p / Fail Case

lib/oddb/util/updater.rb

      def Updater.import_dimdi
p "get-in import_dimdi"
        if(date = Import::Dimdi.current_date(DIMDI_INDEX))
          import_dimdi_substances(date)
          import_dimdi_galenic_forms(date)
          import_dimdi_products(date)
        end
      end
      def Updater.import_dimdi_galenic_forms(date)
p "get-in import_dimdi_galenic_forms"
        file = date.strftime("darreichungsformen-%Y%m.xls")
        Import::Dimdi.download(file) { |io|
          reported_import(Import::Dimdi::GalenicForm.new(date), io,
                          :filetype => 'XLS')
        }
      end
      def Updater.import_dimdi_products(date)
p "get-in import_dimdi_products"
        file = date.strftime("festbetraege-%Y%m.xls")
        Import::Dimdi.download(file) { |io|
          reported_import(Import::Dimdi::Product.new(date), io,
                         :subject => "Update Festbeträge",
                         :filetype => 'XLS')
        }
      end
      def Updater.import_dimdi_substances(date)
p "get-in import_dimdi_substances"
        file = date.strftime("wirkstoffkuerzel-%Y%m.xls")
        Import::Dimdi.download(file) { |io|
          reported_import(Import::Dimdi::Substance.new(date), io,
                          :filetype => 'XLS')
        }
      end
      def Updater.run(today = Date.today)
        #import_dimdi
        run_logged_job 'import_dimdi'
        run_logged_job 'import_gkv'
        case today.day
        when 1
          run_logged_job 'import_pharmnet'
          run_logged_job 'import_whocc'
        when 15
          update_prices
        end
      end

test/util/test_updater.rb

      def test_run
        today = Date.new(2006,10)
        flexmock(Util::Mail).should_receive(:notify_admins)\
          .with(String, Array).times(3)
        dimdi = flexmock(Import::Dimdi)
        dimdi.should_receive(:current_date).and_return today
        #dimdi_files = %w{wirkkurz_011006.xls darform_011006.xls fb_011006.xls}
        dimdi_files = %w{wirkstoffkuerzel-200610.xls darreichungsformen-200610.xls festbetraege-200610.xls}
        download = StringIO.new('downloaded from dimdi')
        dimdi.should_receive(:download).times(3).and_return do |file, block|
          assert_equal dimdi_files.shift, file
          block.call download
        end
        flexmock(Import::Dimdi::GalenicForm).new_instances.should_receive(:import).with(download).times(1).and_return []
        flexmock(Import::Dimdi::Product).new_instances.should_receive(:import).with(download).times(1).and_return []
        flexmock(Import::Dimdi::Substance).new_instances.should_receive(:import).with(download).times(1).and_return []
        job_dir = File.join ODDB.config.oddb_dir, 'jobs'
        log_dir = File.join ODDB.config.oddb_dir, 'log'
        #cmds = %w{import_gkv import_pharmnet import_whocc}
        cmds = %w{import_dimdi import_gkv import_pharmnet import_whocc}
        flexmock(IO).should_receive(:popen).and_return do |popen, block|
          cmd = cmds.shift
          assert_equal "#{job_dir}/#{cmd} log_file=#{log_dir}/#{cmd}", popen
        end
        @updater.run(today)
      end

Result

masa@masa ~/work/de.oddb.org $ ruby test/util/test_updater.rb 
/home/masa/work/de.oddb.org/test/stub/model.rb:172: warning: already initialized constant Currency
Loaded suite test/util/test_updater
Started
F
Finished in 0.021354 seconds.

  1) Failure:
test_run(ODDB::Util::TestUpdater)
    [/usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/validators.rb:40:in `validate'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation.rb:123:in `flexmock_verify'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation.rb:122:in `each'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation.rb:122:in `flexmock_verify'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation_director.rb:64:in `flexmock_verify'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation_director.rb:63:in `each'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation_director.rb:63:in `flexmock_verify'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/core.rb:76:in `flexmock_verify'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/core.rb:75:in `each'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/core.rb:75:in `flexmock_verify'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/core.rb:191:in `flexmock_wrap'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/core.rb:74:in `flexmock_verify'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/mock_container.rb:41:in `flexmock_verify'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/mock_container.rb:40:in `each'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/mock_container.rb:40:in `flexmock_verify'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/mock_container.rb:32:in `flexmock_teardown'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/test_unit_integration.rb:37:in `teardown']:
in mock 'flexmock(Module)': method 'notify_admins(String, Array)' called incorrect number of times.
<3> expected but was
<0>.

1 tests, 4 assertions, 1 failures, 0 errors

Therefore

  • Updater.import_dimdi looks not called.

Read run_logged_job method

lib/oddb/util/updater.rb

      def Updater.run_logged_job job
        dir = ODDB.config.oddb_dir
        cmd = File.join dir, 'jobs', job
        log = File.join dir, 'log', job
        IO.popen "#{cmd} log_file=#{log}" do |io|
          # wait for importer to exit
        end
      end

Notes

  • This method just calls the job which is set as the argument with option 'log_file'.
  • The first half looks only the import_dimdi test
      def test_run
        today = Date.new(2006,10)
        flexmock(Util::Mail).should_receive(:notify_admins)\
          .with(String, Array).times(3)
        dimdi = flexmock(Import::Dimdi)
        dimdi.should_receive(:current_date).and_return today
        #dimdi_files = %w{wirkkurz_011006.xls darform_011006.xls fb_011006.xls}
        dimdi_files = %w{wirkstoffkuerzel-200610.xls darreichungsformen-200610.xls festbetraege-200610.xls}
        download = StringIO.new('downloaded from dimdi')
        dimdi.should_receive(:download).times(3).and_return do |file, block|
          assert_equal dimdi_files.shift, file
          block.call download
        end
        flexmock(Import::Dimdi::GalenicForm).new_instances.should_receive(:import).with(download).times(1).and_return []
        flexmock(Import::Dimdi::Product).new_instances.should_receive(:import).with(download).times(1).and_return []
        flexmock(Import::Dimdi::Substance).new_instances.should_receive(:import).with(download).times(1).and_return []
  • test_run method tests only calling jobs and check the calling strings.
  • The detail tests of imoprt_gkv, import_pharmnet and import_whocc look not composed yet.
  • Updater.run_logged_job does not call each method in the test_run method.

Modify the latest commit 2 days ago Masaomi Hatakeyama Possible to add pdf link as command line option to.

test/util/test_updater.rb (Comment out the other method, only test test_run method)

      def test_run
        today = Date.new(2006,10)
=begin
        flexmock(Util::Mail).should_receive(:notify_admins)\
          .with(String, Array).times(3)
        dimdi = flexmock(Import::Dimdi)
        dimdi.should_receive(:current_date).and_return today
        dimdi_files = %w{wirkkurz_011006.xls darform_011006.xls fb_011006.xls}
        download = StringIO.new('downloaded from dimdi')
        dimdi.should_receive(:download).times(3).and_return do |file, block|
          assert_equal dimdi_files.shift, file
          block.call download
        end
        flexmock(Import::Dimdi::GalenicForm).new_instances.should_receive(:import).with(download).times(1).and_return []
        flexmock(Import::Dimdi::Product).new_instances.should_receive(:import).with(download).times(1).and_return []
        flexmock(Import::Dimdi::Substance).new_instances.should_receive(:import).with(download).times(1).and_return []
=end
        job_dir = File.join ODDB.config.oddb_dir, 'jobs'
        log_dir = File.join ODDB.config.oddb_dir, 'log'
        cmds = %w{import_dimdi import_gkv import_pharmnet import_whocc}
        flexmock(IO).should_receive(:popen).times(4).and_return do |popen, block|
          cmd = cmds.shift
          assert_equal "#{job_dir}/#{cmd} log_file=#{log_dir}/#{cmd}", popen
        end
        @updater.run(today)
      end

Result

masa@masa ~/ywesee/de.oddb.org $ ruby test/util/test_updater.rb 
/home/masa/ywesee/de.oddb.org/test/stub/model.rb:172: warning: already initialized constant Currency
Loaded suite test/util/test_updater
Started
.
Finished in 0.001922 seconds.

1 tests, 4 assertions, 0 failures, 0 errors

Commit locally

masa@masa ~/ywesee/de.oddb.org $ git add test/util/test_updater.rb 
masa@masa ~/ywesee/de.oddb.org $ git commit -m "clear test_run"

Add test_import_dimdi

test/util/updater.rb

      def test_import_dimdi
        today = Date.new(2006,10)
        flexmock(Util::Mail).should_receive(:notify_admins)\
          .with(String, Array).times(3)
        dimdi = flexmock(Import::Dimdi)
        dimdi.should_receive(:current_date).and_return today
        #dimdi_files = %w{wirkkurz_011006.xls darform_011006.xls fb_011006.xls}
        dimdi_files = %w{wirkstoffkuerzel-200610.xls darreichungsformen-200610.xls festbetraege-200610.xls}
        download = StringIO.new('downloaded from dimdi')
        dimdi.should_receive(:download).times(3).and_return do |file, block|
          assert_equal dimdi_files.shift, file
          block.call download
        end
        flexmock(Import::Dimdi::GalenicForm).new_instances.should_receive(:import).with(download).times(1).and_return []
        flexmock(Import::Dimdi::Product).new_instances.should_receive(:import).with(download).times(1).and_return []
        flexmock(Import::Dimdi::Substance).new_instances.should_receive(:import).with(download).times(1).and_return []

        @updater.import_dimdi
      end

Result

masa@masa ~/ywesee/de.oddb.org $ ruby test/util/test_updater.rb 
/home/masa/ywesee/de.oddb.org/test/stub/model.rb:172: warning: already initialized constant Currency
Loaded suite test/util/test_updater
Started
..
Finished in 0.025893 seconds.

2 tests, 7 assertions, 0 failures, 0 errors

Commit locally

masa@masa ~/ywesee/de.oddb.org $ git add test/util/test_updater.rb 
masa@masa ~/ywesee/de.oddb.org $ git commit -m "add test_import_dimdi"

Fix test_run__errors

Confirm Error

masa@masa ~/ywesee/de.oddb.org $ ruby test/util/test_updater.rb 
/home/masa/ywesee/de.oddb.org/test/stub/model.rb:172: warning: already initialized constant Currency
Loaded suite test/util/test_updater
Started
.F
Finished in 0.023424 seconds.

  1) Failure:
test_run__errors(ODDB::Util::TestUpdater) [test/util/test_updater.rb:80]:
<RuntimeError> exception expected but was
Class: <Test::Unit::AssertionFailedError>
Message: <"in mock 'flexmock(Class)': <\"/home/masa/ywesee/de.oddb.org/jobs/import_gkv log_file=/home/masa/ywesee/de.oddb.org/log/import_gkv\"> expected but was\n<\"/home/masa/ywesee/de.oddb.org/jobs/import_dimdi log_file=/home/masa/ywesee/de.oddb.org/log/import_dimdi\">.">
---Backtrace---
test/util/test_updater.rb:78:in `test_run__errors'
/usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation.rb:78:in `call'
/usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation.rb:78:in `return_value'
/usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation.rb:59:in `verify_call'
/usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation_director.rb:42:in `call'
/usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/core.rb:101:in `method_missing'
/usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/core.rb:191:in `flexmock_wrap'
/usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/core.rb:98:in `method_missing'
/usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/partial_mock.rb:255:in `popen'
/home/masa/ywesee/de.oddb.org/lib/oddb/util/updater.rb:150:in `run_logged_job'
/home/masa/ywesee/de.oddb.org/lib/oddb/util/updater.rb:136:in `run'
test/util/test_updater.rb:81:in `test_run__errors'
test/util/test_updater.rb:80:in `test_run__errors'
---------------

2 tests, 5 assertions, 1 failures, 0 errors

Separate it into import_dimdi and the other part

      def test_dimdi__errors
        today = Date.new(2006,10)
        flexmock(Util::Mail).should_receive(:notify_admins)\
          .with(String, Array).times(0)
        dimdi = flexmock(Import::Dimdi)
        dimdi.should_receive(:current_date).and_return today
        #dimdi_files = %w{wirkkurz_011006.xls darform_011006.xls fb_011006.xls}
        dimdi_files = %w{wirkstoffkuerzel-200610.xls darreichungsformen-200610.xls festbetraege-200610.xls}
        download = StringIO.new('downloaded from dimdi')
        dimdi.should_receive(:download).times(1).and_return do |file, block|
          assert_equal dimdi_files.shift, file
          raise "connection error"
        end
        job_dir = File.join ODDB.config.oddb_dir, 'jobs'
        log_dir = File.join ODDB.config.oddb_dir, 'log'
        cmds = %w{import_gkv import_pharmnet import_whocc}
        flexmock(IO).should_receive(:popen).and_return do |popen, block|
          cmd = cmds.shift
          assert_equal "#{job_dir}/#{cmd} log_file=#{log_dir}/#{cmd}", popen
        end

        assert_raises RuntimeError do
          #@updater.run(today)
          @updater.import_dimdi
        end

      end

Result

masa@masa ~/ywesee/de.oddb.org $ ruby test/util/test_updater.rb 
/home/masa/ywesee/de.oddb.org/test/stub/model.rb:172: warning: already initialized constant Currency
Loaded suite test/util/test_updater
Started
...
Finished in 0.028506 seconds.

3 tests, 8 assertions, 0 failures, 0 errors

Commit locally

masa@masa ~/ywesee/de.oddb.org $ git add test/util/test_updater.rb 
masa@masa ~/ywesee/de.oddb.org $ git commit -m "add test_import_dimdi__errors"

Fix test_run__later_errors

Confirm error

masa@masa ~/ywesee/de.oddb.org $ ruby test/util/test_updater.rb 
/home/masa/ywesee/de.oddb.org/test/stub/model.rb:172: warning: already initialized constant Currency
Loaded suite test/util/test_updater
Started
...F
Finished in 0.032832 seconds.

  1) Failure:
test_run__later_errors(ODDB::Util::TestUpdater)
    [test/util/test_updater.rb:157:in `test_run__later_errors'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation.rb:78:in `call'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation.rb:78:in `return_value'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation.rb:59:in `verify_call'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation_director.rb:42:in `call'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/core.rb:101:in `method_missing'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/core.rb:191:in `flexmock_wrap'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/core.rb:98:in `method_missing'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/partial_mock.rb:255:in `popen'
     /home/masa/ywesee/de.oddb.org/lib/oddb/util/updater.rb:150:in `run_logged_job'
     /home/masa/ywesee/de.oddb.org/lib/oddb/util/updater.rb:136:in `run'
     test/util/test_updater.rb:160:in `test_run__later_errors'
     test/util/test_updater.rb:159:in `test_run__later_errors']:
in mock 'flexmock(Class)': <"/home/masa/ywesee/de.oddb.org/jobs/import_gkv log_file=/home/masa/ywesee/de.oddb.org/log/import_gkv"> expected but was
<"/home/masa/ywesee/de.oddb.org/jobs/import_dimdi log_file=/home/masa/ywesee/de.oddb.org/log/import_dimdi">.

4 tests, 9 assertions, 1 failures, 0 errors

This can also be separated into dimdi and the other parts.

      def test_import_dimdi__later_errors
        today = Date.new(2006,10)
        flexmock(Util::Mail).should_receive(:notify_admins)\
          .with(String, Array).times(3)
        dimdi = flexmock(Import::Dimdi)
        dimdi.should_receive(:current_date).and_return today
        #dimdi_files = %w{wirkkurz_011006.xls darform_011006.xls fb_011006.xls}
        dimdi_files = %w{wirkstoffkuerzel-200610.xls darreichungsformen-200610.xls festbetraege-200610.xls}
        download = StringIO.new('downloaded from dimdi')
        dimdi.should_receive(:download).times(3).and_return do |file, block|
          assert_equal dimdi_files.shift, file
          block.call download
        end
        flexmock(Import::Dimdi::GalenicForm).new_instances.should_receive(:import).with(download).times(1).and_return do raise 'import error' end
        flexmock(Import::Dimdi::Product).new_instances.should_receive(:import).with(download).times(1).and_return do raise 'import error' end
        flexmock(Import::Dimdi::Substance).new_instances.should_receive(:import).with(download).times(1).and_return do raise 'import error' end

        assert_nothing_raised do
          #@updater.run(today)
          @updater.import_dimdi
        end
      end

Result

masa@masa ~/ywesee/de.oddb.org $ ruby test/util/test_updater.rb 
/home/masa/ywesee/de.oddb.org/test/stub/model.rb:172: warning: already initialized constant Currency
Loaded suite test/util/test_updater
Started
....
Finished in 0.035044 seconds.

4 tests, 9 assertions, 0 failures, 0 errors

Commit locally

masa@masa ~/ywesee/de.oddb.org $ git add test/util/test_updater.rb 
masa@masa ~/ywesee/de.oddb.org $ git commit -m "add test_import_dimdi__later_errors"

Merge and Push

masa@masa ~/ywesee/de.oddb.org $ git checkout master
Switched to branch 'master'
masa@masa ~/ywesee/de.oddb.org $ git merge --squash work
Updating 75ee4e1..2a6a8ed
Fast-forward
Squash commit -- not updating HEAD
 test/util/test_updater.rb |   46 +++++++++++++++++++++++---------------------
 1 files changed, 24 insertions(+), 22 deletions(-)
masa@masa ~/ywesee/de.oddb.org $ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   test/util/test_updater.rb
#
masa@masa ~/ywesee/de.oddb.org $ git add test/util/test_updater.rb 
masa@masa ~/ywesee/de.oddb.org $ git commit -m "Fixed test_updater.rb"
[master f0becae] Fixed test_updater.rb
 1 files changed, 24 insertions(+), 22 deletions(-)
masa@masa ~/ywesee/de.oddb.org $ ruby test/util/test_updater.rb 
/home/masa/ywesee/de.oddb.org/test/stub/model.rb:172: warning: already initialized constant Currency
Loaded suite test/util/test_updater
Started
....
Finished in 0.0352260000000001 seconds.

4 tests, 9 assertions, 0 failures, 0 errors
masa@masa ~/ywesee/de.oddb.org $ git push
Enter passphrase for key '/home/masa/.ssh/id_rsa': 
Counting objects: 9, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 622 bytes, done.
Total 5 (delta 4), reused 0 (delta 0)
To ssh://ywesee@scm.ywesee.com/home/ywesee/git/de.oddb.org
   75ee4e1..f0becae  master -> master

Commit

test/util/test_updater.rb

      def test_import_gkv
        today = Date.new(2006,10)
        flexmock(Util::Mail).should_receive(:notify_admins)\
          .with(String, Array).times(1)
        gkv = flexmock(Import::Gkv).new_instances
        gkv.should_receive(:current_date).and_return today
        gkv_files = %w{wirkstoffkuerzel-200610.xls darreichungsformen-200610.xls festbetraege-200610.xls}
        url = "http://hogehoge/"
        gkv.should_receive(:latest_url).and_return(url)
        download = StringIO.new('downloaded from gkv')
        gkv.should_receive(:download_latest).times(1).and_return do |file, block|
          assert_equal gkv_files.shift, file
          block.call download
        end
        gkv.should_receive(:import).with(download).times(1).and_return []

        @updater.import_gkv

      end

Result

masa@masa ~/ywesee/de.oddb.org $ ruby test/util/test_updater.rb 
/home/masa/ywesee/de.oddb.org/test/stub/model.rb:172: warning: already initialized constant Currency
Loaded suite test/util/test_updater
Started
..."get-in import_gkv"
url=http://hogehoge/
F.
Finished in 0.038308 seconds.

  1) Failure:
test_import_gkv(ODDB::Util::TestUpdater)
    [test/util/test_updater.rb:122:in `test_import_gkv'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation.rb:78:in `call'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation.rb:78:in `return_value'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation.rb:59:in `verify_call'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/expectation_director.rb:42:in `call'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/core.rb:101:in `method_missing'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/core.rb:191:in `flexmock_wrap'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/core.rb:98:in `method_missing'
     /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/partial_mock.rb:255:in `download_latest'
     /home/masa/ywesee/de.oddb.org/lib/oddb/util/updater.rb:59:in `import_gkv'
     test/util/test_updater.rb:127:in `test_import_gkv']:
in mock 'flexmock(ODDB::Import::Gkv)': <"wirkstoffkuerzel-200610.xls"> expected but was
<"http://hogehoge/">.

5 tests, 10 assertions, 1 failures, 0 errors

Continut this tomorrow

Flexock Practice

Simple Sample

test.rb

class MOCK
  def test
    2
  end
end

class TEST
  def test
    mock = MOCK.new
    mock.test
  end
  def test2(mock)
    mock.test
  end
end

if __FILE__ == $0
test=TEST.new
p test.test

mock=MOCK.new
p test.test2(mock)
end

test_test.rb

require 'test/unit'
require 'flexmock'

require 'test'

class TestTest < Test::Unit::TestCase
include FlexMock::TestCase
  def test_test
    expected = 2
    test = TEST.new
    assert_equal expected, test.test
  end

  def test_test_mock
    flexstub(MOCK) do |mockclass|
      mockclass.should_receive(:new).and_return do
        flexmock('mock object') do |mockobj|
          mockobj.should_receive(:test).with_no_args.and_return(1)
        end
      end
    end

    expected = 1
    test = TEST.new
    assert_equal expected, test.test
  end

  def test_test_mock2
    mockclass = flexstub(MOCK)
    #mockclass = flexmock(MOCK)
    mockobj   = flexmock("mock object")
    mockclass.should_receive(:new).and_return(mockobj)
    mockobj.should_receive(:test).with_no_args.and_return(1)

    expected = 1
    test = TEST.new
    assert_equal expected, test.test
  end

  def test_test2
    mock = MOCK.new

    expected = 2
    test = TEST.new
    assert_equal expected, test.test2(mock)
  end

  def test_test2_mock
    mock = flexmock(MOCK.new)
    mock.should_receive(:test).and_return(1)

    expected = 1
    test = TEST.new
    assert_equal expected, test.test2(mock)
  end

Result

masa@masa ~/work/test_mock $ ruby test_test.rb 
Loaded suite test_test
Started
.....
Finished in 0.001917 seconds.

5 tests, 5 assertions, 0 failures, 0 errors

link

view · edit · sidebar · attach · print · history
Page last modified on July 13, 2011, at 12:02 PM