view · edit · sidebar · attach · print · history

20110110-debug-bag-sl-flag-test_case-bsv_xml

<< | Index | >>


  1. Trace 'SL' flag process
  2. Test-case bsv_xml.rb

Goal
  • Debug BAG SL flag / 90%
Milestones
  • Trace the 'SL' flag process 10:30
  • Test-case bsv_xml.rb
  • (Limitation Ticket 248)
Summary
Commits
ToDo Tomorrow
  • Complete the test-case and commit them
Keep in Mind
  1. swissmedic_followers debug
  2. On Ice
  3. emerge --sync

Trace 'SL' flag process

Experiment

  1. Access: http://oddb.masa.org/
  2. Search: 'Medikamente', 'Temodal 5 mg'
  3. Click: '092'
  4. Enter: SL Eintrag

Then 'SL' flag is shown, but 'SO' flag goes away.

Experiment

Default

Run update_bsv (first run)

masa@masa ~/ywesee/oddb.org $ bin/admin 
ch.oddb> Updater.new(self).update_bsv

Result

Run update_bsv again (second run)

masa@masa ~/ywesee/oddb.org $ bin/admin 
ch.oddb> Updater.new(self).update_bsv

Result

SL-Eintrag

Note

  • I should understand the 'SL' and 'SO' flag meanings

Experiment

  • Try to update_bsv two times

Preparation

  • Stop all daemons
  • Restore the current cache data
~/ywesee/oddb.org $ sudo -u postgres dropdb oddb.org
~/ywesee/oddb.org $ sudo -u postgres createdb -E UTF8 -T template0 oddb.org
~/ywesee/oddb.org $ zcat data/sql/oddb.org.20110106.sql.gz |psql -U postgres oddb.org
ch.oddb> Updater.new(self).update_bsv
-> mhatakeyama@ywesee.com
ch.oddb> Updater.new(self).update_bsv
-> mhatakeyama@ywesee.com

Result

Note

  • My guess is true
  • But I do not know why 'SL' is shown

Summary

Test-case bsv_xml.rb

Check the current test-cases

masa@masa ~/ywesee/oddb.org $ ruby test/test_plugin/bsv_xml.rb 
Loaded suite test/test_plugin/bsv_xml
Started
.........
Finished in 0.154731 seconds.

9 tests, 71 assertions, 0 failures, 0 errors

After this updating of bsv_xml.rb (http://dev.ywesee.com/wiki.php/Masa/20110107-debug-bag-list#Sum)

src/plugin/bsv_xml.rb#tag_end

            # update 'SB' flag
            elsif @pack
              if @pack.deductible != @pac_data[:deductible]
                @app.update @pack.pointer, @data, :bag
              end

Test

masa@masa ~/ywesee/oddb.org $ ruby test/test_plugin/bsv_xml.rb 
Loaded suite test/test_plugin/bsv_xml
Started
...F.....
Finished in 0.153695 seconds.

  1) Failure:
