oddb2xml 1.0.5 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest.txt CHANGED
@@ -1,6 +1,8 @@
1
1
  .gitignore
2
+ .rspec
2
3
  Gemfile
3
4
  History.txt
5
+ LICENSE
4
6
  Manifest.txt
5
7
  README.md
6
8
  Rakefile
@@ -13,3 +15,14 @@ lib/oddb2xml/downloader.rb
13
15
  lib/oddb2xml/extractor.rb
14
16
  lib/oddb2xml/version.rb
15
17
  oddb2xml.gemspec
18
+ spec/builder_spec.rb
19
+ spec/cli_spec.rb
20
+ spec/compressor_spec.rb
21
+ spec/data/XMLPublications.zip
22
+ spec/data/oddb_article.xml
23
+ spec/data/oddb_product.xml
24
+ spec/data/swissindex.xml
25
+ spec/data/wsdl.xml
26
+ spec/downloader_spec.rb
27
+ spec/extractor_spec.rb
28
+ spec/spec_helper.rb
data/bin/oddb2xml CHANGED
@@ -5,26 +5,44 @@ require 'pathname'
5
5
  root = Pathname.new(__FILE__).realpath.parent.parent
6
6
  $:.unshift root.join('lib') if $0 == __FILE__
7
7
 
8
+ require 'optparse'
8
9
  require 'oddb2xml'
9
10
 
10
- # TODO: Parse option
11
- args = ARGV.dup
11
+ def help
12
+ <<EOS
13
+ #$0 ver.#{Oddb2xml::VERSION}
14
+ Usage:
15
+ oddb2xml [option]
16
+ -c F, --compress=F Compress format F. Currently only 'tar.gz' is available.
17
+ -a T, --append=T Additional target. T is only 'nonpharma' available.
18
+ -h, --help Show this help message.
19
+ EOS
20
+ end
21
+
22
+ parser = OptionParser.new
12
23
  opts = {
13
- :compress => nil
24
+ :compress => nil,
25
+ :nonpharma => false
14
26
  }
15
- if args == ['-c', 'tar.gz']
16
- opts[:compress] = 'tar.gz'
17
- args = {}
27
+
28
+ parser.on('-c v', '--compress v', /tar\.gz/) {|v| opts[:compress] = v }
29
+ parser.on('-a v', '--append v', /nonpharma/) {|v| opts[:nonpharma] = v }
30
+ parser.on_tail('-h', '--help') { puts help; exit }
31
+
32
+ args = ARGV.dup
33
+ begin
34
+ parser.parse!(args)
35
+ rescue OptionParser::MissingArgument,
36
+ OptionParser::InvalidArgument,
37
+ OptionParser::InvalidOption
38
+ puts help
39
+ exit
18
40
  end
19
41
 
20
42
  ui = Oddb2xml::Cli.new(opts)
21
- unless args.empty?
22
- ui.help
23
- else
24
- begin
25
- ui.run
26
- rescue Interrupt
27
- puts
28
- exit
29
- end
43
+ begin
44
+ ui.run
45
+ rescue Interrupt
46
+ puts
47
+ exit
30
48
  end
data/lib/oddb2xml/cli.rb CHANGED
@@ -13,20 +13,12 @@ module Oddb2xml
13
13
  def initialize(args)
14
14
  @options = args
15
15
  #@mutex = Mutex.new
16
- @items = {} # Preparations.xml in BAG
17
- @index = {}
16
+ @items = {} # Items from Preparations.xml in BAG
17
+ @index = {} # Base index from swissINDEX
18
18
  LANGUAGES.each do |lang|
19
- @index[lang] = {} # swissINDEX
19
+ @index[lang] = {}
20
20
  end
21
21
  end
22
- def help
23
- puts <<EOS
24
- #$0 ver.#{Oddb2xml::VERSION}
25
- Usage:
26
- oddb2xml [option]
27
- -c compress option. currently only 'tar.gz' is available.
28
- EOS
29
- end
30
22
  def run
31
23
  # Sometimes nokogiri crashes with ruby in Threads.
32
24
  #threads = []
@@ -34,20 +26,20 @@ EOS
34
26
  #threads << Thread.new do
35
27
  downloader = BagXmlDownloader.new
36
28
  xml = downloader.download
