Skip to content

Commit

Permalink
Fix daily-import of text_info
Browse files Browse the repository at this point in the history
  • Loading branch information
ngiger committed Oct 20, 2014
1 parent 0f2a77d commit 213c793
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 58 deletions.
7 changes: 2 additions & 5 deletions src/plugin/text_info.rb
Expand Up @@ -887,11 +887,7 @@ def swissmedicinfo_index(state)
_names << [tds[i.first].text, tds[i.last].text]
end
end
names[typ.downcase.intern] =
_names.sort_by do |name, date|
Date.strptime(date, "%d.%m.%Y")
end.reverse!
end
names[typ.downcase.intern] = _names.sort.reverse end
index[lang.downcase.intern] = names
end
index
Expand Down Expand Up @@ -1003,6 +999,7 @@ def match(node_set, name)
found_node ? [found_node] : []
end
end.new).first
return nil, nil,nil,nil unless match
if match
content = match.parent.at('./content')
styles = match.parent.at('./style').text
Expand Down
2 changes: 1 addition & 1 deletion src/util/mail.rb
Expand Up @@ -97,7 +97,7 @@ def Util.send_mail(list_and_recipients, mail_subject, mail_body, override_from =
mail.body mail_body. respond_to?(:force_encoding) ? mail_body. force_encoding("utf-8") : mail_body
log_and_deliver_mail(mail)
rescue => e
msg = "Util.send_mail rescue: error is #{e.inspect} recipients #{recipients.inspect} #{caller[0..10].join("\n")}"
msg = "Util.send_mail rescue: error is #{e.inspect} recipients #{recipients.inspect} #{caller.join("\n")}"
msg += "\n#{mail_subject}"
msg += "\n#{mail_body.to_s[0..160]}"
Util.debug_msg(msg)
Expand Down
124 changes: 72 additions & 52 deletions test/test_plugin/text_info_swissmedicinfo.rb
Expand Up @@ -233,52 +233,6 @@ def teardown
FileUtils.rm_rf @@vardir
super # to clean up FlexMock
end

def setup_mechanize mapping=[]
agent = flexmock Mechanize.new
@pages = Hash.new(0)
@actions = {}
mapping.each do |page, method, url, formname, page2|
path = File.join @@datadir, page
page = setup_page url, path, agent
if formname
form = flexmock page.form(formname)
action = form.action
page = flexmock page
page.should_receive(:form).with(formname).and_return(form)
path2 = File.join @@datadir, page2
page2 = setup_page action, path2, agent
agent.should_receive(:submit).and_return page2
end
case method
when :get, :post
agent.should_receive(method).with(url).and_return do |*args|
@pages[[method, url, *args]] += 1
page
end
when :submit
@actions[url] = page
agent.should_receive(method).and_return do |form, *args|
action = form.action
@pages[[method, action, *args]] += 1
@actions[action]
end
else
agent.should_receive(method).and_return do |*args|
@pages[[method, *args]] += 1
page
end
end
end
agent
end

def setup_page url, path, agent
response = {'content-type' => 'text/html'}
Mechanize::Page.new(URI.parse(url), response,
File.read(path), 200, agent)
end

def setup_fachinfo_document heading, text
fi = FachinfoDocument.new
fi.iksnrs = Text::Chapter.new
Expand All @@ -287,12 +241,6 @@ def setup_fachinfo_document heading, text
fi
end

def test_init_agent
agent = @plugin.init_agent
assert_instance_of Mechanize, agent
assert /Mozilla/.match(agent.user_agent)
end

def test_import_swissmedicinfo_xml
reg = flexmock('registration4',
:new => 'new',
Expand Down Expand Up @@ -332,6 +280,78 @@ def test_import_swissmedicinfo_xml
assert(@plugin.import_swissmedicinfo(@opts), 'must be able to run import_swissmedicinfo')
end

def test_import_swissmedicinfo_no_iksnr
reg = flexmock('registration4',
:new => 'new',
:store => 'store',
:export_flag => false,
:inactive? => false,
:package => :package,
:expiration_date => false,
)

reg.should_receive(:fachinfo)
ptr = Persistence::Pointer.new([:registration, '32917'])
reg.should_receive(:pointer).and_return ptr
part = flexmock('part')
package = flexmock('package', :create_part => part)
seq = flexmock('sequence',
:patinfo= => 'patinfo',
:odba_isolated_store => 'odba_isolated_store',
:create_package => package,
:packages => [package],
)
seq.should_receive(:patinfo)
seq.should_receive(:pointer).and_return ptr
reg.should_receive(:each_sequence).and_return do |block| block.call seq end
reg.should_receive(:sequences).and_return({'01' => seq})
reg.should_receive(:sequence).and_return(seq)
reg.should_receive(:packages).and_return([])
@app.should_receive(:registration).with('32917').and_return reg
fi = flexmock 'fachinfo'
fi.should_receive(:pointer).and_return Persistence::Pointer.new([:fachinfo,1])
pi = flexmock 'patinfo'
pi.should_receive(:pointer).and_return Persistence::Pointer.new([:patinfo,1])
flags = {:de => :up_to_date, :fr => :up_to_date}
# only german fachinfo is present
@parser.should_receive(:parse_fachinfo_html).once
@parser.should_receive(:parse_patinfo_html).never
opts = {:iksnrs => [], :xml_file => File.join(@@datadir, 'AipsDownload.xml')}
@plugin = TextInfoPlugin.new(@app, opts)
agent = @plugin.init_agent
base = File.expand_path(File.join(__FILE__, '../../../test/data/html/swissmedic/'))
mappings = { "http://www.swissmedicinfo.ch/Accept.aspx\?ReturnUrl=\%2f" => File.join(base, 'accept.html'),
"http://www.swissmedicinfo.ch/?Lang=DE" => File.join(base, 'lang.html'),
"http://www.swissmedicinfo.ch/?Lang=FR" => File.join(base, 'lang.html'),
}
@plugin.parser = @parser
def @plugin.download_swissmedicinfo_xml
@dest = File.join(@@vardir, 'xml', 'AipsDownload_latest.xml')
FileUtils.makedirs(File.dirname(@dest))
FileUtils.cp(File.join(@@datadir, 'AipsDownload_xeljanz.xml'), @dest)
File.join(@dest, 'AipsDownload_xeljanz.xml')
end
def @plugin.textinfo_swissmedicinfo_index
index = {:new=>{:de=> {:fi=>[["Zyloric®", "Jan 2014"],],
:pi=>[["Zyloric®", "Jan 2014"], ],},
:fr=>{:fi=>[["Zyloric®", "janv. 2014"],],
:pi=>[["Zyloric®", "janv. 2014"],],
},
},
:change=>{:de=> {:fi=>[["Zyloric®", "Jan 2014"],],
:pi=>[["Zyloric®", "Jan 2014"], ],},
:fr=>{:fi=>[["Zyloric®", "janv. 2014"],],
:pi=>[["Zyloric®", "janv. 2014"],],
},
},
}
index
end
@app.should_receive(:sorted_fachinfos).and_return([])
@plugin.extract_matched_content("Zyloric®", 'fi', 'de')
assert(@plugin.import_swissmedicinfo(), 'must be able to run import_swissmedicinfo')
end

def test_import_passion
name = 'Capsules PASSIFLORE "Künzle"'
stripped = name # With this line we get the error
Expand Down

0 comments on commit 213c793

Please sign in to comment.