test_update_preparation__conflicted_package(ODDB::TestBsvXmlPlugin)
    [test/test_plugin/bsv_xml.rb:1014:in `test_update_preparation__conflicted_package'
     /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'
     /home/masa/ywesee/oddb.org/src/plugin/bsv_xml.rb:370:in `tag_end'
     /usr/lib64/ruby/1.8/rexml/parsers/streamparser.rb:26:in `parse'
     /usr/lib64/ruby/1.8/rexml/document.rb:201:in `parse_stream'
     /home/masa/ywesee/oddb.org/src/plugin/bsv_xml.rb:989:in `update_preparations'
     test/test_plugin/bsv_xml.rb:1016:in `test_update_preparation__conflicted_package']:
in mock 'app': <nil> expected but was
<{:sl_generic_type=>:original,
 :ikscat=>"B",
 :deductible=>:deductible_g,
 :price_exfactory=>
  #<ODDB::Util::Money:0x7f513077a7d0
   @amount=2.9,
   @authority=:sl,
   @country="CH",
   @credits=290,
   @mutation_code="NORMAL",
   @origin=
    "http://bag.e-mediat.net/SL2007.Web.External/File.axd?file=XMLPublications.zip (10.01.2011)",
   @type="exfactory",
   @valid_from=Tue Aug 01 00:00:00 +0200 2006>,
 :pharmacode=>"703279",
 :narcotic=>false,
 :price_public=>
  #<ODDB::Util::Money:0x7f5130761cd0
   @amount=7.5,
   @authority=:sl,
   @country="CH",
   @credits=750,
   @mutation_code="NORMAL",
   @origin=
    "http://bag.e-mediat.net/SL2007.Web.External/File.axd?file=XMLPublications.zip (10.01.2011)",
   @type="public",
   @valid_from=Tue Aug 01 00:00:00 +0200 2006>}>.
@report: {:name_descr=>"Filmtabs 500 mg ", :atc_class=>"M01AG01", :swissmedic_no5_bag=>"12345", :deductible=>:deductible_g, :swissmedic_no8_bag=>"39271028", :generic_type=>:original, :pharmacode_bag=>"703279", :pharmacode_oddb=>"987654", :name_base=>"Ponstan"}

9 tests, 65 assertions, 1 failures, 0 errors

Note

  • 1 Failure

test/test_plugin/bsv_xml.rb

    def test_update_preparation__conflicted_package
      package = setup_package :pharmacode => "987654",
                              :steps => %w{39271 02 028},
                              :price_public => Util::Money.new(17.65),
                              :price_exfactory => Util::Money.new(11.22)
      reg = setup_registration :iksnr => '39271', :package => package
      reg.should_receive(:packages).and_return []
      package.should_receive(:registration).and_return reg
      flexmock(Package).should_receive(:find_by_pharmacode).
                        times(1).and_return nil
      setup_meddata_server :ean13 => '7680392710281'
      @app.should_receive(:registration).and_return reg
      @app.should_receive(:each_package)
      expected_updates = {}
      ptr = Persistence::Pointer.new [:registration, '39271']
      expected_updates.store ptr, { :generic_type => :original,
                                    :index_therapeuticus => '07.10.10.' }
      ptr += [:sequence, '02']
      pac_pointer = ptr += [:package, '028']
      @app.should_receive(:update).and_return do |ptr, data|
        assert_equal expected_updates.delete(ptr), data         # HERE
      end

Note

  • I should understand the testcase meaning line by line

Memo

  • This test-case is to check the method, 'update_preparation', in the case of the conflict of registration

Pass the current tests with the updating (trace line by line)

    def test_update_preparation__conflicted_package
      package = setup_package :pharmacode => "987654",
                              :steps => %w{39271 02 028},
                              :price_public => Util::Money.new(17.65),
                              :price_exfactory => Util::Money.new(11.22)
      reg = setup_registration :iksnr => '39271', :package => package
      reg.should_receive(:packages).and_return []
      package.should_receive(:registration).and_return reg
      flexmock(Package).should_receive(:find_by_pharmacode).
                        times(1).and_return nil
      setup_meddata_server :ean13 => '7680392710281'
      @app.should_receive(:registration).and_return reg
      @app.should_receive(:each_package)
      expected_updates = {}
      ptr = Persistence::Pointer.new [:registration, '39271']
      expected_updates.store ptr, { :generic_type => :original,
                                    :index_therapeuticus => '07.10.10.' }
      ptr += [:sequence, '02']
      pac_pointer = ptr += [:package, '028']

Notes

  • These are the setting of package instance and registration instance and meddata server and @app mock
  • 'expected_updates' is compared with the expected result of updating data in the later assert methods
      @app.should_receive(:update).and_return do |ptr, data|
        assert_equal expected_updates.delete(ptr), data         # HERE
      end

Note

  • This is also the settting of @app mock, but at the same time the following things are checked:
    • when '@app.update' is called somewhere, it is checked if 'expected_updates(ptr)' and 'data' are same
    • 'ptr' and 'data' are arguments of '@app.update' method somewhere in the code This is unclear because 'ptr' and 'data' are placed after 'and_return' method
  • So, this is the checking of which '@app.update' is called
  • One more important thing is this code never called until '@app.update' method is called
 @plugin.update_preparations StringIO.new(@conflicted_src)

Note

  • Actually, in this method the 'assert_equal' method above is called (executed) throught the '@app.update' method somewhere

Experiment (without updating)

test/test_plugin/bsv_xml.rb

    def test_update_preparation__conflicted_package
      package = setup_package :pharmacode => "987654",
                              :steps => %w{39271 02 028},
                              :price_public => Util::Money.new(17.65),
                              :price_exfactory => Util::Money.new(11.22)
      reg = setup_registration :iksnr => '39271', :package => package
      reg.should_receive(:packages).and_return []
      package.should_receive(:registration).and_return reg
      flexmock(Package).should_receive(:find_by_pharmacode).
                        times(1).and_return nil
      setup_meddata_server :ean13 => '7680392710281'
      @app.should_receive(:registration).and_return reg
      @app.should_receive(:each_package)
      expected_updates = {}
      ptr = Persistence::Pointer.new [:registration, '39271']
      expected_updates.store ptr, { :generic_type => :original,
                                    :index_therapeuticus => '07.10.10.' }
      ptr += [:sequence, '02']
      pac_pointer = ptr += [:package, '028']
      @app.should_receive(:update).and_return do |ptr, data|
print "ptr="
pp ptr
print "data="
pp data
        assert_equal expected_updates.delete(ptr), data         # HERE
      end

Result

masa@masa ~/ywesee/oddb.org $ ruby test/test_plugin/bsv_xml.rb 
Loaded suite test/test_plugin/bsv_xml
Started
ptr=#<ODDB::Persistence::Pointer:0x7f04168491f0
 @directions=[[:registration, "39271"]]>
data={:generic_type=>:original, :index_therapeuticus=>"07.10.10."}
.
Finished in 0.029529 seconds.

1 tests, 2 assertions, 0 failures, 0 errors

Note

  • So, the assert_equal method should be as follows:
      ptr = Persistence::Pointer.new [:registration, '39271']
      expected_updates.store ptr, { :generic_type => :original,
                                    :index_therapeuticus => '07.10.10.' }
      expected_pointer = ptr
      #@app.should_receive(:update).and_return do |ptr, data|
      @app.should_receive(:update).and_return do |pointer, update_data|
         assert_equal expected_pointer, pointer
         assert_equal expected_updates[pointer], update_data
      end
      @plugin.update_preparations StringIO.new(@conflicted_src)

Result

masa@masa ~/ywesee/oddb.org $ ruby test/test_plugin/bsv_xml.rb 
Loaded suite test/test_plugin/bsv_xml
Started
.
Finished in 0.029847 seconds.

1 tests, 3 assertions, 0 failures, 0 errors

Note

  • This is better to understand the meaning of the test-case

Experiment

      ptr = Persistence::Pointer.new [:registration, '39271']
      expected_updates.store ptr, { :generic_type => :original,
                                    :index_therapeuticus => '07.10.10.' }
      expected_pointer = ptr
      #@app.should_receive(:update).and_return do |ptr, data|
=begin
      @app.should_receive(:update).and_return do |pointer, update_data|
         assert_equal expected_pointer, pointer
         assert_equal expected_updates[pointer], update_data
      end
=end
      @plugin.update_preparations StringIO.new(@conflicted_src)

Result

masa@masa ~/ywesee/oddb.org $ ruby test/test_plugin/bsv_xml.rb 
Loaded suite test/test_plugin/bsv_xml
Started
E
Finished in 0.028686 seconds.

  1) Error:
