oddb2xml 2.1.7 → 2.1.8

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/spec/galenic_spec.rb CHANGED
@@ -149,9 +149,7 @@ def test_one_string(parser, string, expected)
149
149
  res1.delete(:unit) if res1
150
150
  stringified = res1 ? res1.to_s.gsub(/@\d+/, '') : nil
151
151
  if res1 == nil or ! stringified.eql? expected.to_s
152
- puts "Failed testing: #{string}"
153
- pp res1
154
- binding.pry
152
+ puts "Failed testing: #{string}"; binding.pry
155
153
  end
156
154
  expect(stringified).to eq expected.to_s if expected
157
155
  end
data/spec/options_spec.rb CHANGED
@@ -2,19 +2,6 @@
2
2
 
3
3
  require 'spec_helper'
4
4
  require "#{Dir.pwd}/lib/oddb2xml/options"
5
- module Kernel
6
- def cli_capture(stream)
7
- begin
8
- stream = stream.to_s
9
- eval "$#{stream} = StringIO.new"
10
- yield
11
- result = eval("$#{stream}").string
12
- ensure
13
- eval "$#{stream} = #{stream.upcase}"
14
- end
15
- result
16
- end
17
- end
18
5
 
19
6
  describe Oddb2xml::Options do
20
7
  include ServerMockHelper
data/spec/parslet_spec.rb CHANGED
@@ -1,9 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
- begin
4
- require 'pry'
5
- rescue LoadError
6
- end
7
3
  require 'pp'
8
4
  VERBOSE_MESSAGES = false
9
5
  require 'spec_helper'
@@ -1375,8 +1371,6 @@ describe ParseComposition do
1375
1371
  rescue Parslet::ParseFailed
1376
1372
  @nrErrors += 1
1377
1373
  puts "#{File.basename(AllCompositionLines)}:#{nr} parse_error #{@nrErrors} in: #{line}"
1378
- # binding.pry
1379
- # binding.pry if nr > 300
1380
1374
  end
1381
1375
  }
1382
1376
  at_exit { puts "Testing whether #{nr} composition lines can be parsed. Found #{@nrErrors} errors in #{(Time.now - start_time).to_i} seconds" }
data/spec/spec_helper.rb CHANGED
@@ -20,6 +20,9 @@ require 'pry'
20
20
  rescue LoadError
21
21
  end
22
22
 
23
+ require 'vcr'
24
+ require 'timecop'
25
+
23
26
  module Oddb2xml
24
27
  # we override here a few directories to make input/output when running specs to
25
28
  # be in different places compared when running
@@ -27,6 +30,93 @@ module Oddb2xml
27
30
  WorkDir = File.join(File.dirname(__FILE__), 'run')
28
31
  Downloads = File.join(WorkDir, 'downloads')
29
32
  SpecCompressor = File.join(Oddb2xml::SpecData, 'compressor')
