<< Masa.20101224-check-problem-Ruby_1_8_7-study-ydim | 2010 | Masa.20101222-update-ch_oddb_org-generics_xls >>
ext/export/test/test_generics_xls.rb
def test_export_generic pac = flexstub(Package) do |pacobj| pacobj.should_receive(:basename).and_return("basename") pacobj.should_receive(:dose).and_return("dose") pacobj.should_receive(:comparable_size).and_return(111) pacobj.should_receive(:barcode).and_return(222) pacobj.should_receive(:pharmacode).and_return(333) pacobj.should_receive(:name).and_return("name") pacobj.should_receive(:price_exfactory).and_return(444.444) pacobj.should_receive(:price_public).and_return(555.555) pacobj.should_receive(:company_name).and_return("company_name") pacobj.should_receive(:ikscat).and_return(666) pacobj.should_receive(:sl_entry).and_return('SL') pacobj.should_receive(:registration_date).and_return(Date.new(2010,12,31)) pacobj.should_receive(:"registration.pointer").and_return(123) pacobj.should_receive(:pointer).and_return(123) end expect_row = ["", "", "", "", "", "", "", "", "", "", "", "", "", "222", "333", "name", "dose", "111", "444.44", "555.55", "company_name", "666", "SL", "31.12.2010", "Generikum: neue Registration, Preissenkung"] flexstub(Spreadsheet::Excel) do |klass| klass.should_receive(:new).and_return(flexmock{|book| book.should_receive(:add_worksheet).and_return(flexmock{|sheet| sheet.should_receive(:format_column) sheet.should_receive(:write).with(0,0,Array, Spreadsheet::Format) sheet.should_receive(:write).with(1,0,expect_row) # This is the check point }) }) end generics_xls = GenericXls.new(".") assert_equal(2, generics_xls.export_generic(pac)) end
Result
masa@masa ~/ywesee/oddb.org/ext/export/test $ ruby test_generics_xls.rb Loaded suite test_generics_xls Started ......... Finished in 0.028024 seconds. 9 tests, 10 assertions, 0 failures, 0 errors
Notes
def test_export_comparable pac = flexstub(Package) do |pacobj| pacobj.should_receive(:basename).and_return("basename") pacobj.should_receive(:dose).and_return("dose") pacobj.should_receive(:comparable_size).and_return(111) pacobj.should_receive(:barcode).and_return(222) pacobj.should_receive(:pharmacode).and_return(333) pacobj.should_receive(:name).and_return("name") pacobj.should_receive(:price_exfactory).and_return(444.444) pacobj.should_receive(:price_public).and_return(555.555) pacobj.should_receive(:company_name).and_return("company_name") pacobj.should_receive(:ikscat).and_return(666) pacobj.should_receive(:sl_entry).and_return('SL') pacobj.should_receive(:registration_date).and_return(Date.new(2010,12,31)) pacobj.should_receive(:"registration.pointer").and_return(123) pacobj.should_receive(:pointer).and_return(123) end expect_row = ["basename", "basename dose/111", "222", "333", "name", "dose", "111", "444.44", "555.55", "company_name", "666", "SL", "31.12.2010", "222", "333", "name", "dose", "111", "444.44", "555.55", "company_name", "666", "SL", "31.12.2010", "Original: neue Registration, Preissenkung Generikum: neue Registration, Preissenkung"] flexstub(Spreadsheet::Excel) do |klass| klass.should_receive(:new).and_return(flexmock{|book| book.should_receive(:add_worksheet).and_return(flexmock{|sheet| sheet.should_receive(:format_column) sheet.should_receive(:write).with(0,0,Array, Spreadsheet::Format) sheet.should_receive(:write).with(1,0,expect_row) # This is the check point }) }) end generics_xls = GenericXls.new(".") assert_equal(2, generics_xls.export_comparable(pac, pac)) end
Result
masa@masa ~/ywesee/oddb.org/ext/export/test $ ruby test_generics_xls.rb Loaded suite test_generics_xls Started .......... Finished in 0.033548 seconds. 10 tests, 11 assertions, 0 failures, 0 errors
def test_export_comparables pac = flexstub(Package) do |pacobj| pacobj.should_receive(:basename).and_return("basename") pacobj.should_receive(:dose).and_return("dose") pacobj.should_receive(:comparable_size).and_return(111) pacobj.should_receive(:barcode).and_return(222) pacobj.should_receive(:pharmacode).and_return(333) pacobj.should_receive(:name).and_return("name") pacobj.should_receive(:price_exfactory).and_return(444.444) pacobj.should_receive(:price_public).and_return(555.555) pacobj.should_receive(:company_name).and_return("company_name") pacobj.should_receive(:ikscat).and_return(666) pacobj.should_receive(:sl_entry).and_return('SL') pacobj.should_receive(:registration_date).and_return(Date.new(2010,12,31)) pacobj.should_receive(:"registration.pointer").and_return(123) pacobj.should_receive(:pointer).and_return(123) pacobj.should_receive(:comparables).and_return([pac]) pacobj.should_receive(:"registration.generic?").and_return(true) end expect_row = ["basename", "basename dose/111", "222", "333", "name", "dose", "111", "444.44", "555.55", "company_name", "666", "SL", "31.12.2010", "222", "333", "name", "dose", "111", "444.44", "555.55", "company_name", "666", "SL", "31.12.2010", "Original: neue Registration, Preissenkung Generikum: neue Registration, Preissenkung"] flexstub(Spreadsheet::Excel) do |klass| klass.should_receive(:new).and_return(flexmock{|book| book.should_receive(:add_worksheet).and_return(flexmock{|sheet| sheet.should_receive(:format_column) sheet.should_receive(:write).with(0,0,Array, Spreadsheet::Format) sheet.should_receive(:write).with(1,0,expect_row) # This is the check point }) }) end generics_xls = GenericXls.new(".") assert_equal(2, generics_xls.export_comparable(pac, pac)) end
Result
masa@masa ~/ywesee/oddb.org/ext/export/test $ ruby test_generics_xls.rb Loaded suite test_generics_xls Started ........... Finished in 0.039299 seconds. 11 tests, 12 assertions, 0 failures, 0 errors
def setup loggroup_swiss = LogGroup.new(:swissmedic_journal) loggroup_swiss.create_log(Date.today) loggroup_swiss.latest.change_flags = {123 => [:new]} loggroup_bsv = LogGroup.new(:bsv_sl) loggroup_bsv.create_log(Date.today) loggroup_bsv.latest.change_flags = {123 => [:price_cut]} pac = flexstub(Package) do |pack| pack.should_receive(:public?).and_return(true) pack.should_receive(:"registration.active?").and_return(true) pack.should_receive(:"registration.original?").and_return(true) pack.should_receive(:comparables).and_return([]) pack.should_receive(:"registration.generic?").and_return(false) end flexstub(ODBA.cache) do |cacheobj| cacheobj.should_receive(:fetch_named).and_return do flexmock do |appobj| appobj.should_receive(:log_group).with(:swissmedic_journal).and_return(loggroup_swiss) appobj.should_receive(:log_group).with(:bsv_sl).and_return(loggroup_bsv) appobj.should_receive(:each_package).and_yield(pac) end end end @generics_xls = GenericXls.new(".") end ... def test_export_generics assert_equal(2, @generics_xls.export_generics) end
Result
masa@masa ~/ywesee/oddb.org/ext/export/test $ ruby test_generics_xls.rb Loaded suite test_generics_xls Started ............ Finished in 0.049937 seconds. 12 tests, 13 assertions, 0 failures, 0 errors
Notes
Updated
def test_export_generics__case_no_output # Note: # if the return value of comparables is not empty (point.1), or # if the return value of registration.generics? is not false (ture) (point.2), # then you have to define the other method in the flexstub(Package), # since export_comparables or export_generic will be called. pac = flexstub(Package) do |pack| pack.should_receive(:public?).and_return(true) pack.should_receive(:"registration.active?").and_return(true) pack.should_receive(:"registration.original?").and_return(true) pack.should_receive(:comparables).and_return([]) # point.1 pack.should_receive(:"registration.generic?").and_return(false) # point.2 end # This is a trick code, a little bit different from the flexstub in setup method # That is why I can re-define the ODBA stub for this method flexstub(ODBA) do |odba| odba.should_receive(:cache).and_return(flexmock{|cache| cache.should_receive(:fetch_named).and_return(flexmock{|app| app.should_receive(:log_group).with(:swissmedic_journal).and_return(@loggroup_swiss) app.should_receive(:log_group).with(:bsv_sl).and_return(@loggroup_bsv) app.should_receive(:each_package).and_yield(pac) }) }) end generics_xls = GenericXls.new(".") assert_equal(2, generics_xls.export_generics) end
Result
masa@masa ~/ywesee/oddb.org/ext/export/test $ ruby test_generics_xls.rb Loaded suite test_generics_xls Started ............ Finished in 0.044519 seconds. 12 tests, 13 assertions, 0 failures, 0 errors
def test_export_generics__case_warning pac = flexstub(Package) do |pack| pack.should_receive(:public?).and_return(true) pack.should_receive(:"registration.active?").and_return(true) pack.should_receive(:"registration.original?").and_return(true) pack.should_receive(:comparables).and_return([pac]) pack.should_receive(:basename).and_return(nil) # This is the point pack.should_receive(:company_name).and_return("company_name") pack.should_receive(:barcode).and_return("barcode") end flexstub(ODBA) do |odba| odba.should_receive(:cache).and_return(flexmock{|cache| cache.should_receive(:fetch_named).and_return(flexmock{|app| app.should_receive(:log_group).with(:swissmedic_journal).and_return(@loggroup_swiss) app.should_receive(:log_group).with(:bsv_sl).and_return(@loggroup_bsv) app.should_receive(:each_package).and_yield(pac) }) }) end # Note: # if the following flexstub is not defined, # an actual email will be sent. flexstub(Log) do |log| log.should_receive(:new) end generics_xls = GenericXls.new(".") assert_raise(NoMethodError) do # This means the report process runs if this assert passes generics_xls.export_generics end end
Result
masa@masa ~/ywesee/oddb.org/ext/export/test $ ruby test_generics_xls.rb Loaded suite test_generics_xls Started ............. Finished in 0.049993 seconds. 13 tests, 14 assertions, 0 failures, 0 errors
def test_export_generics__case_export pac = flexstub(Package) do |pack| pack.should_receive(:public?).and_return(true) pack.should_receive(:"registration.active?").and_return(true) pack.should_receive(:"registration.original?").and_return(true) pack.should_receive(:comparables).and_return([]) pack.should_receive(:basename).and_return("basename") # This is the point pack.should_receive(:"registration.generic?").and_return(true) # This is the point # for test_export_generic pack.should_receive(:dose).and_return("dose") pack.should_receive(:comparable_size).and_return(111) pack.should_receive(:barcode).and_return(222) pack.should_receive(:pharmacode).and_return(333) pack.should_receive(:name).and_return("name") pack.should_receive(:price_exfactory).and_return(444.444) pack.should_receive(:price_public).and_return(555.555) pack.should_receive(:company_name).and_return("company_name") pack.should_receive(:ikscat).and_return(666) pack.should_receive(:sl_entry).and_return('SL') pack.should_receive(:registration_date).and_return(Date.new(2010,12,31)) pack.should_receive(:"registration.pointer").and_return(123) pack.should_receive(:pointer).and_return(123) end flexstub(ODBA) do |odba| odba.should_receive(:cache).and_return(flexmock{|cache| cache.should_receive(:fetch_named).and_return(flexmock{|app| app.should_receive(:log_group).with(:swissmedic_journal).and_return(@loggroup_swiss) app.should_receive(:log_group).with(:bsv_sl).and_return(@loggroup_bsv) app.should_receive(:each_package).and_yield(pac) }) }) end generics_xls = GenericXls.new(".") assert_equal(3, generics_xls.export_generics)
Result
masa@masa ~/ywesee/oddb.org/ext/export/test $ ruby test_generics_xls.rb Loaded suite test_generics_xls Started .............. Finished in 0.055982 seconds. 14 tests, 15 assertions, 0 failures, 0 errors
Memo
Example
def setup @loggroup_swiss = LogGroup.new(:swissmedic_journal) @loggroup_swiss.create_log(Date.today) @loggroup_swiss.latest.change_flags = {123 => [:new]} @loggroup_bsv = LogGroup.new(:bsv_sl) @loggroup_bsv.create_log(Date.today) @loggroup_bsv.latest.change_flags = {123 => [:price_cut]} flexstub(ODBA.cache) do |cacheobj| cacheobj.should_receive(:fetch_named).and_return do flexmock do |appobj| appobj.should_receive(:log_group).with(:swissmedic_journal).and_return(@loggroup_swiss) appobj.should_receive(:log_group).with(:bsv_sl).and_return(@loggroup_bsv) end end end @pac = flexmock('Package') do |pack| pack.should_receive(:"registration.pointer").and_return(999) pack.should_receive(:pointer).and_return(999) end @generics_xls = GenericXls.new(".") end def test__remarks1 #pac = flexstub(Package) do |pack| pac = flexstub(@pac) do |pack| #pack.should_receive(:"registration.pointer").and_return(999) #pack.should_receive(:pointer).and_return(999) end assert_nil(@generics_xls._remarks(pac, 'Generikum')) end
Note
Commit
dbi sample
# simple.rb - connection test by using Ruby DBI #require 'postgres' require 'dbi' #require 'dbd/pg' begin # connection to database dbh = DBI.connect("dbi:pg:testdb:localhost", "masa", "") # get server version string row = dbh.select_one("select version()") puts "Server version: " + row[0] rescue DBI::DatabaseError => e puts "An error occurred" puts "Error code: #{e.err}" puts "Error message: #{e.errstr}" ensure # disconnect dbh.disconnect if dbh end
Check PostgreSQL DB
masa@masa ~/work $ psql -U postgres psql (8.4.2) Geben Sie »help« für Hilfe ein. postgres=# \l Liste der Datenbanken Name | Eigentümer | Kodierung | Sortierfolge | Zeichentyp | Zugriffsrechte -------------+-------------+-----------+--------------+------------+----------------------- testdb | masa | UTF8 | C | C |
Check drivers
masa@masa ~/work $ gem list pg (0.9.0) postgres (0.7.9.2008.01.28)
Result
masa@masa ~/work $ ruby dbi_test.rb Server version: PostgreSQL 8.4.2 on x86_64-pc-linux-gnu, compiled by GCC x86_64-pc-linux-gnu-gcc (Gentoo 4.4.3 p1.0) 4.4.3, 64-bit
Check Ruby-DBI version
* dev-ruby/ruby-dbi Latest version available: 0.2.0-r1 Latest version installed: 0.2.0-r1 Size of files: 97 kB Homepage: http://ruby-dbi.rubyforge.org Description: Ruby/DBI - a database independent interface for accessing databases - similar to Perl's DBI License: BSD
Links
Memo
Important part
dbh = DBI.connect("dbi:pg:testdb:localhost", "masa", "")
Notes
Experiment
require 'dbi' print "Available drivers=" p DBI.available_drivers
Result
masa@masa ~/work $ ruby test.rb Available drivers=["dbi:SQLRelay:", "dbi:Proxy:", "dbi:Pg:"]
Format
DBI.connect("DBI:[Driver]:[DB]:[Host]", "db_user", "db_pass")
Notes
dbd-pg (0.3.9)
masa@masa ~/work $ emerge -s dbd-pg * dev-ruby/dbd-pg Latest version available: 0.3.9 Latest version installed: [ Not Installed ] Size of files: 63 kB Homepage: http://ruby-dbi.rubyforge.org Description: The PostgreSQL database driver (DBD) for Ruby/DBI License: BSD masa@masa ~/work $ gem search dbd-pg -r *** REMOTE GEMS *** dbd-pg (0.3.9)
pg (0.9.0)
* dev-ruby/pg Latest version available: 0.9.0-r1 Latest version installed: 0.9.0-r1 Size of files: 98 kB Homepage: http://bitbucket.org/ged/ruby-pg/ Description: Ruby extension library providing an API to PostgreSQL License: || ( GPL-2 Ruby ) masa@masa ~/work $ gem search pg -r pg (0.10.0, 0.9.0 x86-mingw32 x86-mswin32, 0.8.0 x86-mswin32-60)
ruby-pg (0.7.9.2008.01.28)
masa@masa ~/work $ gem search ruby-pg -r *** REMOTE GEMS *** ruby-pg (0.7.9.2008.01.28)
ruby-postgres (0.7.9.20080128)
masa@masa ~/work $ emerge -s ruby-postgre * dev-ruby/ruby-postgres Latest version available: 0.7.9.20080128-r1 Latest version installed: 0.7.9.20080128 Size of files: 32 kB Homepage: http://ruby.scripting.ca/postgres Description: An extension library to access a PostgreSQL database from Ruby License: GPL-2 Ruby masa@masa ~/work $ gem search ruby-postgres -r *** REMOTE GEMS *** ruby-postgres (0.7.1.2006.04.06 ruby mswin32)
postgres (0.7.9.2008.01.28)
masa@masa ~/work $ gem search postgres -r *** REMOTE GEMS *** postgres (0.7.9.2008.01.28)
postgres-pr (0.6.3)
masa@masa ~/work $ gem search postgres -r *** REMOTE GEMS *** postgres-pr (0.6.3)
Notes
Experiment
masa@masa ~/work $ ruby dbi_test.rb Server version: PostgreSQL 8.4.2 on x86_64-pc-linux-gnu, compiled by GCC x86_64-pc-linux-gnu-gcc (Gentoo 4.4.3 p1.0) 4.4.3, 64-bit
Uninstall ruby-postgres
masa@masa ~/ywesee/oddb.org $ sudo emerge -C ruby-postgres
Check dbi_test
masa@masa ~/work $ ruby dbi_test.rb Server version: PostgreSQL 8.4.2 on x86_64-pc-linux-gnu, compiled by GCC x86_64-pc-linux-gnu-gcc (Gentoo 4.4.3 p1.0) 4.4.3, 64-bit
Note
Uninstall pg
masa@masa ~/work $ sudo gem uninstall pg Successfully uninstalled pg-0.9.0
Check dbi_test
masa@masa ~/work $ ruby dbi_test.rb /usr/lib64/ruby/site_ruby/1.8/dbi.rb:368:in `load_driver': Could not load driver (no such file to load -- pg) (DBI::InterfaceError) from /usr/lib64/ruby/site_ruby/1.8/dbi.rb:233:in `_get_full_driver' from /usr/lib64/ruby/site_ruby/1.8/dbi.rb:219:in `connect' from dbi_test.rb:9
Re-install pg
masa@masa ~/work $ sudo gem install pg ERROR: Error installing pg: pg requires Ruby version >= 1.8.7.
Note
Oh my GOD!!
masa@masa ~/work $ sudo gem install pg --version "< 0.9.0" Passwort: Building native extensions. This could take a while... Successfully installed pg-0.8.0 1 gem installed /usr/lib64/ruby/gems/1.8/gems/rdoc-2.5.11/lib/rdoc/ruby_lex.rb:67: warning: parenthesize argument(s) for future version Installing ri documentation for pg-0.8.0... Installing RDoc documentation for pg-0.8.0...
Check dbi_test.rb
masa@masa ~/work $ ruby dbi_test.rb Server version: PostgreSQL 8.4.2 on x86_64-pc-linux-gnu, compiled by GCC x86_64-pc-linux-gnu-gcc (Gentoo 4.4.3 p1.0) 4.4.3, 64-bit
Check oddb.org
Run
Access
Result
Note
Commit
Installer
Installer
* Devel / bison * Devel / gcc-core * Devel / flex * Devel / gettext-devel * Devel / make * Devel / readline * Devel / zlib-devel * Perl / perl
Check gem command on Cwgwin
masa@masa-win7 ~ $ gem list /cygdrive/c/Ruby186/bin/gem:8:in `require': no such file to load -- rubygems (Lo adError) from /cygdrive/c/Ruby186/bin/gem:8
Note
masa@masa-win7 ~/rubygems-1.3.7 $ ruby setup.rb masa@masa-win7 ~/rubygems-1.3.7 $ gem -v 1.3.7
Note
Donwload postgresql source code (same version with the postgreSQL installed)
Compile
$ tar jxvf postgresql-8.4.0.tar.bz2 $ cd postgresql-8.4.0 $ export PGSRC=`pwd` $ ./configure --enable-thread-safety $ cd $PGSRC/src/bin $ make $ make install $ cd $PGSRC/src/interfaces/libpq $ make install
Set environment variables
$ cat ~/.bashrc export PATH=/usr/local/pgsql/bin:/usr/local/pgsql/lib:$PATH export PGHOST=localhost
Confirm psql command
masa@masa-win7 ~/postgresql-8.4.6/src/interfaces/libpq $ psql --version psql (PostgreSQL) 8.4.6 contains support for command-line editing
Note
Next