test_update_preparation__conflicted_package(ODDB::TestBsvXmlPlugin):
NoMethodError: undefined method `update' for <FlexMock:app>:FlexMock
@report: {:name_base=>"Ponstan", :swissmedic_no8_bag=>"39271028", :generic_type=>:original, :atc_class=>"M01AG01", :deductible=>:deductible_g, :pharmacode_oddb=>"987654", :name_descr=>"Filmtabs 500 mg ", :swissmedic_no5_bag=>"12345", :pharmacode_bag=>"703279"}
    /usr/lib64/ruby/gems/1.8/gems/flexmock-0.8.6/lib/flexmock/core.rb:105: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'
    /home/masa/ywesee/oddb.org/src/plugin/bsv_xml.rb:444:in `tag_end'
    /usr/lib64/ruby/1.8/rexml/parsers/streamparser.rb:26:in `parse'
    /usr/lib64/ruby/1.8/rexml/document.rb:201:in `parse_stream'
    /home/masa/ywesee/oddb.org/src/plugin/bsv_xml.rb:990:in `update_preparations'
    test/test_plugin/bsv_xml.rb:1030:in `test_update_preparation__conflicted_package'

1 tests, 1 assertions, 0 failures, 1 errors

Note

         if @registration
            @app.update @registration.pointer, @reg_data, :bag       #<= here
          elsif @refdata_registration
            @unknown_registrations.push @report_data
          end

So, let's go back to the new updating part

  • The reason what the test fails when I update the following part is
    • '@app.update' method is called again in addition to the above
    • I have to think about '@app.should_receive(:update)' part

src/plugin/bsv_xml.rb#tag_end

            @data.delete :ikscat if @pack.ikscat
            @app.update @pack.pointer, @data, :bag
            @sl_entries.store @pack.pointer, @sl_data
            @lim_texts.store @pack.pointer, @lim_data
