oddb2xml 1.8.1 → 1.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.travis.yml +1 -1
- data/Gemfile.lock +7 -7
- data/README.md +14 -2
- data/Rakefile +10 -1
- data/bin/oddb2xml +2 -2
- data/lib/oddb2xml/builder.rb +36 -26
- data/lib/oddb2xml/cli.rb +19 -4
- data/lib/oddb2xml/compressor.rb +7 -7
- data/lib/oddb2xml/downloader.rb +77 -58
- data/lib/oddb2xml/extractor.rb +31 -21
- data/lib/oddb2xml/util.rb +18 -13
- data/lib/oddb2xml/version.rb +1 -1
- data/oddb2xml.gemspec +8 -5
- data/spec/builder_spec.rb +68 -31
- data/spec/cli_spec.rb +43 -69
- data/spec/compressor_spec.rb +36 -13
- data/spec/data/compressor/oddb2xml_files_bm_update.txt +4 -0
- data/spec/data/compressor/oddb2xml_files_lppv.txt +4 -0
- data/spec/data/compressor/oddb2xml_files_nonpharma.xls +0 -0
- data/spec/data/{oddb_article.xml → compressor/oddb_article.xml} +0 -0
- data/spec/data/{oddb_fi.xml → compressor/oddb_fi.xml} +0 -0
- data/spec/data/{oddb_fi_product.xml → compressor/oddb_fi_product.xml} +0 -0
- data/spec/data/{oddb_limitation.xml → compressor/oddb_limitation.xml} +0 -0
- data/spec/data/{oddb_product.xml → compressor/oddb_product.xml} +0 -0
- data/spec/data/{oddb_substance.xml → compressor/oddb_substance.xml} +0 -0
- data/spec/data/epha_interactions.csv +4 -1
- data/spec/data/swissindex_nonpharma.xml +13 -1
- data/spec/data/swissindex_pharma.xml +12 -0
- data/spec/data/{swissmedic_fridges.xlsx → swissmedic_fridge.xlsx} +0 -0
- data/spec/data/swissmedic_orphan.xlsx +0 -0
- data/spec/data/{swissmedic_packages.xlsx → swissmedic_package.xlsx} +0 -0
- data/spec/data/zurrose_transfer.dat +12 -11
- data/spec/downloader_spec.rb +48 -13
- data/spec/extractor_spec.rb +10 -11
- data/spec/spec_helper.rb +44 -15
- data/test_options.rb +24 -8
- metadata +71 -45
- checksums.yaml +0 -15
- data/spec/data/Gestrichene_Packungen_Emballages_radies.xls +0 -1
- data/spec/data/Publications.xls +0 -1
- data/spec/data/swissmedic_fridges.xls +0 -0
- data/spec/data/swissmedic_packages.xls +0 -0
data/lib/oddb2xml/extractor.rb
CHANGED
@@ -186,7 +186,6 @@ module Oddb2xml
|
|
186
186
|
data = {}
|
187
187
|
result = PharmaEntry.parse(@xml.sub(Strip_For_Sax_Machine, ''), :lazy => true)
|
188
188
|
items = result.PHARMA.ITEM
|
189
|
-
$stderr.puts "SwissIndexExtractor #{__LINE__}: #{@type} with #{items.size} items"; $stderr.flush
|
190
189
|
items.each do |pac|
|
191
190
|
item = {}
|
192
191
|
item[:_type] = @type.downcase.intern
|
@@ -216,10 +215,11 @@ module Oddb2xml
|
|
216
215
|
end
|
217
216
|
class SwissmedicExtractor < Extractor
|
218
217
|
def initialize(filename, type)
|
219
|
-
@filename = filename
|
218
|
+
@filename = File.join(Downloads, File.basename(filename))
|
219
|
+
@filename = File.join(SpecData, File.basename(filename)) if defined?(RSpec) and not File.exists?(@filename)
|
220
220
|
@type = type
|
221
|
-
return unless File.exists?(filename)
|
222
|
-
@sheet = RubyXL::Parser.parse(File.expand_path(filename)).worksheets[0]
|
221
|
+
return unless File.exists?(@filename)
|
222
|
+
@sheet = RubyXL::Parser.parse(File.expand_path(@filename)).worksheets[0]
|
223
223
|
end
|
224
224
|
def to_arry
|
225
225
|
data = []
|
@@ -366,20 +366,25 @@ module Oddb2xml
|
|
366
366
|
ixno = 0
|
367
367
|
inhalt = @io.read
|
368
368
|
inhalt.split("\n").each do |line|
|
369
|
-
next if line =~ /ATC1.*Name1.*ATC2.*Name2/
|
370
|
-
line = '"'+line unless /^"/.match(line)
|
371
|
-
row = CSV.parse_line(line)
|
372
369
|
ixno += 1
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
370
|
+
next if /ATC1.*Name1.*ATC2.*Name2/.match(line)
|
371
|
+
#line = '"'+line unless /^"/.match(line)
|
372
|
+
begin
|
373
|
+
row = CSV.parse_line(line.gsub('""','"'))
|
374
|
+
action = {}
|
375
|
+
next unless row.size > 8
|
376
|
+
action[:ixno] = ixno
|
377
|
+
action[:title] = row[4]
|
378
|
+
action[:atc1] = row[0]
|
379
|
+
action[:atc2] = row[2]
|
380
|
+
action[:mechanism] = row[5]
|
381
|
+
action[:effect] = row[6]
|
382
|
+
action[:measures] = row[7]
|
383
|
+
action[:grad] = row[8]
|
384
|
+
data << action
|
385
|
+
rescue CSV::MalformedCSVError
|
386
|
+
puts "CSV::MalformedCSVError in line #{ixno}: #{line}"
|
387
|
+
end
|
383
388
|
end
|
384
389
|
data
|
385
390
|
end
|
@@ -435,7 +440,7 @@ module Oddb2xml
|
|
435
440
|
# see http://dev.ywesee.com/Bbmb/TransferDat
|
436
441
|
def initialize(dat, extended = false)
|
437
442
|
@@extended = extended
|
438
|
-
@@error_file ||= File.open("duplicate_ean13_from_zur_rose.txt", 'w+')
|
443
|
+
@@error_file ||= File.open(File.join(WorkDir, "duplicate_ean13_from_zur_rose.txt"), 'w+')
|
439
444
|
@@items_without_ean13s ||= 0
|
440
445
|
@@duplicated_ean13s ||= 0
|
441
446
|
@@zur_rose_items ||= 0
|
@@ -444,10 +449,11 @@ module Oddb2xml
|
|
444
449
|
def to_hash
|
445
450
|
data = {}
|
446
451
|
while line = @io.gets
|
452
|
+
line = line.chomp
|
447
453
|
if @@extended
|
448
|
-
next unless line =~ /(\d{13})(\d{1})
|
454
|
+
next unless line =~ /(\d{13})(\d{1})$/
|
449
455
|
else
|
450
|
-
next unless line =~ /(7680\d{9})(\d{1})
|
456
|
+
next unless line =~ /(7680\d{9})(\d{1})$/
|
451
457
|
end
|
452
458
|
pharma_code = line[3..9]
|
453
459
|
if $1.to_s == '0000000000000'
|
@@ -462,10 +468,11 @@ module Oddb2xml
|
|
462
468
|
@@duplicated_ean13s += 1
|
463
469
|
next
|
464
470
|
end
|
471
|
+
|
465
472
|
data[ean13] = {
|
466
473
|
:line => line.chomp,
|
467
474
|
:ean => ean13,
|
468
|
-
:vat =>
|
475
|
+
:vat => line[96],
|
469
476
|
:description => line[10..59], # .sub(/\s+$/, ''),
|
470
477
|
:additional_desc => '',
|
471
478
|
:pharmacode => pharma_code,
|
@@ -473,6 +480,9 @@ module Oddb2xml
|
|
473
480
|
:pub_price => sprintf("%.2f", line[66,6].gsub(/(\d{2})$/, '.\1').to_f),
|
474
481
|
:type => :nonpharma,
|
475
482
|
}
|
483
|
+
if /5366964/.match(ean13) then
|
484
|
+
Oddb2xml.log "found 5366964 data is now #{data[ean13].inspect}"
|
485
|
+
end
|
476
486
|
@@zur_rose_items += 1
|
477
487
|
end if @io
|
478
488
|
data
|
data/lib/oddb2xml/util.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
module Oddb2xml
|
2
|
-
|
2
|
+
unless defined?(RSpec)
|
3
|
+
WorkDir = Dir.pwd
|
4
|
+
Downloads = "#{Dir.pwd}/downloads"
|
5
|
+
end
|
3
6
|
@options = {}
|
4
7
|
|
5
8
|
def Oddb2xml.log(msg)
|
@@ -11,26 +14,28 @@ module Oddb2xml
|
|
11
14
|
def Oddb2xml.save_options(options)
|
12
15
|
@options = options
|
13
16
|
end
|
17
|
+
|
18
|
+
def Oddb2xml.skip_download?
|
19
|
+
@options[:skip_download]
|
20
|
+
end
|
14
21
|
|
15
22
|
def Oddb2xml.skip_download(file)
|
16
|
-
dest = "#{
|
17
|
-
return false unless @options[:skip_download]
|
23
|
+
dest = "#{Downloads}/#{File.basename(file)}"
|
18
24
|
if File.exists?(dest)
|
19
|
-
FileUtils.cp(dest, file, :verbose => false, :preserve => true)
|
25
|
+
FileUtils.cp(dest, file, :verbose => false, :preserve => true) unless File.expand_path(file).eql?(dest)
|
20
26
|
return true
|
21
27
|
end
|
22
28
|
false
|
23
29
|
end
|
24
30
|
|
25
31
|
def Oddb2xml.download_finished(file, remove_file = true)
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
32
|
+
src = "#{WorkDir}/#{File.basename(file)}"
|
33
|
+
dest = "#{Downloads}/#{File.basename(file)}"
|
34
|
+
FileUtils.makedirs(Downloads)
|
35
|
+
#return unless File.exists?(file)
|
36
|
+
return unless file and File.exists?(file)
|
37
|
+
return if File.expand_path(file).eql?(dest)
|
38
|
+
FileUtils.cp(src, dest, :verbose => false)
|
39
|
+
Oddb2xml.log("download_finished saved as #{dest} #{File.size(dest)} bytes.")
|
35
40
|
end
|
36
41
|
end
|
data/lib/oddb2xml/version.rb
CHANGED
data/oddb2xml.gemspec
CHANGED
@@ -17,14 +17,17 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
|
-
spec
|
21
|
-
|
20
|
+
# We fix the version of the spec to newer versions only in the third position
|
21
|
+
# hoping that these version fix only security/severe bugs
|
22
|
+
# Consulted the Gemfile.lock to get
|
23
|
+
spec.add_dependency 'rubyzip', '~> 1.1.3'
|
24
|
+
spec.add_dependency 'archive-tar-minitar', '~> 0.5.2'
|
22
25
|
spec.add_dependency 'mechanize', '~> 2.5.1'
|
23
26
|
spec.add_dependency 'nokogiri', '~> 1.5.10'
|
24
|
-
spec.add_dependency 'savon', '~> 2.0'
|
25
|
-
spec.add_dependency 'spreadsheet'
|
27
|
+
spec.add_dependency 'savon', '~> 2.4.0'
|
28
|
+
spec.add_dependency 'spreadsheet', '~> 0.9.7'
|
26
29
|
spec.add_dependency 'rubyXL', '~> 2.5'
|
27
|
-
spec.add_dependency 'sax-machine'
|
30
|
+
spec.add_dependency 'sax-machine', '~> 0.1.0'
|
28
31
|
|
29
32
|
spec.add_development_dependency "bundler"
|
30
33
|
spec.add_development_dependency "rake"
|
data/spec/builder_spec.rb
CHANGED
@@ -5,7 +5,7 @@ require "rexml/document"
|
|
5
5
|
include REXML
|
6
6
|
|
7
7
|
module Kernel
|
8
|
-
def
|
8
|
+
def buildr_capture(stream)
|
9
9
|
begin
|
10
10
|
stream = stream.to_s
|
11
11
|
eval "$#{stream} = StringIO.new"
|
@@ -19,38 +19,44 @@ module Kernel
|
|
19
19
|
end
|
20
20
|
|
21
21
|
describe Oddb2xml::Builder do
|
22
|
+
NrExtendedArticles = 71
|
23
|
+
NrPharmaAndNonPharmaArticles = 61
|
24
|
+
NrPharmaArticles = 4
|
22
25
|
include ServerMockHelper
|
23
|
-
before(:all) do
|
24
|
-
files = (Dir.glob('oddb_*.tar.gz')+ Dir.glob('oddb_*.zip')+ Dir.glob('oddb_*.xml'))# +Dir.glob('data/download/*'))
|
25
|
-
files.each{ |file| FileUtils.rm(file) }
|
26
|
-
end
|
27
|
-
|
28
26
|
before(:each) do
|
27
|
+
@savedDir = Dir.pwd
|
28
|
+
cleanup_directories_before_run
|
29
29
|
setup_server_mocks
|
30
30
|
setup_swiss_index_server_mock(types = ['NonPharma', 'Pharma'])
|
31
|
+
Dir.chdir Oddb2xml::WorkDir
|
31
32
|
end
|
33
|
+
after(:each) do
|
34
|
+
Dir.chdir @savedDir if @savedDir and File.directory?(@savedDir)
|
35
|
+
end
|
36
|
+
|
32
37
|
context 'should handle BAG-articles with and without pharmacode' do
|
33
38
|
it {
|
34
|
-
dat = File.read(File.expand_path('../data/
|
39
|
+
dat = File.read(File.expand_path('../data/Preparations.xml', __FILE__))
|
35
40
|
@items = Oddb2xml::BagXmlExtractor.new(dat).to_hash
|
36
41
|
saved = @items.clone
|
37
42
|
expect(@items.size).to eq(5)
|
38
43
|
expect(saved).to eq(@items)
|
39
44
|
}
|
40
45
|
end
|
41
|
-
|
46
|
+
|
42
47
|
context 'when no option is given' do
|
43
48
|
let(:cli) do
|
44
49
|
opts = {}
|
45
50
|
Oddb2xml::Cli.new(opts)
|
46
51
|
end
|
52
|
+
|
47
53
|
it 'should generate a valid oddb_product.xml' do
|
48
|
-
res =
|
54
|
+
res = buildr_capture(:stdout){ cli.run }
|
49
55
|
res.should match(/products/)
|
50
|
-
article_filename = File.expand_path(File.join(
|
56
|
+
article_filename = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_article.xml'))
|
51
57
|
File.exists?(article_filename).should be_true
|
52
58
|
article_xml = IO.read(article_filename)
|
53
|
-
product_filename = File.expand_path(File.join(
|
59
|
+
product_filename = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_product.xml'))
|
54
60
|
File.exists?(product_filename).should be_true
|
55
61
|
unless /1\.8\.7/.match(RUBY_VERSION)
|
56
62
|
product_xml = IO.read(product_filename)
|
@@ -73,7 +79,7 @@ describe Oddb2xml::Builder do
|
|
73
79
|
|
74
80
|
product_xml.should match(/3TC/)
|
75
81
|
product_xml.should match(/7680620690084/) # Levetiracetam DESITIN
|
76
|
-
article_xml.scan(/<ART DT=/).size.should eq(
|
82
|
+
article_xml.scan(/<ART DT=/).size.should eq(NrPharmaArticles)
|
77
83
|
article_xml.should match(/<PHAR>5819012</)
|
78
84
|
article_xml.should match(/<DSCRD>LEVETIRACETAM DESITIN Filmtabl 250 mg/)
|
79
85
|
article_xml.should match(/<COMPNO>7601001320451</)
|
@@ -90,9 +96,9 @@ describe Oddb2xml::Builder do
|
|
90
96
|
Oddb2xml::Cli.new(opts)
|
91
97
|
end
|
92
98
|
it 'should generate a valid oddb_with_migel.dat' do
|
93
|
-
res =
|
99
|
+
res = buildr_capture(:stdout){ cli.run }
|
94
100
|
res.should match(/products/)
|
95
|
-
dat_filename = File.
|
101
|
+
dat_filename = File.join(Oddb2xml::WorkDir, 'oddb_with_migel.dat')
|
96
102
|
File.exists?(dat_filename).should be_true
|
97
103
|
oddb_dat = IO.read(dat_filename)
|
98
104
|
oddb_dat.should match(/1115819012LEVETIRACETAM DESITIN Filmtabl 250 mg 30 Stk/), "should have Desitin"
|
@@ -106,22 +112,49 @@ describe Oddb2xml::Builder do
|
|
106
112
|
:extended => :true,
|
107
113
|
:nonpharma => :true,
|
108
114
|
:price => :zurrose,
|
109
|
-
|
115
|
+
:log => true,
|
116
|
+
:skip_download => true,
|
117
|
+
}
|
110
118
|
Oddb2xml::Cli.new(opts)
|
111
119
|
end
|
112
120
|
|
121
|
+
it 'should handle not duplicate pharmacode 5366964' do
|
122
|
+
res = buildr_capture(:stdout){ cli.run }
|
123
|
+
res.should match(/NonPharma/i)
|
124
|
+
res.should match(/NonPharma products: #{NrPharmaAndNonPharmaArticles}/)
|
125
|
+
article_filename = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_article.xml'))
|
126
|
+
File.exists?(article_filename).should be_true
|
127
|
+
article_xml = IO.read(article_filename)
|
128
|
+
doc = REXML::Document.new File.new(article_filename)
|
129
|
+
dscrds = XPath.match( doc, "//ART" )
|
130
|
+
XPath.match( doc, "//PHAR" ).find_all{|x| x.text.match('5366964') }.size.should == 1
|
131
|
+
dscrds.size.should == NrExtendedArticles
|
132
|
+
XPath.match( doc, "//PRODNO" ).find_all{|x| true}.size.should == 1
|
133
|
+
XPath.match( doc, "//PRODNO" ).find_all{|x| x.text.match('620691') }.size.should == 1
|
134
|
+
end
|
135
|
+
|
113
136
|
it 'should load correct number of nonpharma' do
|
114
|
-
res =
|
137
|
+
res = buildr_capture(:stdout){ cli.run }
|
115
138
|
res.should match(/NonPharma/i)
|
116
|
-
res.should match(/NonPharma products:
|
139
|
+
res.should match(/NonPharma products: #{NrPharmaAndNonPharmaArticles}/)
|
140
|
+
article_filename = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_article.xml'))
|
141
|
+
File.exists?(article_filename).should be_true
|
142
|
+
article_xml = IO.read(article_filename)
|
143
|
+
doc = REXML::Document.new File.new(article_filename)
|
144
|
+
dscrds = XPath.match( doc, "//ART" )
|
145
|
+
dscrds.size.should == NrExtendedArticles
|
146
|
+
XPath.match( doc, "//PHAR" ).find_all{|x| x.text.match('1699947') }.size.should == 1 # swissmedic_packages Cardio-Pulmo-Rénal Sérocytol, suppositoire
|
147
|
+
XPath.match( doc, "//PHAR" ).find_all{|x| x.text.match('2465312') }.size.should == 1 # from swissindex_pharma.xml"
|
148
|
+
XPath.match( doc, "//PHAR" ).find_all{|x| x.text.match('0000000') }.size.should == 1 # from swissindex_pharma.xml
|
117
149
|
end
|
118
150
|
|
119
151
|
it 'should emit a correct oddb_limitation.xml' do
|
120
|
-
res =
|
152
|
+
res = buildr_capture(:stdout){ cli.run }
|
121
153
|
# check limitations
|
122
|
-
limitation_filename = File.expand_path(File.join(
|
154
|
+
limitation_filename = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_limitation.xml'))
|
123
155
|
File.exists?(limitation_filename).should be_true
|
124
156
|
limitation_xml = IO.read(limitation_filename)
|
157
|
+
limitation_xml.should match(/Die aufgeführten Präparat/)
|
125
158
|
doc = REXML::Document.new File.new(limitation_filename)
|
126
159
|
limitations = XPath.match( doc, "//LIM" )
|
127
160
|
limitations.size.should == 4
|
@@ -132,8 +165,8 @@ describe Oddb2xml::Builder do
|
|
132
165
|
end
|
133
166
|
|
134
167
|
it 'should emit a correct oddb_article.xml' do
|
135
|
-
res =
|
136
|
-
article_filename = File.expand_path(File.join(
|
168
|
+
res = buildr_capture(:stdout){ cli.run }
|
169
|
+
article_filename = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_article.xml'))
|
137
170
|
File.exists?(article_filename).should be_true
|
138
171
|
article_xml = IO.read(article_filename)
|
139
172
|
doc = REXML::Document.new File.new(article_filename)
|
@@ -154,7 +187,7 @@ describe Oddb2xml::Builder do
|
|
154
187
|
article_xml.should match(/7680536620137/) # Pharmacode
|
155
188
|
article_xml.should match(/<PRICE>13.49</)
|
156
189
|
article_xml.should match(/<PRICE>27.8</)
|
157
|
-
article_xml.scan(/<ART DT=/).size.should eq(
|
190
|
+
article_xml.scan(/<ART DT=/).size.should eq(NrExtendedArticles) # we should find some articles
|
158
191
|
article_xml.should match(/<PHAR>5819012</)
|
159
192
|
article_xml.should match(/<DSCRD>LEVETIRACETAM DESITIN Filmtabl 250 mg/)
|
160
193
|
article_xml.should match(/<COMPNO>7601001320451</)
|
@@ -167,30 +200,30 @@ describe Oddb2xml::Builder do
|
|
167
200
|
dscrds.find_all{|x| x.text.match('ZYVOXID Filmtabl 600 mg') }.size.should == 1
|
168
201
|
|
169
202
|
end
|
170
|
-
pending 'Checking for LIMPTS' # XPath.match( doc, "//LIMPTS" ).size.should == 1
|
203
|
+
#pending 'Checking for LIMPTS' # XPath.match( doc, "//LIMPTS" ).size.should == 1
|
171
204
|
end
|
205
|
+
|
172
206
|
it 'should emit a correct oddb_substance.xml' do
|
173
|
-
res =
|
174
|
-
doc = REXML::Document.new File.new(File.join(
|
207
|
+
res = buildr_capture(:stdout){ cli.run }
|
208
|
+
doc = REXML::Document.new File.new(File.join(Oddb2xml::WorkDir, 'oddb_substance.xml'))
|
175
209
|
names = XPath.match( doc, "//NAML" )
|
176
210
|
names.size.should == 10
|
177
211
|
names.find_all{|x| x.text.match('Lamivudinum') }.size.should == 1
|
178
212
|
end
|
179
213
|
|
180
214
|
it 'should emit a correct oddb_interaction.xml' do
|
181
|
-
res =
|
182
|
-
doc = REXML::Document.new File.new(File.join(
|
215
|
+
res = buildr_capture(:stdout){ cli.run }
|
216
|
+
doc = REXML::Document.new File.new(File.join(Oddb2xml::WorkDir, 'oddb_interaction.xml'))
|
183
217
|
titles = XPath.match( doc, "//TITD" )
|
184
218
|
titles.size.should == 2
|
185
219
|
titles.find_all{|x| x.text.match('Keine Interaktion') }.size.should == 1
|
186
|
-
titles.find_all{|x| x.text.match('Erhöhtes Risiko für Myopathie und Rhabdomyolyse') }.size.should == 1
|
220
|
+
titles.find_all{|x| x.text.match('Erhöhtes Risiko für Myopathie und Rhabdomyolyse') }.size.should == 1
|
187
221
|
end
|
188
222
|
|
189
223
|
it 'should emit a correct oddb_product.xml' do
|
190
|
-
res =
|
191
|
-
|
224
|
+
res = buildr_capture(:stdout){ cli.run }
|
192
225
|
res.should match(/products/)
|
193
|
-
product_filename = File.expand_path(File.join(
|
226
|
+
product_filename = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_product.xml'))
|
194
227
|
File.exists?(product_filename).should be_true
|
195
228
|
|
196
229
|
unless /1\.8\.7/.match(RUBY_VERSION)
|
@@ -204,6 +237,10 @@ describe Oddb2xml::Builder do
|
|
204
237
|
product_xml.should match(/7680555580054/) # ZYVOXID
|
205
238
|
product_xml.should_not match(/ZYVOXID/i)
|
206
239
|
end
|
240
|
+
doc = REXML::Document.new File.new(product_filename)
|
241
|
+
XPath.match( doc, "//PRD" ).find_all{|x| true}.size.should == 3
|
242
|
+
XPath.match( doc, "//GTIN" ).find_all{|x| true}.size.should == 3
|
243
|
+
XPath.match( doc, "//PRODNO" ).find_all{|x| true}.size.should == 1
|
207
244
|
end
|
208
245
|
end
|
209
246
|
end
|
data/spec/cli_spec.rb
CHANGED
@@ -2,10 +2,8 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
# for stdout/stderr on ruby 1.8.7
|
6
|
-
# $stdout.should_receive(:puts).with() does not work
|
7
5
|
module Kernel
|
8
|
-
def
|
6
|
+
def cli_capture(stream)
|
9
7
|
begin
|
10
8
|
stream = stream.to_s
|
11
9
|
eval "$#{stream} = StringIO.new"
|
@@ -31,27 +29,32 @@ RSpec::Matchers.define :have_option do |option|
|
|
31
29
|
end
|
32
30
|
|
33
31
|
shared_examples_for 'any interface for product' do
|
34
|
-
it {
|
32
|
+
it { cli_capture(:stdout) { cli.should respond_to(:run) } }
|
35
33
|
it 'should run successfully' do
|
36
|
-
|
34
|
+
cli_capture(:stdout){ cli.run }.should match(/products/)
|
37
35
|
end
|
38
36
|
end
|
39
37
|
|
40
38
|
shared_examples_for 'any interface for address' do
|
41
|
-
it {
|
39
|
+
it { cli_capture(:stdout) { cli.should respond_to(:run) } }
|
42
40
|
it 'should run successfully' do
|
43
|
-
|
41
|
+
cli_capture(:stdout){ cli.run }.should match(/addresses/)
|
44
42
|
end
|
45
43
|
end
|
46
44
|
|
47
45
|
describe Oddb2xml::Cli do
|
46
|
+
# Setting ShouldRun to false and changing one -> if true allows you
|
47
|
+
# to run easily the failing test
|
48
48
|
include ServerMockHelper
|
49
|
-
before(:all) do
|
50
|
-
files = (Dir.glob('oddb_*.tar.gz')+ Dir.glob('oddb_*.zip')+ Dir.glob('oddb_*.xml'))# +Dir.glob('data/download/*'))
|
51
|
-
files.each{ |file| FileUtils.rm(file) }
|
52
|
-
end
|
53
49
|
before(:each) do
|
50
|
+
@savedDir = Dir.pwd
|
51
|
+
cleanup_directories_before_run
|
54
52
|
setup_server_mocks
|
53
|
+
Dir.chdir(Oddb2xml::WorkDir)
|
54
|
+
end
|
55
|
+
after(:each) do
|
56
|
+
Dir.chdir(@savedDir) if @savedDir and File.directory?(@savedDir)
|
57
|
+
cleanup_compressor
|
55
58
|
end
|
56
59
|
context 'when -c tar.gz option is given' do
|
57
60
|
let(:cli) do
|
@@ -69,21 +72,16 @@ describe Oddb2xml::Cli do
|
|
69
72
|
cli.should have_option(:compress_ext => 'tar.gz')
|
70
73
|
end
|
71
74
|
it 'should create tar.gz file' do
|
72
|
-
|
73
|
-
file = Dir.glob('oddb_*.tar.gz').first
|
75
|
+
cli_capture(:stdout) { cli.run }.should match(/Pharma/)
|
76
|
+
file = Dir.glob(File.join(Dir.pwd, 'oddb_*.tar.gz')).first
|
74
77
|
File.exists?(file).should be_true
|
75
78
|
end
|
76
79
|
it 'should not create any xml file' do
|
77
|
-
|
78
|
-
Dir.glob('oddb_*.xml').each do |file|
|
80
|
+
cli_capture(:stdout) { cli.run }.should match(/Pharma/)
|
81
|
+
Dir.glob(File.join(Oddb2xml::WorkDir, 'oddb_*.xml')).each do |file|
|
79
82
|
File.exists?(file).should be_false
|
80
83
|
end
|
81
84
|
end
|
82
|
-
after(:each) do
|
83
|
-
Dir.glob('oddb_*.tar.gz').each do |file|
|
84
|
-
File.unlink(file) if File.exists?(file)
|
85
|
-
end
|
86
|
-
end
|
87
85
|
end
|
88
86
|
context 'when -c zip option is given' do
|
89
87
|
let(:cli) do
|
@@ -101,21 +99,17 @@ describe Oddb2xml::Cli do
|
|
101
99
|
cli.should have_option(:compress_ext => 'zip')
|
102
100
|
end
|
103
101
|
it 'should create zip file' do
|
104
|
-
|
105
|
-
file = Dir.glob('oddb_*.zip').first
|
102
|
+
cli_capture(:stdout) { cli.run }.should match(/Pharma/)
|
103
|
+
file = Dir.glob(File.join(Dir.pwd, 'oddb_*.zip')).first
|
106
104
|
File.exists?(file).should be_true
|
107
105
|
end
|
108
106
|
it 'should not create any xml file' do
|
109
|
-
|
110
|
-
|
107
|
+
Dir.glob(File.join(Oddb2xml::WorkDir, 'oddb_*.xml')).each do |file| FileUtil.rm_f(file) end
|
108
|
+
cli_capture(:stdout) { cli.run }.should match(/Pharma/)
|
109
|
+
Dir.glob(File.join(Oddb2xml::WorkDir, 'oddb_*.xml')).each do |file|
|
111
110
|
File.exists?(file).should be_false
|
112
111
|
end
|
113
112
|
end
|
114
|
-
after(:each) do
|
115
|
-
Dir.glob('oddb_*.zip').each do |file|
|
116
|
-
File.unlink(file) if File.exists?(file)
|
117
|
-
end
|
118
|
-
end
|
119
113
|
end
|
120
114
|
context 'when -a nonpharma option is given' do
|
121
115
|
let(:cli) do
|
@@ -133,12 +127,12 @@ describe Oddb2xml::Cli do
|
|
133
127
|
cli.should have_option(:nonpharma => true)
|
134
128
|
end
|
135
129
|
it 'should not create any compressed file' do
|
136
|
-
|
137
|
-
Dir.glob('oddb_*.tar.gz').first.should be_nil
|
138
|
-
Dir.glob('oddb_*.zip').first.should be_nil
|
130
|
+
cli_capture(:stdout) { cli.run }.should match(/NonPharma/)
|
131
|
+
Dir.glob(File.join(Oddb2xml::WorkDir, 'oddb_*.tar.gz')).first.should be_nil
|
132
|
+
Dir.glob(File.join(Oddb2xml::WorkDir, 'oddb_*.zip')).first.should be_nil
|
139
133
|
end
|
140
134
|
it 'should create xml files' do
|
141
|
-
|
135
|
+
cli_capture(:stdout) { cli.run }.should match(/NonPharma/)
|
142
136
|
expected = [
|
143
137
|
'oddb_product.xml',
|
144
138
|
'oddb_article.xml',
|
@@ -147,15 +141,10 @@ describe Oddb2xml::Cli do
|
|
147
141
|
'oddb_interaction.xml',
|
148
142
|
'oddb_code.xml'
|
149
143
|
].length
|
150
|
-
Dir.glob('oddb_*.xml').each do |file|
|
144
|
+
Dir.glob(File.join(Oddb2xml::WorkDir, 'oddb_*.xml')).each do |file|
|
151
145
|
File.exists?(file).should be_true
|
152
146
|
end.to_a.length.should equal expected
|
153
147
|
end
|
154
|
-
after(:each) do
|
155
|
-
Dir.glob('oddb_*.xml').each do |file|
|
156
|
-
File.unlink(file) if File.exists?(file)
|
157
|
-
end
|
158
|
-
end
|
159
148
|
end
|
160
149
|
context 'when -t _swiss option is given' do
|
161
150
|
let(:cli) do
|
@@ -173,12 +162,12 @@ describe Oddb2xml::Cli do
|
|
173
162
|
cli.should have_option(:tag_suffix=> '_SWISS')
|
174
163
|
end
|
175
164
|
it 'should not create any compressed file' do
|
176
|
-
|
177
|
-
Dir.glob('oddb_*.tar.gz').first.should be_nil
|
178
|
-
Dir.glob('oddb_*.zip').first.should be_nil
|
165
|
+
cli_capture(:stdout) { cli.run }.should match(/Pharma/)
|
166
|
+
Dir.glob(File.join(Oddb2xml::WorkDir, 'oddb_*.tar.gz')).first.should be_nil
|
167
|
+
Dir.glob(File.join(Oddb2xml::WorkDir, 'oddb_*.zip')).first.should be_nil
|
179
168
|
end
|
180
169
|
it 'should create xml files with prefix swiss_' do
|
181
|
-
|
170
|
+
cli_capture(:stdout) { cli.run }.should match(/Pharma/)
|
182
171
|
expected = [
|
183
172
|
'swiss_product.xml',
|
184
173
|
'swiss_article.xml',
|
@@ -187,15 +176,10 @@ describe Oddb2xml::Cli do
|
|
187
176
|
'swiss_interaction.xml',
|
188
177
|
'swiss_code.xml'
|
189
178
|
].length
|
190
|
-
Dir.glob('swiss_*.xml').each do |file|
|
179
|
+
Dir.glob(File.join(Oddb2xml::WorkDir, 'swiss_*.xml')).each do |file|
|
191
180
|
File.exists?(file).should be_true
|
192
181
|
end.to_a.length.should equal expected
|
193
182
|
end
|
194
|
-
after(:each) do
|
195
|
-
Dir.glob('swiss_*.xml').each do |file|
|
196
|
-
File.unlink(file) if File.exists?(file)
|
197
|
-
end
|
198
|
-
end
|
199
183
|
end
|
200
184
|
context 'when -o fi option is given' do
|
201
185
|
let(:cli) do
|
@@ -213,12 +197,12 @@ describe Oddb2xml::Cli do
|
|
213
197
|
cli.should have_option(:fi => true)
|
214
198
|
end
|
215
199
|
it 'should not create any compressed file' do
|
216
|
-
|
217
|
-
Dir.glob('oddb_*.tar.gz').first.should be_nil
|
218
|
-
Dir.glob('oddb_*.zip').first.should be_nil
|
200
|
+
cli_capture(:stdout) { cli.run }.should match(/Pharma/)
|
201
|
+
Dir.glob(File.join(Oddb2xml::WorkDir, 'oddb_*.tar.gz')).first.should be_nil
|
202
|
+
Dir.glob(File.join(Oddb2xml::WorkDir, 'oddb_*.zip')).first.should be_nil
|
219
203
|
end
|
220
204
|
it 'should create xml files' do
|
221
|
-
|
205
|
+
cli_capture(:stdout) { cli.run }.should match(/Pharma/)
|
222
206
|
expected = [
|
223
207
|
'oddb_fi.xml',
|
224
208
|
'oddb_fi_product.xml',
|
@@ -229,15 +213,10 @@ describe Oddb2xml::Cli do
|
|
229
213
|
'oddb_interaction.xml',
|
230
214
|
'oddb_code.xml'
|
231
215
|
].length
|
232
|
-
Dir.glob('oddb_*.xml').each do |file|
|
216
|
+
Dir.glob(File.join(Oddb2xml::WorkDir, 'oddb_*.xml')).each do |file|
|
233
217
|
File.exists?(file).should be_true
|
234
218
|
end.to_a.length.should equal expected
|
235
219
|
end
|
236
|
-
after(:each) do
|
237
|
-
Dir.glob('oddb_*.xml').each do |file|
|
238
|
-
File.unlink(file) if File.exists?(file)
|
239
|
-
end
|
240
|
-
end
|
241
220
|
end
|
242
221
|
context 'when -x address option is given' do
|
243
222
|
let(:cli) do
|
@@ -255,24 +234,19 @@ describe Oddb2xml::Cli do
|
|
255
234
|
cli.should have_option(:address=> true)
|
256
235
|
end
|
257
236
|
it 'should not create any compressed file' do
|
258
|
-
|
259
|
-
Dir.glob('oddb_*.tar.gz').first.should be_nil
|
260
|
-
Dir.glob('oddb_*.zip').first.should be_nil
|
237
|
+
cli_capture(:stdout) { cli.run }.should match(/addresses/)
|
238
|
+
Dir.glob(File.join(Oddb2xml::WorkDir, 'oddb_*.tar.gz')).first.should be_nil
|
239
|
+
Dir.glob(File.join(Oddb2xml::WorkDir, 'oddb_*.zip')).first.should be_nil
|
261
240
|
end
|
262
241
|
it 'should create xml files' do
|
263
|
-
|
242
|
+
cli_capture(:stdout) { cli.run }.should match(/addresses/)
|
264
243
|
expected = [
|
265
244
|
'oddb_betrieb.xml',
|
266
245
|
'oddb_medizinalperson.xml',
|
267
246
|
].length
|
268
|
-
Dir.glob('oddb_*.xml').each do |file|
|
247
|
+
Dir.glob(File.join(Oddb2xml::WorkDir, 'oddb_*.xml')).each do |file|
|
269
248
|
File.exists?(file).should be_true
|
270
249
|
end.to_a.length.should equal expected
|
271
250
|
end
|
272
|
-
after(:each) do
|
273
|
-
Dir.glob('oddb_*.xml').each do |file|
|
274
|
-
File.unlink(file) if File.exists?(file)
|
275
|
-
end
|
276
|
-
end
|
277
251
|
end
|
278
252
|
end
|