37
- extractor = BagXmlExtractor.new(xml)
38
- @items = extractor.to_hash
29
+ @items = BagXmlExtractor.new(xml).to_hash
39
30
  #end
40
- LANGUAGES.map do |lang|
31
+ LANGUAGES.each do |lang|
41
32
  # swissindex
42
- #threads << Thread.new do
43
- downloader = SwissIndexDownloader.new
44
- xml = downloader.download_by(lang)
45
- extractor = SwissIndexExtractor.new(xml)
46
- index = extractor.to_hash
47
- #@mutex.synchronize do
48
- @index[lang] = index
33
+ types.each do |type|
34
+ #threads << Thread.new do
35
+ downloader = SwissIndexDownloader.new(type)
36
+ xml = downloader.download_by(lang)
37
+ hsh = SwissIndexExtractor.new(xml, type).to_hash
38
+ #@mutex.synchronize do
39
+ @index[lang][type] = hsh
40
+ #end
49
41
  #end
50
- #end
42
+ end
51
43
  end
52
44
  #threads.map(&:join)
53
45
  build
@@ -60,9 +52,16 @@ EOS
60
52
  begin
61
53
  files.each_pair do |sbj, file|
62
54
  builder = Builder.new do |builder|
55
+ index = {}
56
+ LANGUAGES.each do |lang|
57
+ index[lang] = {} unless index[lang]
58
+ types.each do |type|
59
+ index[lang].merge!(@index[lang][type])
60
+ end
61
+ end
63
62
  builder.subject = sbj
64
- builder.index = @index
65
- builder.items = @items
63
+ builder.index = index
64
+ builder.items = @items
66
65
  end
67
66
  xml = builder.to_xml
68
67
  File.open(file, 'w:utf-8'){ |fh| fh << xml }
@@ -84,7 +83,22 @@ EOS
84
83
  end
85
84
  end
86
85
  def report
87
- # pass
86
+ lines = []
87
+ LANGUAGES.each do |lang|
88
+ lines << lang
89
+ types.each do |type|
90
+ key = (type == :nonpharma ? 'NonPharma' : 'Pharma')
91
+ lines << sprintf("\t#{key} products: %i", @index[lang][type].values.length)
92
+ end
93
+ end
94
+ puts lines.join("\n")
95
+ end
96
+ def types # swissindex
97
+ if @options[:nonpharma]
98
+ [:pharma, :nonpharma]
99
+ else
100
+ [:pharma]
101
+ end
88
102
  end
89
103
  end
90
104
  end
@@ -24,8 +24,9 @@ module Oddb2xml
24
24
  File.unlink file
25
25
  end
26
26
  end
27
- rescue
28
- if File.exits? @compressed_file
27
+ rescue => error
28
+ puts error
29
+ if File.exists? @compressed_file
29
30
  File.unlink @compressed_file
30
31
  end
31
32
  return false
@@ -52,8 +52,12 @@ module Oddb2xml
52
52
  end
53
53
  end
54
54
  class SwissIndexDownloader < Downloader
55
+ def initialize(type=:pharma)
56
+ @type = (type == :pharma ? 'Pharma' : 'NonPharma')
57
+ url = "https://index.ws.e-mediat.net/Swissindex/#{@type}/ws_#{@type}_V101.asmx?WSDL"
58
+ super(url)
59
+ end
55
60
  def init
56
- @url ||= 'https://index.ws.e-mediat.net/Swissindex/Pharma/ws_Pharma_V101.asmx?WSDL'
57
61
  Savon.configure do |config|
58
62
  config.log_level = :info
59
63
  config.log = false # $stdout
@@ -66,12 +70,13 @@ module Oddb2xml
66
70
  wsdl.document = @url
67
71
  end
68
72
  begin
73
+ type = @type
69
74
  response = client.request :download_all do
70
75
  soap.xml = <<XML
71
76
  <?xml version="1.0" encoding="utf-8"?>
72
77
  <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/">
73
78
  <soap:Body>
74
- <lang xmlns="http://swissindex.e-mediat.net/SwissindexPharma_out_V101">#{lang}</lang>
79
+ <lang xmlns="http://swissindex.e-mediat.net/Swissindex#{type}_out_V101">#{lang}</lang>
75
80
  </soap:Body>