#=begin
            # update 'SB' flag
            elsif @pack
              if @pack.deductible != @pac_data[:deductible]
                @app.update @pack.pointer, @data, :bag
              end
#=end
            end

          @pcode, @pack, @sl_data, @lim_data, @out_of_trade, @ikscd, @data,
            @size = nil

Next

  • How can I update '@app' flexmock?

Consideration

  • The reason that the '@app.udpate' is called is '@pack.deductible != @pac_data[:deductible]' becomes true
  • I should define '@pack.deductible', namely, add a 'should_receive(:deductible)' method to '@pack' flexmock

Experiment

test/test_plugin/bsv_xml.rb#test_update__conflicted_registration

    def test_update_preparation__conflicted_package
      package = setup_package :pharmacode => "987654",
                              :steps => %w{39271 02 028},
                              :price_public => Util::Money.new(17.65),
                              :price_exfactory => Util::Money.new(11.22)

package.should_receive(:deductible).and_return(:deductible_g)

      reg = setup_registration :iksnr => '39271', :package => package
      reg.should_receive(:packages).and_return []
      package.should_receive(:registration).and_return reg
      flexmock(Package).should_receive(:find_by_pharmacode).
                        times(1).and_return nil
      setup_meddata_server :ean13 => '7680392710281'
      @app.should_receive(:registration).and_return reg
      @app.should_receive(:each_package)
      expected_updates = {}
      ptr = Persistence::Pointer.new [:registration, '39271']
      expected_updates.store ptr, { :generic_type => :original,
                                    :index_therapeuticus => '07.10.10.' }

expected_pointer = ptr

      ptr += [:sequence, '02']
      pac_pointer = ptr += [:package, '028']
      #@app.should_receive(:update).and_return do |ptr, data|
      @app.should_receive(:update).and_return do |pointer, update_data|
        #assert_equal expected_updates.delete(ptr), data

assert_equal expected_pointer, pointer
assert_equal expected_updates[pointer], update_data

      end
      @plugin.update_preparations StringIO.new(@conflicted_src)
      #assert_equal({}, expected_updates)
      assert_equal({}, @plugin.change_flags)
      listener = @plugin.preparations_listener
      expected = [ {
        :name_base          => "Ponstan",
        :name_descr         => "Filmtabs 500 mg ",
        :swissmedic_no5_bag => "12345",
        :swissmedic_no8_bag => "39271028",
        :pharmacode_bag     => "703279",
        :pharmacode_oddb    => "987654",
        :generic_type       => :original,
        :deductible         => :deductible_g,
        :atc_class          => "M01AG01",
      } ]
      assert_equal expected, listener.conflicted_packages
      assert_equal [], listener.conflicted_registrations
      assert_equal [], listener.unknown_packages
      expected = []
      assert_equal [], listener.unknown_registrations
    end

Result

masa@masa ~/ywesee/oddb.org $ ruby test/test_plugin/bsv_xml.rb 
Loaded suite test/test_plugin/bsv_xml
Started
.
Finished in 0.029053 seconds.

1 tests, 8 assertions, 0 failures, 0 errors

Note

  • Good

Check all the tests

masa@masa ~/ywesee/oddb.org $ ruby test/test_plugin/bsv_xml.rb 
Loaded suite test/test_plugin/bsv_xml
Started
.........
Finished in 0.147585 seconds.

9 tests, 71 assertions, 0 failures, 0 errors

Note

  • Very good

Then

  • Add a new test-case for the updating

Add a new test-case for the updating

Design

  • The test code of the updating should be in 'test_update_preparation' method

Preparation

  • Comment out the other test methods (remain only the 'test_update_preparation' method)

Confirm

masa@masa ~/ywesee/oddb.org $ ruby test/test_plugin/bsv_xml.rb 
Loaded suite test/test_plugin/bsv_xml
Started
.
Finished in 0.03303 seconds.

1 tests, 10 assertions, 0 failures, 0 errors

suspend

  • Change my mind
  • It is easy to test the updating by creating a new test-case
  • It would be goot to make a new test-case from 'test_update_preparation__conflicted_package'
    • because the updated code is executed in this test-case

Tempate

    def test_update_preparation__change_only_SB_flag
      assert(true)
    end

Check it passes

masa@masa ~/ywesee/oddb.org $ ruby test/test_plugin/bsv_xml.rb 
Loaded suite test/test_plugin/bsv_xml
Started
.
Finished in 0.00025 seconds.

1 tests, 1 assertions, 0 failures, 0 errors
view · edit · sidebar · attach · print · history
Page last modified on January 10, 2011, at 04:47 PM