Skip to content

Commit

Permalink
Fix undefined method first in RubyXL::Row. Add unit test for plugin/s…
Browse files Browse the repository at this point in the history
…wissmedic
  • Loading branch information
ngiger committed Jul 8, 2014
1 parent a97fe23 commit c31dccc
Show file tree
Hide file tree
Showing 16 changed files with 255 additions and 242 deletions.
4 changes: 2 additions & 2 deletions Gemfile
Expand Up @@ -46,10 +46,10 @@ gem 'wasabi', '2.3.0'
gem 'savon', '0.9.7'
gem 'sbsm', '1.2.6', :git => 'https://github.com/ngiger/sbsm.git'
gem 'spreadsheet', '0.9.7'
gem 'swissmedic-diff', '0.1.7'
gem 'swissmedic-diff', '0.1.8'
gem 'webrobots', '0.1.1'
gem 'ydim', '1.0.0'
gem 'ydocx', '1.2.4'
gem 'ydocx', '1.2.5'
gem 'yus', '1.0.1'

group :development, :test do
Expand Down
8 changes: 4 additions & 4 deletions Gemfile.lock
Expand Up @@ -169,7 +169,7 @@ GEM
slop (3.5.0)
spreadsheet (0.9.7)
ruby-ole (>= 1.0)
swissmedic-diff (0.1.7)
swissmedic-diff (0.1.8)
thread_safe (0.3.4)
travis-lint (1.8.0)
hashr (~> 0.0.22)
Expand All @@ -191,7 +191,7 @@ GEM
webrobots (0.1.1)
websocket (1.0.7)
ydim (1.0.0)
ydocx (1.2.4)
ydocx (1.2.5)
yml_reader (0.3)
yus (1.0.1)

Expand Down Expand Up @@ -250,12 +250,12 @@ DEPENDENCIES
sbsm (= 1.2.6)!
simplecov (~> 0.7.1)
spreadsheet (= 0.9.7)
swissmedic-diff (= 0.1.7)
swissmedic-diff (= 0.1.8)
travis-lint
wasabi (= 2.3.0)
watir
watir-webdriver
webrobots (= 0.1.1)
ydim (= 1.0.0)
ydocx (= 1.2.4)
ydocx (= 1.2.5)
yus (= 1.0.1)
23 changes: 19 additions & 4 deletions src/plugin/swissmedic.rb
Expand Up @@ -14,6 +14,15 @@
require 'swissmedic-diff'
require 'util/logfile'

# Some monkey patching needed to avoid an error
module RubyXL
class Row < OOXMLObject
def first
cells[0]
end
end
end