33
+
34
+ GTINS_CALC = [
35
+ '7680458820202', # for calc_spec.rb
36
+ '7680555940018', # for calc_spec.rb
37
+ '7680434541015', # for calc_spec.rb
38
+ '7680300150105', # for calc_spec.rb
39
+ '7680446250592', # for calc_spec.rb
40
+ '7680611860045', # for calc_spec.rb
41
+ '7680165980114', # for calc_spec.rb
42
+ '7680589430011', # for calc_spec.rb
43
+ '7680556740075', # for calc_spec.rb
44
+ '7680540151009', # for calc_spec.rb
45
+ '7680560890018', # for calc_spec.rb
46
+ ]
47
+ GTINS_DRUGS = [ '733905577161', # 1-DAY ACUVUE Moist Tag -2.00dpt BC 8.5
48
+ '4042809018288',
49
+ '4042809018400',
50
+ '4042809018493',
51
+ '5000223074777',
52
+ '5000223439507',
53
+ '7611600441013',
54
+ '7611600441020',
55
+ '7611600441037',
56
+ '7680161050583', # Hirudoid Creme 3 mg/g
57
+ '7680172330414', # SELSUN
58
+ '7680284860144',
59
+ '7680316440115', # FERRO-GRADUMET Depottabl 30 Stk
60
+ '7680316950157', # SOFRADEX Gtt Auric 8 ml
61
+ '7680324750190', # LANSOYL Gel
62
+ '7680353660163',
63
+ '7680403330459',
64
+ '7680536620137', # 3TC Filmtabl 150 mg
65
+ '7680555580054', # ZYVOXID
66
+ '7680620690084', # LEVETIRACETAM DESITIN Mini Filmtab 250 mg needed for extractor_spec.rb
67
+ ] + GTINS_CALC
68
+ FERRO_GRADUMET_GTIN = '7680316440115'
69
+ FIRST_DAY_ACUVUE_GTIN = '733905577161'
70
+ HIRUDOID_GTIN = '7680161050583'
71
+ LANSOYL_GTIN = '7680324750190'
72
+ LANSOYL_PRICE_RESELLER_PUB = 18.95
73
+ LANSOYL_PRICE_ZURROSE = 10.54
74
+ LANSOYL_PRICE_ZURROSEPUB = 16.25
75
+ LEVETIRACETAM_GTIN = '7680620690084'
76
+ LEVETIRACETAM_PRICE_PPUB = 27.8
77
+ LEVETIRACETAM_PRICE_ZURROSE = 13.49
78
+ LEVETIRACETAM_PRICE_RESELLER_PUB = 24.3
79
+ SOFRADEX_GTIN = '7680316950157'
80
+ SOFRADEX_PRICE_RESELLER_PUB = 12.9
81
+ SOFRADEX_PRICE_ZURROSE = 7.18
82
+ SOFRADEX_PRICE_ZURROSEPUB = 15.45
83
+ THREE_TC_GTIN = '7680536620137'
84
+ ZYVOXID_GTIN = '7680555580054'
85
+
86
+ GTINS_MEDREG = [
87
+ 7601001380028, # Glarus
88
+ 7601002017145, # Kantonsspital Glarus AG
89
+ 7601001395145, # Kantonstierärztlicher Dienst
90
+ 7601001396043, # St. Fridolin Pharma AG
91
+ 7601000159199, # Davatz Ursula
92
+ 7601000159199, # Davatz Ursula
93
+ 7601000254344, # Pfister Daniel 8753 Mollis
94
+ 7601000254207, # Züst Peter 8753 Mollis
95
+ 7601000752314, # Züst Yvonne 8753 Mollis
96
+ ]
97
+
98
+ end
99
+
100
+ VCR.configure do |config|
101
+ config.cassette_library_dir = "spec/fixtures/vcr_cassettes"
102
+ config.hook_into :webmock # or :fakeweb
103
+ config.debug_logger = File.open(File.join(File.dirname(File.dirname(__FILE__)), 'vcr.log'), 'w+')
104
+ config.debug_logger.sync = true
105
+ config.default_cassette_options = { :record => ARGV.join(' ').index('downloader_spec') ? :new_episodes : :once ,
106
+ :preserve_exact_body_bytes => true,
107
+ :allow_playback_repeats => true,
108
+ :serialize_with => :json,
109
+ :decode_compressed_response => true,
110
+ :match_requests_on => [:method, :uri, :body],
111
+ }
112
+ # :match_requests_on (Array<Symbol, #call>) —
113
+ #
114
+ # List of request matchers to use to determine what recorded HTTP interaction to replay. Defaults to [:method, :uri]. The built-in matchers are :method, :uri, :host, :path, :headers and :body. You can also pass the name of a registered custom request matcher or any object that responds to #call.
115
+
116
+ config.before_http_request(:real?) do |request|
117
+ $stderr.puts("before real request: #{request.method} #{request.uri}")
118
+ $stderr.flush
119
+ end
30
120
  end
31
121
 
32
122
  AllCompositionLines = File.expand_path("#{__FILE__}/../data/compositions.txt")