76
81
  </soap:Envelope>
77
82
  XML
@@ -11,9 +11,7 @@ module Oddb2xml
11
11
  end
12
12
  class BagXmlExtractor < Extractor
13
13
  def to_hash
14
- #File.open('../bagxml.xml', 'r:ASCII-8BIT') do |f|
15
- # @xml = f.read
16
- #end
14
+ #File.open('../bagxml.xml', 'r:ASCII-8BIT') {|f| @xml = f.read }
17
15
  # pharmacode => sequence
18
16
  data = {}
19
17
  doc = Nokogiri::XML(@xml)
@@ -90,15 +88,17 @@ module Oddb2xml
90
88
  end
91
89
  end
92
90
  class SwissIndexExtractor < Extractor
91
+ def initialize(xml, type)
92
+ @type = (type == :pharma ? 'PHARMA' : 'NONPHARMA')
93
+ super(xml)
94
+ end
93
95
  def to_hash
94
- #File.open('../swissindex.xml', 'r:ASCII-8BIT') do |f|
95
- # @xml = f.read
96
- #end
96
+ #File.open("../swissindex_#{@type.downcase}.xml", 'r:ASCII-8BIT'){|f| @xml = f.read }
97
97
  # pharmacode => package
98
98
  data = {}
99
99
  doc = Nokogiri::XML(@xml)
100
100
  doc.remove_namespaces!
101
- doc.xpath('//Envelope/Body/PHARMA/ITEM').each do |pac|
101
+ doc.xpath("//Envelope/Body/#{@type}/ITEM").each do |pac|
102
102
  item = {}
103
103
  item[:ean] = (gtin = pac.at_xpath('.//GTIN')) ? gtin.text : ''
104
104
  item[:pharmacode] = (phar = pac.at_xpath('.//PHAR')) ? phar.text : ''
@@ -1,3 +1,3 @@
1
1
  module Oddb2xml
2
- VERSION = "1.0.5"
2
+ VERSION = "1.0.6"
3
3
  end
data/oddb2xml.gemspec CHANGED
@@ -22,4 +22,8 @@ Gem::Specification.new do |gem|
22
22
  gem.add_dependency 'mechanize'
23
23
  gem.add_dependency 'nokogiri'
24
24
  gem.add_dependency 'savon'
25
+
26
+ gem.add_development_dependency 'rspec'
27
+ gem.add_development_dependency 'webmock'
28
+ gem.add_development_dependency 'ZenTest'
25
29
  end