module ODDB
class SwissmedicPlugin < Plugin
PREPARATIONS_COLUMNS = [ :iksnr, :seqnr, :name_base, :company, :export_flag,
Expand All @@ -39,7 +48,7 @@ def initialize(app=nil, archive=ARCHIVE_PATH)
@empty_compositions = []
end
def debug_msg(msg)
# $stdout.puts Time.now.to_s + ': ' + msg; $stdout.flush
if defined?(MiniTest) then $stdout.puts Time.now.to_s + ': ' + msg; $stdout.flush; return end
if not defined?(@checkLog) or not @checkLog
name = LogFile.filename('oddb/debug/', Time.now)
FileUtils.makedirs(File.dirname(name))
Expand All @@ -64,6 +73,11 @@ def update(agent=Mechanize.new, target=get_latest_file(agent))
end
# check diff from stored data about date-fields of Registration
check_date!
if @latest and File.exists?(@latest)
debug_msg "#{__FILE__}: #{__LINE__} Compared #{target} #{File.size(target)} bytes with #{@latest} #{File.size(@latest)} bytes"
else
debug_msg "#{__FILE__}: #{__LINE__} No @latest #{@latest} exists"
end
debug_msg "#{__FILE__}: #{__LINE__} Found #{@diff.news.size} news, #{@diff.updates.size} updates, #{@diff.replacements.size} replacements and #{@diff.package_deletions.size} package_deletions"
debug_msg "#{__FILE__}: #{__LINE__} changes: #{@diff.changes.inspect}"
# debug_msg "#{__FILE__}: #{__LINE__} first news: #{@diff.news.first.inspect}"
Expand All @@ -80,7 +94,7 @@ def update(agent=Mechanize.new, target=get_latest_file(agent))
deactivate @diff.sequence_deletions
deactivate @diff.registration_deletions
end_time = Time.now - start_time
@update_time = (end_time / 60.0)
@update_time = (end_time / 60.0).to_i
if File.exists?(target) and File.exists?(@latest) and FileUtils.compare_file(target, @latest)
debug_msg "#{__FILE__}: #{__LINE__} rm_f #{target} after #{@update_time} minutes"
FileUtils.rm_f(target, :verbose => true)
Expand Down Expand Up @@ -256,6 +270,7 @@ def get_latest_file(agent, keyword='Packungen', extension = '.xlsx')
link = links.first or raise "could not identify url to #{keyword}.xlsx"
file = agent.get(link.href)
download = file.body

latest_name = File.join @archive, "#{keyword}-latest"+extension
if extension == '.xlsx'
latest_xls = latest_name.sub('.xlsx', '.xls')
Expand All @@ -273,7 +288,7 @@ def get_latest_file(agent, keyword='Packungen', extension = '.xlsx')
target = File.join @archive, @@today.strftime("#{keyword}-%Y.%m.%d.xlsx")
if(!File.exist?(latest_name) or download.size != File.size(latest_name))
File.open(target, 'w') { |fh| fh.puts(download) }
msg = "#{__FILE__}: #{__LINE__} updated download.size is #{download.size}."
msg = "#{__FILE__}: #{__LINE__} updated download.size is #{download.size} -> #{target} #{File.size(target)}"
msg += "#{target} now #{File.size(target)} bytes != #{latest_name} #{File.size(latest_name)}" if File.exists?(latest_name)
debug_msg(msg)
target
Expand Down Expand Up @@ -418,7 +433,7 @@ def resolve_link(ptr)
end
end
#def rows_diff(row, other, ignore = [:product_group, :atc_class, :sequence_date])
def rows_diff(row, other, ignore = [:atc_class, :sequence_date])
def rows_diff(row, other, ignore = [:atc_class, :sequence_date])
flags = super(row, other, ignore)
if other.first.is_a?(String) \
&& (reg = @app.registration("%05i" % cell(row, column(:iksnr)).to_i)) \
Expand Down
Binary file added test/data/xls/Packungen_2014_01.xlsx
Binary file not shown.
Binary file added test/data/xls/Packungen_2014_small.xlsx
Binary file not shown.
Binary file added test/data/xlsx/CoMarketing_small_010514.xlsx
Binary file not shown.
Binary file added test/data/xlsx/Packungen.initial.xlsx
Binary file not shown.
Binary file added test/data/xlsx/Packungen_2014_01.xlsx
Binary file not shown.
Binary file added test/data/xlsx/Packungen_2014_small.xlsx
Binary file not shown.
Binary file added test/data/xlsx/Präparateliste-latest.xlsx
Binary file not shown.
Binary file added test/data/xlsx/Präparateliste.xlsx
Binary file not shown.
139 changes: 139 additions & 0 deletions test/stub/oddbapp.rb
Expand Up @@ -32,4 +32,143 @@ class App < SBSM::DRbServer
RUN_EXPORTER = false
RUN_UPDATER = false
end
module Admin
class Subsystem; end
end
class PowerUser; end
class CompanyUser; end
class RootUser
def initialize
@oid = 0
@unique_email = 'test@oddb.org'
@pass_hash = Digest::MD5::hexdigest('test')
@pointer = Pointer.new([:user, 0])
end
end
class Registration
attr_writer :sequences
end
class Sequence
attr_accessor :packages
end
module Persistence
class Pointer
public :directions
end
end
class GalenicGroup
attr_accessor :galenic_forms
def GalenicGroup::reset_oids
@oid = 0
end
end
end
module DRb
class DRbObject
def respond_to?(msg_id, *args)
case msg_id
when :_dump
true
when :marshal_dump
false
else
true
# method_missing(:respond_to?, msg_id)
end
end
end
end

# some StubSequence

class StubSequence
attr_reader :name_base, :name_descr, :atc_class
def initialize(name_base, atc_class)
@name_base = name_base
@atc_class = atc_class
end
def name
@name_base
end
end
class StubAtcClass
attr_reader :code
def initialize(halb)
@code = halb
end
end
class StubAtcClassFactory
class << self
def atc(code)
(@atc ||= {}).fetch(code) {
@atc.store(code, StubAtcClass.new(code))
}
end
end
end
class StubRegistration
attr_reader :iksnr, :block_result
def initialize(key=nil)
@iksnr = key
end
def active_package_count
3
end
def replace(registration)
end
def sequences
{
:foo => StubSequence.new('blah', StubAtcClassFactory.atc('1')),
:bar => StubSequence.new('blahdiblah', StubAtcClassFactory.atc('2')),
:rob => StubSequence.new('frohbus', nil),
}
end
def atcless_sequences
[
StubSequence.new('no_atc', nil)
]
end
def each_package(&block)
@block_result = block.call(@iksnr)
end
end
class StubGalenicForm
include ODDB::Language
attr_reader :name
def initialize(name)
self.update_values({ 'de' => name })
@name = name
end
end
class StubGalenicGroup
attr_writer :galenic_form
attr_reader :block_result
def each_galenic_form(&block)
@block_result = block.call(@galenic_form)
end
def empty?
@galenic_form.nil?
end
def get_galenic_form(description)
@galenic_form
end
end
class StubSubstance
attr_reader :name
def initialize(name, similar)
@name = name
@similar = similar
end
def <=>(other)
@name.downcase <=> other.name.downcase
end
end
class StubRegistration2
attr_accessor :sequences, :pointer, :descriptions
def initialize
@descriptions = {}
end
def indication
self
end
end
6 changes: 3 additions & 3 deletions test/test_plugin/bsv_xml.rb
Expand Up @@ -675,7 +675,7 @@ def test__update
entry = flexmock('entry') do |e|
e.should_receive(:name).and_return('AbCdef-123.xml')
end
flexstub(Zip::ZipFile) do |z|
flexstub(Zip::File) do |z|
z.should_receive(:foreach).and_yield(entry)
end
flexstub(@plugin) do |p|
Expand All @@ -690,7 +690,7 @@ def test__update_do_nothing
entry = flexmock('entry') do |e|
e.should_receive(:name).and_return('Publications.xls')
end
flexstub(Zip::ZipFile) do |z|
flexstub(Zip::File) do |z|
z.should_receive(:foreach).and_yield(entry)
end
assert_equal(nil, @plugin._update('path'))
Expand Down Expand Up @@ -1637,7 +1637,7 @@ def test_update_it_codes
@app.should_receive(:update).times(38).and_return do |ptr, data|
updates.push data
end
zip = Zip::ZipFile.open(@zip)
zip = Zip::File.open(@zip)
zip.find_entry('ItCodes.xml').get_input_stream do |io|
@plugin.update_it_codes io
end
Expand Down

0 comments on commit c31dccc

Please sign in to comment.