@@ -34,6 +124,20 @@ AllColumn_C_Lines = File.expand_path("#{__FILE__}/../data/column_c.txt")
34
124
 
35
125
  require 'oddb2xml'
36
126
 
127
+ module Kernel
128
+ def buildr_capture(stream)
129
+ begin
130
+ stream = stream.to_s
131
+ eval "$#{stream} = StringIO.new"
132
+ yield
133
+ result = eval("$#{stream}").string
134
+ ensure
135
+ eval "$#{stream} = #{stream.upcase}"
136
+ end
137
+ result
138
+ end
139
+ end
140
+
37
141
  module ServerMockHelper
38
142
  def cleanup_compressor
39
143
  [ File.join(Oddb2xml::SpecCompressor, '*.zip'),
@@ -53,246 +157,7 @@ module ServerMockHelper
53
157
  end
54
158
 
55
159
  def setup_server_mocks
56
- setup_bag_xml_server_mock
57
- setup_swiss_index_server_mock
58
- setup_swissmedic_server_mock
59
- setup_swissmedic_info_server_mock
60
- setup_epha_server_mock
61
- setup_bm_update_server_mock
62
- setup_lppv_server_mock
63
- setup_migel_server_mock
64
- setup_medregbm_server_mock
65
- setup_zurrose_server_mock
66
- setup_epha_atc_csv_mock
67
- end
68
-
69
- def setup_epha_atc_csv_mock
70
- body = File.read(File.join(Oddb2xml::SpecData, 'atc.csv'))
71
- stub_request(:get, "https://raw.githubusercontent.com/epha/robot/master/data/manual/swissmedic/atc.csv").
72
- with(:headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
73
- to_return(:status => 200, :body => body, :headers => {})
74
- end
75
- def setup_bag_xml_server_mock
76
- # zip
77
- stub_zip_url = 'http://bag.e-mediat.net/SL2007.Web.External/File.axd?file=XMLPublications.zip'
78
- stub_response = File.read(File.join(Oddb2xml::SpecData, 'XMLPublications.zip'))
79
- stub_request(:get, stub_zip_url).
80
- with(:headers => {
81
- 'Accept' => '*/*',
82
- 'Accept-Encoding' => 'gzip,deflate,identity',
83
- 'Host' => 'bag.e-mediat.net',
84
- }).
85
- to_return(
86
- :status => 200,
87
- :headers => {'Content-Type' => 'application/zip; charset=utf-8'},
88
- :body => stub_response)
89
- end
90
- def setup_swiss_index_server_mock(types =['NonPharma', 'Pharma'], languages=['DE', 'FR'])
91
- types.each do |type|
92
- languages.each do |language|
93
- # wsdl
94
- stub_wsdl_url = "https://index.ws.e-mediat.net/Swissindex/#{type}/ws_#{type}_V101.asmx?WSDL"
95
- first_file = File.join(Oddb2xml::SpecData, "wsdl_#{type.downcase}.xml")
96
- stub_response_wsdl = File.read(File.join(Oddb2xml::SpecData, "wsdl_#{type.downcase}.xml"))
97
- stub_request(:get, stub_wsdl_url).
98
- with(:headers => {
99
- 'Accept' => '*/*',
100
- }).
101
- to_return(
102
- :status => 200,
103
- :headers => {'Content-Type' => 'text/xml; charset=utf-8'},
104
- :body => stub_response_wsdl)
105
- # soap (dummy)
106
- stub_soap_url = 'https://example.com/test'
107
- stub_file = File.join(Oddb2xml::SpecData, "swissindex_#{type}_#{language}.xml")
108
- stub_response = File.read(stub_file)
109
- stub_request(:post, "https://example.com/test").
110
- with(:body => "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n<soap:Body>\n <lang xmlns=\"http://swissindex.e-mediat.net/Swissindex#{type}_out_V101\">#{language}</lang>\n</soap:Body>\n</soap:Envelope>\n",
111
- :headers => {'Accept'=>'*/*', 'Content-Type'=>'text/xml;charset=UTF-8', 'Soapaction'=>'"http://example.com/DownloadAll"', 'User-Agent'=>'Ruby'}).
112
- to_return(:status => 200, :body => stub_response, :headers => {})
113
- end
114
- end
115
- end
116
-
117
- def setup_swissmedic_server_mock
118
- host = 'www.swissmedic.ch'
119
- {
120
- :orphans => {:html => '/arzneimittel/00156/00221/00222/00223/00224/00227/00228/index.html?lang=de', :xls => '/download'},
121
- :fridges => {:html => '/arzneimittel/00156/00221/00222/00235/index.html?lang=de', :xls => '/download'},
122
- :packages => {:html => '/arzneimittel/00156/00221/00222/00230/index.html?lang=de', :xls => '/download'},
123
- }.each_pair do |type, urls|
124
- # html (dummy)
125
- stub_html_url = "https://#{host}" + urls[:html]
126
- filename = File.join(Oddb2xml::SpecData, "swissmedic_#{type.to_s}.html")
127
-
128
- stub_response = File.read(filename)
129
- stub_request(:get, stub_html_url).
130
- with(:headers => {
131
- 'Accept' => '*/*',
132
- 'Accept-Encoding'=>'gzip,deflate,identity',
133
- 'Host' => host,
134
- }).
135
- to_return(
136
- :status => 200,
137
- :headers => {'Content-Type' => 'text/html; charset=utf-8'},
138
- :body => stub_response)
139
- # xls
140
- if type == :orphans
141
- stub_xls_url = "https://#{host}" + urls[:xls] + "/swissmedic_orphan.xlsx"
142
- stub_response = File.read(File.join(Oddb2xml::SpecData, "swissmedic_orphan.xlsx"))
143
- else
144
- stub_xls_url = "https://#{host}" + urls[:xls] + "/swissmedic_#{type.to_s}.xlsx"
145
- stub_response = 'no_such_file'
146
- end
147
- stub_request(:get, stub_xls_url).
148
- with(:headers => {
149
- 'Accept' => '*/*',
150
- 'Accept-Encoding' => 'gzip,deflate,identity',
151
- 'Host' => host,
152
- }).
153
- to_return(
154
- :status => 200,
155
- :headers => {'Content-Type' => 'application/octet-stream; charset=utf-8'},
156
- :body => stub_response)
157
- end
158
- end
159
- def setup_swissmedic_info_server_mock
160
- # html (dummy)
161
- stub_html_url = "http://download.swissmedicinfo.ch/Accept.aspx?ReturnUrl=%2f"
162
- stub_response = File.read(File.join(Oddb2xml::SpecData, "swissmedic_info.html"))
163
- stub_request(:get, stub_html_url).
164
- with(
165
- :headers => {
166
- 'Accept' => '*/*',
167
- 'Host' => 'download.swissmedicinfo.ch',
168
- }).
169
- to_return(
170
- :status => 200,
171
- :headers => {'Content-Type' => 'text/html; charset=utf-8'},
172
- :body => stub_response)
173
- # html (dummy 2)
174
- stub_html_url = 'http://download.swissmedicinfo.ch/Accept.aspx?ctl00$MainContent$btnOK=1'
175
- stub_response = File.read(File.join(Oddb2xml::SpecData, "swissmedic_info_2.html"))
176
- stub_request(:get, stub_html_url).
177
- with(
178
- :headers => {
179
- 'Accept' => '*/*',
180
- 'Host' => 'download.swissmedicinfo.ch',
181
- }).
182
- to_return(
183
- :status => 200,
184
- :headers => {'Content-Type' => 'text/html; charset=utf-8'},
185
- :body => stub_response)
186
- # zip
187
- stub_zip_url = 'http://download.swissmedicinfo.ch/Accept.aspx?ctl00$MainContent$BtnYes=1'
188
- stub_response = File.read(File.join(Oddb2xml::SpecData, 'swissmedic_info.zip'))
189
- stub_request(:get, stub_zip_url).
190
- with(
191
- :headers => {
192
- 'Accept' => '*/*',
193
- 'Accept-Encoding' => 'gzip,deflate,identity',
194
- 'Host' => 'download.swissmedicinfo.ch',
195
- }).
196
- to_return(
197
- :status => 200,
198
- :headers => {'Content-Type' => 'application/zip; charset=utf-8'},
199
- :body => stub_response)
200
- end
201
- def setup_epha_server_mock
202
- # csv
203
- stub_csv_url = 'https://download.epha.ch/cleaned/matrix.csv'
204
- stub_response = File.read(File.join(Oddb2xml::SpecData, 'epha_interactions.csv'))
205
- stub_request(:get, stub_csv_url).
206
- with(:headers => {
207
- 'Accept' => '*/*',
208
- 'Host' => 'download.epha.ch',
209
- }).
210
- to_return(
211
- :status => 200,
212
- :headers => {'Content-Type' => 'text/csv; charset=utf-8'},
213
- :body => stub_response)
214
- end
215
- def setup_bm_update_server_mock
216
- # txt
217
- stub_txt_url = 'https://raw.github.com/zdavatz/oddb2xml_files/master/BM_Update.txt'
218
- stub_response = File.read(File.join(Oddb2xml::SpecData, 'oddb2xml_files_bm_update.txt'))
219
- stub_request(:get, stub_txt_url).
220
- with(:headers => {
221
- 'Accept' => '*/*',
222
- 'Host' => 'raw.github.com',
223
- }).
224
- to_return(
225
- :status => 200,
226
- :headers => {'Content-Type' => 'text/plain; charset=utf-8'},
227
- :body => stub_response)
228
- end
229
- def setup_lppv_server_mock
230
- # txt
231
- stub_txt_url = 'https://raw.github.com/zdavatz/oddb2xml_files/master/LPPV.txt'
232
- stub_response = File.read(File.join(Oddb2xml::SpecData, 'oddb2xml_files_lppv.txt'))
233
- stub_request(:get, stub_txt_url).
234
- with(:headers => {
235
- 'Accept' => '*/*',
236
- 'Host' => 'raw.github.com',
237
- }).
238
- to_return(
239
- :status => 200,
240
- :headers => {'Content-Type' => 'text/plain; charset=utf-8'},
241
- :body => stub_response)
242
- end
243
- def setup_migel_server_mock
244
- # xls
245
- stub_xls_url = 'https://github.com/zdavatz/oddb2xml_files/raw/master/NON-Pharma.xls'
246
- stub_response = File.read(File.join(Oddb2xml::SpecData, 'oddb2xml_files_nonpharma.xls'))
247
- stub_request(:get, stub_xls_url).
248
- with(:headers => {
249
- 'Accept' => '*/*',
250
- 'Host' => 'github.com',
251
- }).
252
- to_return(
253
- :status => 200,
254
- :headers => {'Content-Type' => 'application/octet-stream; charset=utf-8'},
255
- :body => stub_response)
256
- end
257
- def setup_medregbm_server_mock
258
- # txt betrieb
259
- stub_txt_url = 'https://www.medregbm.admin.ch/Publikation/CreateExcelListBetriebs'
260
- stub_response = File.read(File.join(Oddb2xml::SpecData, 'medregbm_betrieb.txt'))
261
- stub_request(:get, stub_txt_url).
262
- with(:headers => {
263
- 'Accept' => '*/*',
264
- 'Host' => 'www.medregbm.admin.ch',
265
- }).
266
- to_return(
267
- :status => 200,
268
- :headers => {'Content-Type' => 'text/plain; charset=utf-8'},
269
- :body => stub_response)
270
- stub_txt_url = 'https://www.medregbm.admin.ch/Publikation/CreateExcelListMedizinalPersons'
271
- # txt person
272
- stub_response = File.read(File.join(Oddb2xml::SpecData, 'medregbm_person.txt'))
273
- stub_request(:get, stub_txt_url).
274
- with(:headers => {
275
- 'Accept' => '*/*',
276
- 'Host' => 'www.medregbm.admin.ch',
277
- }).
278
- to_return(
279
- :status => 200,
280
- :headers => {'Content-Type' => 'text/plain; charset=utf-8'},
281
- :body => stub_response)
282
- end
283
- def setup_zurrose_server_mock
284
- # dat
285
- stub_dat_url = 'http://zurrose.com/fileadmin/main/lib/download.php?file=/fileadmin/user_upload/downloads/ProduktUpdate/IGM11_mit_MwSt/Vollstamm/transfer.dat'
286
- stub_response = File.read(File.join(Oddb2xml::SpecData, 'zurrose_transfer.dat'))
287
- stub_request(:get, stub_dat_url).
288
- with(:headers => {
289
- 'Accept' => '*/*',
290
- 'Host' => 'zurrose.com',
291
- }).
292
- to_return(
293
- :status => 200,
294
- :headers => {'Content-Type' => 'text/plain; charset=utf-8'},
295
- :body => stub_response)
160
+ puts "Skip setup_server_mocks as we want to use vcr"
296
161
  end
297
162
  end
298
163
 
data/test_options.rb CHANGED
@@ -11,6 +11,8 @@ require 'socket'
11
11
 
12
12
  def test_one_call(cmd)
13
13
  dest = File.join(Ausgabe, cmd.gsub(/[ -]/, '_'))
14
+ all_downloads = File.join(dest, 'downloads')
15
+ FileUtils.makedirs(all_downloads) unless File.exists?(all_downloads)
14
16
  cmd.sub!('oddb2xml', 'oddb2xml --skip-download --log')
15
17
  files = (Dir.glob('%.xls*') + Dir.glob('*.dat*') + Dir.glob('*.xml'))
16
18
  FileUtils.rm(files, :verbose => true)
@@ -28,12 +30,15 @@ def test_one_call(cmd)
28
30
  FileUtils.cp(Dir.glob('*.dat'), dest, :preserve => true, :verbose => true) if Dir.glob('*.dat').size > 0
29
31
  FileUtils.cp(Dir.glob('*.xml'), dest, :preserve => true, :verbose => true) if Dir.glob('*.xml').size > 0
30
32
  FileUtils.cp(Dir.glob('*.gz'), dest, :preserve => true, :verbose => true) if Dir.glob('*.gz').size > 0
33
+ downloaded_files = Dir.glob("#{dest}/*/downloads/*")
34
+ FileUtils.mv(downloaded_files, all_downloads, :verbose => true) if downloaded_files.size > 0
35
+ FileUtils.rm(Dir.glob("#{dest}/*#{Time.now.year}*.xml"), :verbose => true)
31
36
  end
32
37
 
33
38
  def prepare_for_gem_test
34
39
  [ "rake clean gem install" , # build and install our gem first
35
40
  # "gem uninstall --all --ignore-dependencies --executables",
36
- "gem install pkg/*.gem"
41
+ "gem install --no-ri --no-rdoc pkg/*.gem"
37
42
  ].each {
38
43
  |cmd|
39
44
  puts "Running #{cmd}"
@@ -48,13 +53,13 @@ prepare_for_gem_test
48
53
  # we will skip some long running tests as travis jobs must finish in less than 50 minutes
49
54
  # unfortunately it returns a very common name
50
55
  unless 'localhost.localdomain'.eql?(Socket.gethostbyname(Socket.gethostname).first)
51
- test_one_call('oddb2xml --calc')
52
56
  test_one_call('oddb2xml -e')
53
57
  test_one_call('oddb2xml -e -I80')
54
58
  test_one_call('oddb2xml -f dat --append -I 80')
55
59
  test_one_call('oddb2xml -f dat --append')
56
60
  test_one_call('oddb2xml --append')
57
61
  end
62
+ test_one_call('oddb2xml --calc')
58
63
  test_one_call('oddb2xml -t md -c tar.gz')
59
64
  test_one_call('oddb2xml -o')
60
65
  test_one_call('oddb2xml -f xml')