@@ -0,0 +1,8 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Oddb2xml::Builder do
6
+ it 'pending'
7
+ end
8
+
data/spec/cli_spec.rb ADDED
@@ -0,0 +1,63 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ shared_examples_for 'any interface' do
6
+ it { cli.should respond_to(:run) }
7
+ it 'should run successfully' do
8
+ $stdout.should_receive(:puts).with(/product/)
9
+ cli.run
10
+ end
11
+ end
12
+
13
+ describe Oddb2xml::Cli do
14
+ include ServerMockHelper
15
+ before(:each) do
16
+ setup_server_mocks
17
+ end
18
+ context "when -c tar.gz option is given" do
19
+ let(:cli) { Oddb2xml::Cli.new({:compress => 'tar.gz', :nonpharma => false}) }
20
+ it { cli.instance_variable_get(:@options).should == {:compress => 'tar.gz', :nonpharma => false} }
21
+ it_behaves_like 'any interface'
22
+ it "should create tar.gz file" do
23
+ $stdout.should_receive(:puts).with(/Pharma/)
24
+ cli.run
25
+ file = Dir.glob('oddb_*.tar.gz').first
26
+ File.exists?(file).should be_true
27
+ end
28
+ it "should not create any xml file" do
29
+ $stdout.should_receive(:puts).with(/Nonpharma/)
30
+ cli.run
31
+ Dir.glob('oddb_*.xml').each do |file|
32
+ File.exists?(file).should be_nil
33
+ end
34
+ end
35
+ after(:each) do
36
+ Dir.glob('oddb_*.tar.gz').each do |file|
37
+ File.unlink(file) if File.exists?(file)
38
+ end
39
+ end
40
+ end
41
+ context "when -a nonpharma option is given" do
42
+ let(:cli) { Oddb2xml::Cli.new({:compress => nil, :nonpharma => true}) }
43
+ it { cli.instance_variable_get(:@options).should == {:compress => nil, :nonpharma => true} }
44
+ it_behaves_like 'any interface'
45
+ it "should not create any compressed file" do
46
+ $stdout.should_receive(:puts).with(/Pharma/)
47
+ cli.run
48
+ Dir.glob('oddb_*.tar.gz').first.should be_nil
49
+ end
50
+ it "should create 2 xml files" do
51
+ $stdout.should_receive(:puts).with(/Nonpharma/)
52
+ cli.run
53
+ Dir.glob('oddb_*.xml').each do |file|
54
+ File.exists?(file).should be_true
55
+ end
56
+ end
57
+ after(:each) do
58
+ Dir.glob('oddb_*.xml').each do |file|
59
+ File.unlink(file) if File.exists?(file)
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Oddb2xml::Compressor do
6
+ context "when tar.gz ext is given at initialize" do
7
+ before(:each) do
8
+ @compressor = Oddb2xml::Compressor.new('tar.gz')
9
+ end
10
+ it 'should have formated filename with datetime' do
11
+ @compressor.instance_variable_get(:@compressed_file).
12
+ should =~ /oddb_xml_\d{2}.\d{2}.\d{4}_\d{2}.\d{2}.tar\.gz/
13
+ end
14
+ it 'should have empty contents as array' do
15
+ @compressor.contents.should be_a Array
16
+ @compressor.contents.should be_empty
17
+ end
18
+ end
19
+ context 'when finalize! is called' do
20
+ before(:each) do
21
+ @compressor = Oddb2xml::Compressor.new()
22
+ end
23
+ context 'unexpectedly' do
24
+ it 'should fail with no contents' do
25
+ @compressor.finalize!.should == false
26
+ end
27
+ it 'should fail with invalid file' do
28
+ @compressor.contents << '../invalid_file'
29
+ @compressor.finalize!.should == false
30
+ end
31
+ end
32
+ context 'successfully' do
33
+ it 'pending'
34
+ end
35
+ end
36
+ end
37
+
Binary file
File without changes
File without changes
@@ -0,0 +1,56 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <soap:Envelope
3
+ xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
4
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema">
6
+ <soap:Body>
7
+ <PHARMA
8
+ CREATION_DATETIME="2012-10-18T06:31:19.4687619+02:00"
9
+ xmlns="http://example.com/test">
10
+ <ITEM DT="2012-10-18T00:00:00">
11
+ <GTIN>0000000000000</GTIN>
12
+ <PHAR>00000</PHAR>
13
+ <STATUS>A</STATUS>
14
+ <STDATE>2002-05-23T00:00:00</STDATE>
15
+ <LANG>DE</LANG>
16
+ <DSCR>Foo 1000 mg</DSCR>
17
+ <ADDSCR>Amp</ADDSCR>
18
+ <ATC>A00AA00</ATC>
19
+ <COMP>
20
+ <NAME>EXAMPLE.COM AG</NAME>
21
+ <GLN>0000000000000</GLN>
22
+ </COMP>
23
+ </ITEM>
24
+ <ITEM DT="2012-10-18T00:00:00">
25
+ <GTIN>0000000000001</GTIN>
26
+ <PHAR>00001</PHAR>
27
+ <STATUS>A</STATUS>
28
+ <STDATE>2002-05-23T00:00:00</STDATE>
29
+ <LANG>DE</LANG>
30
+ <DSCR>Bar 10 Stk</DSCR>
31
+ <ADDSCR>10 Stk</ADDSCR>
32
+ <ATC>A02AA02</ATC>
33
+ <COMP>
34
+ <NAME>EXAMPLE.ORG AG</NAME>
35
+ </COMP>
36
+ </ITEM>
37
+ <ITEM DT="2012-10-18T00:00:00">
38
+ <GTIN>0000000000002</GTIN>
39
+ <PHAR>00002</PHAR>
40
+ <STATUS>A</STATUS>
41
+ <STDATE>2002-05-23T00:00:00</STDATE>
42
+ <LANG>DE</LANG>
43
+ <DSCR>Baz 10 Tablet</DSCR>
44
+ <ADDSCR>5 Stk</ADDSCR>
45
+ <ATC>A03AA03</ATC>
46
+ <COMP>
47
+ <NAME>EXAMPLE.AC AG</NAME>
48
+ </COMP>
49
+ </ITEM>
50
+ <RESULT>
51
+ <OK_ERROR>OK</OK_ERROR>
52
+ <NBR_RECORD>3</NBR_RECORD>
53
+ </RESULT>
54
+ </PHARMA>
55
+ </soap:Body>
56
+ </soap:Envelope>
@@ -0,0 +1,55 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <wsdl:definitions
3
+ xmlns:s="http://www.w3.org/2001/XMLSchema"
4
+ xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
5
+ xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
6
+ xmlns:tns="http://example.com/test"
7
+ xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
8
+ xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
9
+ xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
10
+ xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
11
+ targetNamespace="http://example.com/test"
12
+ xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
13
+ <wsdl:types>
14
+ <s:schema elementFormDefault="qualified" targetNamespace="http://example.com/test">
15
+ </s:schema>
16
+ </wsdl:types>
17
+ <wsdl:message name="DownloadAllSoapIn">
18
+ <wsdl:part name="lang" element="tns:lang" />
19
+ </wsdl:message>
20
+ <wsdl:message name="DownloadAllSoapOut">
21
+ <wsdl:part name="DownloadAllResult" element="tns:PHARMA" />
22
+ </wsdl:message>
23
+ <wsdl:binding name="ws_Pharma_V101Soap" type="tns:ws_Pharma_V101Soap">
24
+ <soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
25
+ <wsdl:operation name="DownloadAll">
26
+ <soap:operation soapAction="http://example.com/DownloadAll" style="document" />
27
+ <wsdl:input>
28
+ <soap:body use="literal" />
29
+ </wsdl:input>
30
+ <wsdl:output>
31
+ <soap:body use="literal" />
32
+ </wsdl:output>
33
+ </wsdl:operation>
34
+ </wsdl:binding>
35
+ <wsdl:binding name="ws_Pharma_V101Soap12" type="tns:ws_Pharma_V101Soap">
36
+ <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" />
37
+ <wsdl:operation name="DownloadAll">
38
+ <soap12:operation soapAction="http://example.com/DownloadAll" style="document" />
39
+ <wsdl:input>
40
+ <soap12:body use="literal" />
41
+ </wsdl:input>
42
+ <wsdl:output>
43
+ <soap12:body use="literal" />
44
+ </wsdl:output>
45
+ </wsdl:operation>
46
+ </wsdl:binding>
47
+ <wsdl:service name="ws_Pharma_V101">
48
+ <wsdl:port name="ws_Pharma_V101Soap" binding="tns:ws_Pharma_V101Soap">
49
+ <soap:address location="https://example.com/test" />
50
+ </wsdl:port>
51
+ <wsdl:port name="ws_Pharma_V101Soap12" binding="tns:ws_Pharma_V101Soap12">
52
+ <soap12:address location="https://example.com/test" />
53
+ </wsdl:port>
54
+ </wsdl:service>
55
+ </wsdl:definitions>
@@ -0,0 +1,64 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ shared_examples_for 'any downloader' do
6
+ # this takes 5 sec. by call for sleep
7
+ it 'should count retry times as retrievable or not' do
8
+ expect {
9
+ Array.new(3).map do
10
+ Thread.new do
11
+ @downloader.send(:retrievable?).should be(true)
12
+ end
13
+ end.map(&:join)
14
+ }.to change {
15
+ @downloader.instance_variable_get(:@retry_times)
16
+ }.from(3).to(0)
17
+ end
18
+ end
19
+
20
+ describe Oddb2xml::BagXmlDownloader do
21
+ include ServerMockHelper
22
+ before(:each) do
23
+ setup_bag_xml_server_mock
24
+ @downloader = Oddb2xml::BagXmlDownloader.new()
25
+ end
26
+ it_behaves_like 'any downloader'
27
+ context 'when download is called' do
28
+ let(:xml) { @downloader.download }
29
+ it 'should parse zip to string' do
30
+ xml.should be_a String
31
+ xml.length.should_not == 0
32
+ end
33
+ it 'should return valid xml' do
34
+ xml.should =~ /xml\sversion="1.0"/
35
+ xml.should =~ /Preparations/
36
+ xml.should =~ /DescriptionDe/
37
+ end
38
+ it 'should cleanup current directory' do
39
+ xml.should_not raise_error(Timeout::Error)
40
+ File.exist?('XMLPublications.zip').should be(false)
41
+ end
42
+ end
43
+ end
44
+
45
+ describe Oddb2xml::SwissIndexDownloader do
46
+ include ServerMockHelper
47
+ before(:each) do
48
+ setup_swiss_index_server_mock
49
+ @downloader = Oddb2xml::SwissIndexDownloader.new()
50
+ end
51
+ it_behaves_like 'any downloader'
52
+ context 'when download_by is called with DE' do
53
+ let(:xml) { @downloader.download_by('DE') }
54
+ it 'should parse hash to xml' do
55
+ xml.should be_a String
56
+ xml.length.should_not == 0
57
+ end
58
+ it 'should return valid xml' do
59
+ xml.should =~ /xml\sversion="1.0"/
60
+ xml.should =~ /ITEM/
61
+ xml.should =~ /PHAR/
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,7 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Oddb2xml::Extractor do
6
+ it "pending"
7
+ end
@@ -0,0 +1,77 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ #
8
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
9
+ $:.unshift File.dirname(__FILE__)
10
+
11
+ require 'bundler/setup'
12
+ Bundler.require
13
+
14
+ require 'rspec'
15
+ require 'webmock/rspec'
16
+ require 'oddb2xml'
17
+
18
+ module ServerMockHelper
19
+ def setup_server_mocks
20
+ setup_bag_xml_server_mock
21
+ setup_swiss_index_server_mock
22
+ end
23
+ def setup_bag_xml_server_mock
24
+ # zip
25
+ stub_wsdl_url = 'http://bag.e-mediat.net/SL2007.Web.External/File.axd?file=XMLPublications.zip'
26
+ stub_response = File.read(File.expand_path('../data/XMLPublications.zip', __FILE__))
27
+ stub_request(:get, stub_wsdl_url).
28
+ with(:headers => {
29
+ 'Accept' => '*/*',
30
+ 'Accept-Encoding' => 'gzip,deflate,identity',
31
+ 'Host' => 'bag.e-mediat.net',
32
+ }).
33
+ to_return(
34
+ :status => 200,
35
+ :headers => {'Content-Type' => 'application/zip; charset=utf-8'},
36
+ :body => stub_response)
37
+ end
38
+ def setup_swiss_index_server_mock
39
+ # wsdl
40
+ stub_wsdl_url = 'https://index.ws.e-mediat.net/Swissindex/Pharma/ws_Pharma_V101.asmx?WSDL'
41
+ stub_response = File.read(File.expand_path('../data/wsdl.xml', __FILE__))
42
+ stub_request(:get, stub_wsdl_url).
43
+ with(:headers => {
44
+ 'Accept' => '*/*',
45
+ 'User-Agent' => 'Ruby'}).
46
+ to_return(
47
+ :status => 200,
48
+ :headers => {'Content-Type' => 'text/xml; charset=utf-8'},
49
+ :body => stub_response)
50
+ # soap (dummy)
51
+ stub_soap_url = 'https://example.com/test'
52
+ stub_response = File.read(File.expand_path('../data/swissindex.xml', __FILE__))
53
+ stub_request(:post, stub_soap_url).
54
+ with(:headers => {
55
+ 'Accept' => '*/*',
56
+ 'User-Agent' => 'Ruby'}).
57
+ to_return(
58
+ :status => 200,
59
+ :headers => {'Content-Type' => 'text/xml; chaprset=utf-8'},
60
+ :body => stub_response)
61
+ end
62
+ end
63
+
64
+ RSpec.configure do |config|
65
+ config.treat_symbols_as_metadata_keys_with_true_values = true
66
+ config.run_all_when_everything_filtered = true
67
+ config.filter_run :focus
68
+
69
+ # Run specs in random order to surface order dependencies. If you find an
70
+ # order dependency and want to debug it, you can fix the order by providing
71
+ # the seed, which is printed after each run.
72
+ # --seed 1234
73
+ config.order = 'random'
74
+
75
+ # Helper
76
+ config.include(ServerMockHelper)
77
+ end