xmlconv 1.1.0 → 1.1.1
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.
- checksums.yaml +4 -4
- data/.travis.yml +25 -0
- data/Gemfile +2 -4
- data/History.txt +7 -2
- data/lib/xmlconv/config.rb +10 -0
- data/lib/xmlconv/i2/header.rb +2 -1
- data/lib/xmlconv/i2/position.rb +2 -2
- data/lib/xmlconv/state/global.rb +2 -2
- data/lib/xmlconv/state/login.rb +25 -4
- data/lib/xmlconv/util/application.rb +52 -27
- data/lib/xmlconv/util/autoload.rb +7 -6
- data/lib/xmlconv/util/destination.rb +26 -30
- data/lib/xmlconv/util/mail.rb +2 -11
- data/lib/xmlconv/util/polling_manager.rb +8 -4
- data/lib/xmlconv/util/transaction.rb +2 -2
- data/lib/xmlconv/version.rb +1 -1
- data/lib/xmlconv/view/login.rb +4 -0
- data/test/suite.rb +5 -1
- data/test/test_i2/header.rb +2 -2
- data/test/test_i2/position.rb +4 -8
- data/test/test_util/application.rb +12 -4
- data/test/test_util/destination.rb +39 -15
- data/test/test_util/polling_manager.rb +9 -7
- data/test/test_util/transaction.rb +10 -11
- data/xmlconv.gemspec +11 -22
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a0cc0602375720c02d07d9739b38ff86f435f38
|
4
|
+
data.tar.gz: 7f3d6a5737221b3f8a6edde132d0371930f7b155
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 433c00703555c1a93a404bf2b9214422598e1a7d13123a161ee1b2eb48a99108f20515099c7b401168511f3d59d4ac8b13cb5e1a1aee9c73cb923205d705cf19
|
7
|
+
data.tar.gz: 4e8b6f90feec79de4276ba716b4418dfe5cfc33cddeea9981ab2b3df03ef7e5ddaa55f053b3d22cc3a3825174d405d2c080737a468ad6046fe17ea0131f7dd8b
|
data/.travis.yml
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
language: ruby
|
2
|
+
|
3
|
+
bundler_args: --without debugger
|
4
|
+
|
5
|
+
cache: bundler
|
6
|
+
sudo: false
|
7
|
+
|
8
|
+
before_install:
|
9
|
+
- gem --version
|
10
|
+
|
11
|
+
script: bundle exec test/suite.rb
|
12
|
+
|
13
|
+
rvm:
|
14
|
+
- 2.3.1
|
15
|
+
- 2.4.0
|
16
|
+
- ruby-head
|
17
|
+
|
18
|
+
matrix:
|
19
|
+
allow_failures:
|
20
|
+
- rvm: ruby-head
|
21
|
+
|
22
|
+
notifications:
|
23
|
+
email:
|
24
|
+
recipients:
|
25
|
+
- ngiger@ywesee.com
|
data/Gemfile
CHANGED
data/History.txt
CHANGED
@@ -1,7 +1,12 @@
|
|
1
|
+
=== 1.1.1 / 06.06.2017
|
2
|
+
|
3
|
+
* Adapted to use the rack based SBSM
|
4
|
+
* Require Ruby >= 2.0 and mail gem
|
5
|
+
|
1
6
|
=== 1.1.0 / 02.09.2016
|
2
7
|
|
3
|
-
*
|
4
|
-
*
|
8
|
+
* Removed use of TMail/Net:SMTP in lib/xmlconv/util/destination.rb
|
9
|
+
* Various fixes for passing the tests
|
5
10
|
|
6
11
|
=== 1.0.9 / 25.07.2016
|
7
12
|
|
data/lib/xmlconv/config.rb
CHANGED
@@ -24,6 +24,7 @@ module XmlConv
|
|
24
24
|
'access' => {},
|
25
25
|
'commission' => 0.3, ## Commission in percent
|
26
26
|
'config' => default_config_files,
|
27
|
+
'bbmb_url' => 'druby://localhost:12004',
|
27
28
|
'db_name' => 'xmlconv',
|
28
29
|
'db_user' => 'xmlconv',
|
29
30
|
'db_auth' => '',
|
@@ -38,6 +39,7 @@ module XmlConv
|
|
38
39
|
'mail_from' => 'xmlconv@ywesee.com',
|
39
40
|
'pass_hash' => nil,
|
40
41
|
'polling_file' => conf_dir,
|
42
|
+
'polling_interval' => nil,
|
41
43
|
'program_name' => 'XmlConv2',
|
42
44
|
'project_root' => data_dir,
|
43
45
|
'plugin_dir' => File.expand_path('conversion', code_dir),
|
@@ -49,9 +51,17 @@ module XmlConv
|
|
49
51
|
'ssh_known_hosts_file'=> File.expand_path('known_hosts', conf_dir),
|
50
52
|
'target_format_fs' => ',',
|
51
53
|
'target_format_rs' => "\n",
|
54
|
+
'smtp_server' => 'smtp.gmail.com',
|
55
|
+
'smtp_user' => 'nouser@nowhere.com',
|
56
|
+
'smtp_domain' => 'no.domain.com',
|
57
|
+
'smtp_authtype' => 'plain',
|
58
|
+
'smtp_port' => '587',
|
59
|
+
'smtp_pass' => 'thisIsNotApassword',
|
52
60
|
'ydim_id' => nil,
|
53
61
|
'ydim_config' => nil,
|
54
62
|
'vat_rate' => 7.6,
|
63
|
+
'reader' => 'XundartBdd',
|
64
|
+
'writer' => 'BddCsv',
|
55
65
|
}
|
56
66
|
|
57
67
|
config = RCLConf::RCLConf.new(ARGV, defaults)
|
data/lib/xmlconv/i2/header.rb
CHANGED
@@ -5,6 +5,7 @@
|
|
5
5
|
module XmlConv
|
6
6
|
module I2
|
7
7
|
class Header
|
8
|
+
TRANSACTION_TIME_FORMAT = '%Y%m%d%H%M'
|
8
9
|
attr_accessor :recipient_id, :filename, :prefix, :transaction_id
|
9
10
|
attr_reader :suffix
|
10
11
|
def initialize(recipient_id = 'EPIN_PL')
|
@@ -13,7 +14,7 @@ module XmlConv
|
|
13
14
|
time = Time.now
|
14
15
|
# msec = sprintf('%03i', (time.to_f * 1000).to_i % 100)
|
15
16
|
#@transaction_id = time.strftime("%Y%m%d%H%M#{msec}")
|
16
|
-
@transaction_id = time.strftime(
|
17
|
+
@transaction_id = time.strftime(TRANSACTION_TIME_FORMAT)
|
17
18
|
end
|
18
19
|
def suffix=(suffix)
|
19
20
|
@suffix = "_" << suffix.to_s
|
data/lib/xmlconv/i2/position.rb
CHANGED
@@ -6,7 +6,7 @@ require 'xmlconv/i2/date'
|
|
6
6
|
module XmlConv
|
7
7
|
module I2
|
8
8
|
class Position
|
9
|
-
attr_accessor :number, :article_ean, :qty, :customer_id, :price, :unit,
|
9
|
+
attr_accessor :number, :article_ean, :qty, :customer_id, :price, :unit,
|
10
10
|
:pharmacode, :free_text
|
11
11
|
attr_reader :delivery_date
|
12
12
|
def delivery_date=(date)
|
@@ -17,7 +17,7 @@ module XmlConv
|
|
17
17
|
output = <<-EOS
|
18
18
|
500:#{@number}
|
19
19
|
EOS
|
20
|
-
#501:#{@article_ean}
|
20
|
+
# output << "501:#{@article_ean}\n"
|
21
21
|
[@customer_id, @pharmacode].compact.each { |id|
|
22
22
|
#output << sprintf("502:%s\n", id)
|
23
23
|
output << sprintf("501:%s\n", id)
|
data/lib/xmlconv/state/global.rb
CHANGED
@@ -14,14 +14,14 @@ module XmlConv
|
|
14
14
|
end
|
15
15
|
def transaction
|
16
16
|
if((id = @session.user_input(:transaction_id)) \
|
17
|
-
&& (transaction = @session.transaction(id)))
|
17
|
+
&& (transaction = @session.persistence_layer.transaction(id)))
|
18
18
|
Transaction.new(@session, transaction)
|
19
19
|
else
|
20
20
|
self
|
21
21
|
end
|
22
22
|
end
|
23
23
|
def home
|
24
|
-
Transactions.new(@session, @session.transactions)
|
24
|
+
Transactions.new(@session, @session.persistence_layer.transactions)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
data/lib/xmlconv/state/login.rb
CHANGED
@@ -9,17 +9,38 @@ module XmlConv
|
|
9
9
|
module State
|
10
10
|
class Login < SBSM::State
|
11
11
|
VIEW = View::Login
|
12
|
+
def initialize(session, model)
|
13
|
+
if session.request_method.eql?('POST')
|
14
|
+
session.request_params
|
15
|
+
xml_src = "#{session.request_params.keys.first} #{session.request_params.values.first}"
|
16
|
+
unless xml_src.length == 0
|
17
|
+
transaction = XmlConv::Util::Transaction.new
|
18
|
+
transaction.domain = session.server_name
|
19
|
+
transaction.input = xml_src
|
20
|
+
transaction.reader = 'SunStoreBdd'
|
21
|
+
transaction.writer = XmlConv::CONFIG.writer
|
22
|
+
poll_config = YAML.load_file(XmlConv::CONFIG.polling_file)
|
23
|
+
transaction.destination = XmlConv::Util::Destination.book(poll_config.destination)
|
24
|
+
transaction.partner = File.basename(session.request_path)
|
25
|
+
transaction.origin = session.request_origin
|
26
|
+
transaction.postprocs.push(['Soap', 'update_partner'])
|
27
|
+
transaction.postprocs.push(['Bbmb2', 'inject', XmlConv::CONFIG.bbmb_url, 'customer_id'])
|
28
|
+
res = session.app.execute_with_response(transaction)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
super
|
32
|
+
end
|
12
33
|
def login
|
13
34
|
if(@session.login)
|
14
|
-
Transactions.new(@session, @session.transactions)
|
35
|
+
Transactions.new(@session, @session.persistence_layer.transactions)
|
15
36
|
else
|
16
37
|
self
|
17
38
|
end
|
18
39
|
end
|
19
40
|
def transaction
|
20
41
|
if((id = @session.user_input(:transaction_id)) \
|
21
|
-
&& (transaction = @session.transaction(id)))
|
22
|
-
TransactionLogin.new(@session, transaction)
|
42
|
+
&& (transaction = @session.persistence_layer.transaction(id)))
|
43
|
+
TransactionLogin.new(@session.persistence_layer, transaction)
|
23
44
|
else
|
24
45
|
self
|
25
46
|
end
|
@@ -29,7 +50,7 @@ module XmlConv
|
|
29
50
|
VIEW = View::Login
|
30
51
|
def login
|
31
52
|
if(@session.login)
|
32
|
-
Transaction.new(@session, @model)
|
53
|
+
Transaction.new(@session.persistence_layer, @model)
|
33
54
|
else
|
34
55
|
self
|
35
56
|
end
|
@@ -3,15 +3,20 @@
|
|
3
3
|
# XmlConv::Application -- xmlconv -- 29.09.2011 -- mhatakeyama@ywesee.com
|
4
4
|
# XmlConv::Application -- xmlconv2 -- 07.06.2004 -- hwyss@ywesee.com
|
5
5
|
|
6
|
-
require '
|
6
|
+
require 'drb/drb'
|
7
|
+
require 'odba'
|
8
|
+
require 'csv'
|
9
|
+
require 'sbsm/admin_server'
|
10
|
+
require 'xmlconv/config'
|
7
11
|
require 'xmlconv/state/global'
|
8
12
|
require 'xmlconv/util/invoicer'
|
9
13
|
require 'xmlconv/util/polling_manager'
|
10
14
|
require 'xmlconv/util/session'
|
11
15
|
require 'xmlconv/util/transaction'
|
12
16
|
require 'xmlconv/util/validator'
|
17
|
+
require 'odba/connection_pool'
|
18
|
+
require 'xmlconv/util/autoload'
|
13
19
|
require 'thread'
|
14
|
-
require 'odba'
|
15
20
|
require 'xmlconv/model/bdd'
|
16
21
|
|
17
22
|
module XmlConv
|
@@ -58,7 +63,7 @@ module XmlConv
|
|
58
63
|
transaction_id = transaction_id.to_i
|
59
64
|
if((last_id = @transactions.last.transaction_id) \
|
60
65
|
&& (last_id >= transaction_id))
|
61
|
-
start = (transaction_id - last_id - 1)
|
66
|
+
start = (transaction_id - last_id - 1)
|
62
67
|
if(start + @transactions.size < 0)
|
63
68
|
start = 0
|
64
69
|
end
|
@@ -68,7 +73,7 @@ module XmlConv
|
|
68
73
|
end
|
69
74
|
end
|
70
75
|
def send_invoice(time_range, date = Date.today)
|
71
|
-
transactions = @transactions.select { |trans|
|
76
|
+
transactions = @transactions.select { |trans|
|
72
77
|
time_range.include?(trans.commit_time)
|
73
78
|
}
|
74
79
|
Util::Invoicer.run(time_range, transactions, date)
|
@@ -88,31 +93,51 @@ module XmlConv
|
|
88
93
|
end
|
89
94
|
end
|
90
95
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
96
|
+
def XmlConv.start_server
|
97
|
+
XmlConv::Util.autoload(XmlConv::CONFIG.plugin_dir, 'plugin')
|
98
|
+
XmlConv::Util.autoload(XmlConv::CONFIG.postproc_dir, 'postproc')
|
99
|
+
Mail.defaults do
|
100
|
+
delivery_method(:smtp, address: XmlConv::CONFIG.smtp_server, port: XmlConv::CONFIG.smtp_port,
|
101
|
+
domain: XmlConv::CONFIG.smtp_domain, user_name: XmlConv::CONFIG.smtp_user,
|
102
|
+
password: XmlConv::CONFIG.smtp_pass, authentication: XmlConv::CONFIG.smtp_authtype,
|
103
|
+
enable_starttls_auto: true)
|
104
|
+
end
|
105
|
+
|
106
|
+
ODBA.storage.dbi = ODBA::ConnectionPool.new("DBI:Pg:#{XmlConv::CONFIG.db_name}",
|
107
|
+
XmlConv::CONFIG.db_user, XmlConv::CONFIG.db_auth)
|
108
|
+
ODBA.cache.setup
|
109
|
+
puts "#{Time.now}: Prefetching cache. This may take a minute or two"
|
110
|
+
ODBA.cache.prefetch
|
111
|
+
$0 = XmlConv::CONFIG.program_name
|
112
|
+
puts "#{Time.now}: Prefetching finshed program name is #{$0}"
|
113
|
+
app = XmlConvApp.new
|
114
|
+
DRb.start_service(XmlConv::CONFIG.server_url, app)
|
115
|
+
SBSM.logger.info(XmlConv::CONFIG.program_name) { "drb-service listening on #{XmlConv::CONFIG.server_url}" }
|
116
|
+
puts "#{Time.now}: start_server done returning #{app.class}"
|
117
|
+
app
|
118
|
+
end
|
119
|
+
|
120
|
+
class XmlConvApp < SBSM::AdminServer
|
121
|
+
attr_reader :app, :persistence_layer, :polling_thread, :dispatch_queue, :dispatcher_thread
|
122
|
+
POLLING_INTERVAL = 60 #* 15
|
123
|
+
def initialize(app: XmlConv::Util::RackInterface.new)
|
124
|
+
@rack_app = app
|
125
|
+
super(app: app)
|
126
|
+
@persistence_layer = ODBA.cache.fetch_named('XmlConv', self) do XmlConv::Util::Application.new end
|
127
|
+
@persistence_layer.init
|
102
128
|
@dispatch_queue = Queue.new
|
103
|
-
|
104
|
-
|
105
|
-
|
129
|
+
@polling_interval = XmlConv::CONFIG.polling_interval || self::class::POLLING_INTERVAL
|
130
|
+
puts "@polling_interval is #{@polling_interval} @persistence_layer is #{@persistence_layer.class}"
|
131
|
+
start_polling if @polling_interval
|
106
132
|
start_dispatcher
|
107
133
|
start_invoicer if XmlConv::CONFIG.run_invoicer
|
108
|
-
super(@system)
|
109
134
|
end
|
110
135
|
def dispatch(transaction)
|
111
136
|
@dispatch_queue.push(transaction)
|
112
137
|
end
|
113
138
|
def execute_with_response(transaction)
|
114
139
|
begin
|
115
|
-
@
|
140
|
+
@persistence_layer.execute(transaction)
|
116
141
|
rescue Exception => e
|
117
142
|
puts "rescued #{e.class}"
|
118
143
|
end
|
@@ -121,21 +146,21 @@ class XmlConvApp < SBSM::DRbServer
|
|
121
146
|
def start_dispatcher
|
122
147
|
@dispatcher_thread = Thread.new {
|
123
148
|
Thread.current.abort_on_exception = true
|
124
|
-
loop {
|
125
|
-
@
|
149
|
+
loop {
|
150
|
+
@persistence_layer.execute(@dispatch_queue.pop)
|
126
151
|
}
|
127
152
|
}
|
128
153
|
end
|
129
154
|
def start_invoicer
|
130
155
|
@invoicer_thread = Thread.new {
|
131
156
|
Thread.current.abort_on_exception = true
|
132
|
-
loop {
|
157
|
+
loop {
|
133
158
|
this_month = Date.today
|
134
159
|
next_month = this_month >> 1
|
135
160
|
strt = Time.local(this_month.year, this_month.month)
|
136
161
|
stop = Time.local(next_month.year, next_month.month)
|
137
162
|
sleep(stop - Time.now)
|
138
|
-
@
|
163
|
+
@persistence_layer.send_invoice(strt...stop)
|
139
164
|
}
|
140
165
|
}
|
141
166
|
end
|
@@ -144,13 +169,13 @@ class XmlConvApp < SBSM::DRbServer
|
|
144
169
|
Thread.current.abort_on_exception = true
|
145
170
|
loop {
|
146
171
|
begin
|
147
|
-
XmlConv::Util::PollingManager.new(@
|
172
|
+
XmlConv::Util::PollingManager.new(@persistence_layer).poll_sources
|
148
173
|
rescue Exception => exc
|
149
|
-
|
174
|
+
SBSM.logger.error(XmlConv::CONFIG.program_name) {
|
150
175
|
[exc.class, exc.message].concat(exc.backtrace).join("\n")
|
151
176
|
}
|
152
177
|
end
|
153
|
-
sleep(
|
178
|
+
sleep(@polling_interval)
|
154
179
|
}
|
155
180
|
}
|
156
181
|
end
|
@@ -1,29 +1,30 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# Util#autoload -- xmlconv2 -- 28.08.2006 -- hwyss@ywesee.com
|
3
|
+
require 'sbsm/logger'
|
3
4
|
|
4
5
|
module XmlConv
|
5
6
|
module Util
|
6
7
|
def Util.autoload(dir, type)
|
7
8
|
config = XmlConv::CONFIG
|
8
|
-
logger =
|
9
|
+
logger = SBSM.logger
|
9
10
|
dir = File.expand_path(dir)
|
10
11
|
prefix = File.basename(dir)
|
11
12
|
search_path = File.dirname(dir)
|
12
13
|
$:.push(search_path) unless $:.include?(search_path)
|
13
|
-
logger.debug(config.program_name) {
|
14
|
-
"checking directory '#{dir}' for #{type}s"
|
14
|
+
logger.debug(config.program_name) {
|
15
|
+
"checking directory '#{dir}' for #{type}s"
|
15
16
|
}
|
16
17
|
Dir.glob(File.join(dir, '*')) { |entry|
|
17
18
|
if(/\.(rb|so)$/.match(entry))
|
18
19
|
keyword = File.basename(entry)
|
19
20
|
keyword.slice!(/#{File.extname(keyword)}$/)
|
20
21
|
rpath = File.join(prefix, keyword)
|
21
|
-
logger.debug(config.program_name) {
|
22
|
-
"loading #{type}: '#{rpath}' (#{File.basename(entry)})"
|
22
|
+
logger.debug(config.program_name) {
|
23
|
+
"loading #{type}: '#{rpath}' (#{File.basename(entry)})"
|
23
24
|
}
|
24
25
|
begin
|
25
26
|
require rpath #File.basename(keyword)
|
26
|
-
rescue
|
27
|
+
rescue
|
27
28
|
logger.warn(config.program_name) {
|
28
29
|
"loading #{type} '#{rpath}' failed!"
|
29
30
|
}
|
@@ -16,8 +16,8 @@ module XmlConv
|
|
16
16
|
attr_accessor :path, :status
|
17
17
|
attr_reader :uri
|
18
18
|
STATUS_COMPARABLE = {
|
19
|
-
:pending_pickup => 10,
|
20
|
-
:picked_up => 20,
|
19
|
+
:pending_pickup => 10,
|
20
|
+
:picked_up => 20,
|
21
21
|
:bbmb_ok => 20,
|
22
22
|
:http_ok => 20,
|
23
23
|
:ftp_ok => 20,
|
@@ -49,7 +49,7 @@ module XmlConv
|
|
49
49
|
def update_status
|
50
50
|
end
|
51
51
|
def status_comparable
|
52
|
-
self::class::STATUS_COMPARABLE[@status].to_i
|
52
|
+
self::class::STATUS_COMPARABLE[@status].to_i
|
53
53
|
end
|
54
54
|
def sanitize(str)
|
55
55
|
str.to_s.gsub(/[^a-zA-Z0-9 _.]/, '').gsub(' ', '+')
|
@@ -97,8 +97,8 @@ module XmlConv
|
|
97
97
|
forget_credentials!
|
98
98
|
end
|
99
99
|
def forget_credentials!
|
100
|
-
|
101
|
-
|
100
|
+
path = /^\//.match(@uri.path) ? @uri.path : '/' + @uri.path
|
101
|
+
@uri = URI::HTTP.new(@uri.scheme, nil, @uri.host, @uri.port, @uri.registry, path, @uri.opaque, @uri.query, @uri.fragment)
|
102
102
|
end
|
103
103
|
def host
|
104
104
|
@uri.host
|
@@ -128,17 +128,17 @@ module XmlConv
|
|
128
128
|
@transport = Net::FTP
|
129
129
|
end
|
130
130
|
def do_deliver(delivery)
|
131
|
-
@transport.open(@uri.host, @uri.user, @uri.password)
|
131
|
+
@transport.open(@uri.host, @uri.user, @uri.password) do |conn|
|
132
132
|
conn.chdir(@uri.path)
|
133
133
|
deliver_to_connection(conn, delivery)
|
134
|
-
|
134
|
+
end
|
135
135
|
end
|
136
136
|
def deliver_to_connection(connection, delivery, idx=nil)
|
137
137
|
if(delivery.is_a?(Array))
|
138
|
-
#delivery.each_with_index { |part, idx|
|
139
|
-
delivery.each { |part|
|
140
|
-
#deliver_to_connection(connection, part, idx)
|
141
|
-
deliver_to_connection(connection, part)
|
138
|
+
#delivery.each_with_index { |part, idx|
|
139
|
+
delivery.each { |part|
|
140
|
+
#deliver_to_connection(connection, part, idx)
|
141
|
+
deliver_to_connection(connection, part)
|
142
142
|
}
|
143
143
|
else
|
144
144
|
fh = Tempfile.new('xmlconv')
|
@@ -146,7 +146,7 @@ module XmlConv
|
|
146
146
|
fh.flush
|
147
147
|
target = delivery.filename
|
148
148
|
# if(idx)
|
149
|
-
#
|
149
|
+
#targidxet = sprintf("%03i_%s", idx, target)
|
150
150
|
# target.gsub!(/\.dat/, "%03i.dat" % idx)
|
151
151
|
# target.gsub!(/(CO_\d{13})/, '\1%02d' % idx)
|
152
152
|
# end
|
@@ -174,9 +174,9 @@ module XmlConv
|
|
174
174
|
def do_deliver(delivery)
|
175
175
|
if(delivery.is_a?(Array))
|
176
176
|
worst_status = ''
|
177
|
-
delivery.each { |part|
|
178
|
-
do_deliver(part)
|
179
|
-
## bogostatus: assume that the more information in the string,
|
177
|
+
delivery.each { |part|
|
178
|
+
do_deliver(part)
|
179
|
+
## bogostatus: assume that the more information in the string,
|
180
180
|
## the worse the status is (ok < not found)
|
181
181
|
## rationale: DTSTTCPW
|
182
182
|
if(@status.to_s > worst_status.to_s)
|
@@ -190,7 +190,7 @@ module XmlConv
|
|
190
190
|
if(@uri.user || @uri.password)
|
191
191
|
request.basic_auth(@uri.user, @uri.password)
|
192
192
|
end
|
193
|
-
response = http.request(request, delivery.to_s)
|
193
|
+
response = http.request(request, delivery.to_s)
|
194
194
|
status_str = response.message.downcase.gsub(/\s+/, "_")
|
195
195
|
@status = "http_#{status_str}".intern
|
196
196
|
}
|
@@ -202,23 +202,19 @@ module XmlConv
|
|
202
202
|
@uri = uri
|
203
203
|
super()
|
204
204
|
end
|
205
|
-
def deliver(
|
205
|
+
def deliver(my_body)
|
206
|
+
XmlConv::CONFIG.mail_from ||= 'dummy@nowhere.org'
|
206
207
|
recipients = [@uri.to].compact
|
207
208
|
recipients.uniq!
|
208
209
|
return if(recipients.empty?)
|
209
|
-
|
210
|
-
mail =
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
mail['User-Agent'] = 'XmlConv::Util::Destination'
|
218
|
-
Net::SMTP.start(XmlConv::CONFIG.mail_host) { |smtp|
|
219
|
-
smtp.sendmail(mail.encoded, XmlConv::CONFIG.mail_from, recipients)
|
220
|
-
}
|
221
|
-
@status = :mail_ok
|
210
|
+
my_subject = 'XmlConv - Delivery'
|
211
|
+
mail = ::Mail.deliver do
|
212
|
+
from XmlConv::CONFIG.mail_from
|
213
|
+
to recipients
|
214
|
+
subject my_subject
|
215
|
+
body my_body.to_s
|
216
|
+
end
|
217
|
+
@status = :mail_ok unless mail.error_status
|
222
218
|
odba_store
|
223
219
|
end
|
224
220
|
end
|
data/lib/xmlconv/util/mail.rb
CHANGED
@@ -1,23 +1,13 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# Util::Mail -- XmlConv -- 23.04.2009 -- hwyss@ywesee.com
|
3
3
|
|
4
|
-
require '
|
5
|
-
unless /^1\.8/.match(RUBY_VERSION)
|
6
|
-
require 'mail'
|
7
|
-
end
|
8
|
-
|
4
|
+
require 'mail'
|
9
5
|
require 'xmlconv/config'
|
10
6
|
|
11
7
|
module XmlConv
|
12
8
|
module Util
|
13
9
|
module Mail
|
14
|
-
SMTP_HANDLER = Net::SMTP
|
15
10
|
def Mail.notify recipients, my_subject, my_body
|
16
|
-
unless /^1\.8/.match(RUBY_VERSION)
|
17
|
-
puts "XmlConv::Util::Mail.notify #{ XmlConv::CONFIG.mail_from} -> #{recipients} subject: #{my_subject}"
|
18
|
-
puts "Skipping as RUBY_VERSON is #{RUBY_VERSION}"
|
19
|
-
return
|
20
|
-
end
|
21
11
|
recipients.flatten!
|
22
12
|
recipients.compact!
|
23
13
|
recipients.uniq!
|
@@ -29,6 +19,7 @@ module Mail
|
|
29
19
|
subject my_subject
|
30
20
|
body my_body
|
31
21
|
end
|
22
|
+
puts "XmlConv::Util::Mail.notify failed #{mail.error_status}" if mail.error_status
|
32
23
|
end
|
33
24
|
end
|
34
25
|
end
|
@@ -13,7 +13,7 @@ module XmlConv
|
|
13
13
|
module Util
|
14
14
|
class Mission
|
15
15
|
attr_accessor :reader, :writer, :destination, :error_recipients,
|
16
|
-
:debug_recipients, :backup_dir, :partner, :postprocs, :filter,
|
16
|
+
:debug_recipients, :backup_dir, :partner, :postprocs, :filter,
|
17
17
|
:tmp_destination, :arguments
|
18
18
|
def create_transaction
|
19
19
|
transaction = XmlConv::Util::Transaction.new
|
@@ -182,17 +182,21 @@ module XmlConv
|
|
182
182
|
file.close if(file)
|
183
183
|
end
|
184
184
|
def poll_sources
|
185
|
-
load_sources
|
185
|
+
load_sources do |source|
|
186
186
|
begin
|
187
187
|
source.poll { |transaction|
|
188
188
|
@system.execute(transaction)
|
189
189
|
}
|
190
190
|
rescue Exception => e
|
191
191
|
subject = 'XmlConv2 - Polling-Error'
|
192
|
-
body = [e.class, e.message
|
192
|
+
body = [e.class, e.message,
|
193
|
+
defined?(source.user) ? 'user '+ source.user : nil,
|
194
|
+
defined?(source.host) ? 'host '+ source.host : nil,
|
195
|
+
defined?(source.port) ? 'port '+ source.port.to_s : nil
|
196
|
+
].compact.concat(e.backtrace).join("\n")
|
193
197
|
Util::Mail.notify source.error_recipients, subject, body
|
194
198
|
end
|
195
|
-
|
199
|
+
end
|
196
200
|
end
|
197
201
|
end
|
198
202
|
end
|
@@ -136,12 +136,12 @@ Output:
|
|
136
136
|
end
|
137
137
|
def status_comparable
|
138
138
|
if(@destination.respond_to?(:status_comparable))
|
139
|
-
@destination.status_comparable
|
139
|
+
@destination.status_comparable
|
140
140
|
end
|
141
141
|
end
|
142
142
|
def update_status
|
143
143
|
if(@destination.respond_to?(:update_status))
|
144
|
-
@destination.update_status
|
144
|
+
@destination.update_status
|
145
145
|
end
|
146
146
|
end
|
147
147
|
def uri
|
data/lib/xmlconv/version.rb
CHANGED
data/lib/xmlconv/view/login.rb
CHANGED
data/test/suite.rb
CHANGED
@@ -2,8 +2,12 @@
|
|
2
2
|
# TestSuite -- xmlconv2 -- 01.06.2004 -- hwyss@ywesee.com
|
3
3
|
|
4
4
|
$: << File.dirname(File.expand_path(__FILE__))
|
5
|
+
begin
|
6
|
+
require 'pry'
|
7
|
+
rescue LoadError
|
8
|
+
end
|
5
9
|
|
6
|
-
current_dir = File.dirname(__FILE__)
|
10
|
+
current_dir = File.dirname(__FILE__)
|
7
11
|
Dir.foreach(current_dir) { |dirname|
|
8
12
|
dirpath = File.expand_path(dirname, current_dir)
|
9
13
|
if(/^test_/o.match(dirname) && (File.ftype(dirpath) == 'directory'))
|
data/test/test_i2/header.rb
CHANGED
@@ -31,8 +31,8 @@ module XmlConv
|
|
31
31
|
assert_equal(expected, @header.to_s)
|
32
32
|
end
|
33
33
|
def test_filename
|
34
|
-
expected = Time.now.strftime("#{@header.recipient_id}_
|
35
|
-
assert_match(/#{expected}
|
34
|
+
expected = Time.now.strftime("#{@header.recipient_id}_#{Header::TRANSACTION_TIME_FORMAT}")
|
35
|
+
assert_match(/#{expected}.dat/, @header.filename)
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
data/test/test_i2/position.rb
CHANGED
@@ -28,17 +28,13 @@ module XmlConv
|
|
28
28
|
@position.number = '12345'
|
29
29
|
@position.article_ean = '7654321098765'
|
30
30
|
@position.qty = 123
|
31
|
-
|
32
|
-
date.should_receive(:code=).and_return({})
|
33
|
-
date.should_receive(:is_a?).and_return(I2::Date)
|
34
|
-
@position.delivery_date = date
|
35
|
-
date.should_receive(:to_s=).and_return("540:A Date\n")
|
31
|
+
@position.delivery_date = I2::Date.new(1999,12,31)
|
36
32
|
expected = <<-EOS
|
37
33
|
500:12345
|
38
|
-
501:7654321098765
|
39
34
|
520:123
|
40
|
-
540:
|
41
|
-
|
35
|
+
540:2
|
36
|
+
541:19991231
|
37
|
+
EOS
|
42
38
|
assert_equal(expected, @position.to_s)
|
43
39
|
end
|
44
40
|
def test_delivery_date_writer
|
@@ -39,6 +39,9 @@ module XmlConv
|
|
39
39
|
ODBA.cache = cache
|
40
40
|
transaction.should_receive(:transaction_id=).with(1)
|
41
41
|
transaction.should_receive(:execute).once.and_return(transaction)
|
42
|
+
transaction.should_receive(:postprocess).once
|
43
|
+
transaction.should_receive(:error=).never
|
44
|
+
transaction.should_receive(:odba_store).once
|
42
45
|
transaction.should_receive(:notify).once
|
43
46
|
assert_equal([], @app.transactions)
|
44
47
|
assert_equal(0, @app.transactions.size)
|
@@ -55,6 +58,9 @@ module XmlConv
|
|
55
58
|
ODBA.cache = cache
|
56
59
|
transaction.should_receive(:transaction_id=).with(1)
|
57
60
|
transaction.should_receive(:execute).once.and_raise(Net::SMTPFatalError, 'could not send email')
|
61
|
+
transaction.should_receive(:postprocess).never
|
62
|
+
transaction.should_receive(:error=).never
|
63
|
+
transaction.should_receive(:odba_store).once
|
58
64
|
assert_equal([], @app.transactions)
|
59
65
|
assert_equal(0, @app.transactions.size)
|
60
66
|
@app.execute(transaction)
|
@@ -70,8 +76,10 @@ module XmlConv
|
|
70
76
|
ODBA.cache = cache
|
71
77
|
transaction.should_receive(:transaction_id=).with(1)
|
72
78
|
transaction.should_receive(:execute).and_raise 'oops, something went wrong'
|
73
|
-
transaction.should_receive(:
|
74
|
-
transaction.should_receive(:
|
79
|
+
transaction.should_receive(:postprocess).never
|
80
|
+
transaction.should_receive(:error=).once
|
81
|
+
transaction.should_receive(:odba_store).once
|
82
|
+
transaction.should_receive(:notify).once
|
75
83
|
assert_equal([], @app.transactions)
|
76
84
|
assert_equal(0, @app.transactions.size)
|
77
85
|
@app.execute(transaction)
|
@@ -80,7 +88,7 @@ module XmlConv
|
|
80
88
|
ODBA.cache = nil
|
81
89
|
end
|
82
90
|
def test_dumpable
|
83
|
-
Marshal.dump(@app)
|
91
|
+
assert_raises(TypeError) { Marshal.dump(@app) }
|
84
92
|
end
|
85
93
|
def test_next_transaction_id
|
86
94
|
assert_equal([], @app.transactions)
|
@@ -98,7 +106,7 @@ module XmlConv
|
|
98
106
|
end
|
99
107
|
def test_odba_exclude_vars
|
100
108
|
@app.instance_variable_set('@next_transaction_id', 10)
|
101
|
-
@app.instance_eval('odba_replace_excluded!')
|
109
|
+
@app.instance_eval('odba_replace_excluded!')
|
102
110
|
assert_nil(@app.instance_variable_get('@next_transaction_id'))
|
103
111
|
end
|
104
112
|
def test_transaction
|
@@ -12,6 +12,10 @@ require 'flexmock/minitest'
|
|
12
12
|
|
13
13
|
module XmlConv
|
14
14
|
module Util
|
15
|
+
class DestinationMail
|
16
|
+
def odba_store
|
17
|
+
end
|
18
|
+
end
|
15
19
|
class TestDestination < ::Minitest::Test
|
16
20
|
def setup
|
17
21
|
@destination = Destination.new
|
@@ -28,7 +32,7 @@ module XmlConv
|
|
28
32
|
end
|
29
33
|
def test_deliver__destination
|
30
34
|
delivery = flexmock('Delivery')
|
31
|
-
assert_raises(RuntimeError) {
|
35
|
+
assert_raises(RuntimeError) {
|
32
36
|
@destination.deliver(delivery)
|
33
37
|
}
|
34
38
|
end
|
@@ -37,16 +41,16 @@ module XmlConv
|
|
37
41
|
end
|
38
42
|
def test_book
|
39
43
|
assert_instance_of(DestinationDir, Destination.book('/'))
|
40
|
-
assert_instance_of(DestinationHttp,
|
44
|
+
assert_instance_of(DestinationHttp,
|
41
45
|
Destination.book('http://www.example.com'))
|
42
|
-
assert_instance_of(DestinationFtp,
|
46
|
+
assert_instance_of(DestinationFtp,
|
43
47
|
Destination.book('ftp://www.example.com'))
|
44
48
|
end
|
45
49
|
end
|
46
50
|
class TestDestinationDir < ::Minitest::Test
|
47
51
|
def setup
|
48
52
|
@destination = DestinationDir.new
|
49
|
-
@target_dir = File.expand_path('data/destination',
|
53
|
+
@target_dir = File.expand_path('data/destination',
|
50
54
|
File.dirname(__FILE__))
|
51
55
|
super
|
52
56
|
end
|
@@ -141,6 +145,21 @@ module XmlConv
|
|
141
145
|
assert_respond_to(@destination, :host=)
|
142
146
|
end
|
143
147
|
end
|
148
|
+
class TestDestinationMail< ::Minitest::Test
|
149
|
+
def setup
|
150
|
+
@destination = DestinationMail.new
|
151
|
+
::Mail.defaults do delivery_method :test end
|
152
|
+
::Mail::TestMailer.deliveries.clear
|
153
|
+
super
|
154
|
+
end
|
155
|
+
def test_destination_mail
|
156
|
+
default_dest = 'mailto:noone@nowhere.org'
|
157
|
+
test_recicpient = 'test@other.org'
|
158
|
+
assert_equal(default_dest, @destination.uri.to_s)
|
159
|
+
@destination.deliver('body as text')
|
160
|
+
assert_equal(1, ::Mail::TestMailer.deliveries.length)
|
161
|
+
end
|
162
|
+
end
|
144
163
|
class TestDestinationHttp < ::Minitest::Test
|
145
164
|
def setup
|
146
165
|
@destination = DestinationHttp.new
|
@@ -175,15 +194,15 @@ module XmlConv
|
|
175
194
|
response = flexmock('Response')
|
176
195
|
response.should_receive(:message).and_return { 'Status' }
|
177
196
|
delivery.should_receive(:to_s).and_return { 'The Delivery' }
|
178
|
-
http_session.should_receive(:request).and_return { |post_request, body|
|
197
|
+
http_session.should_receive(:request).and_return { |post_request, body|
|
179
198
|
assert_instance_of(Net::HTTP::Post, post_request)
|
180
|
-
header = post_request.instance_variable_get('@header')
|
199
|
+
header = post_request.instance_variable_get('@header')
|
181
200
|
assert_equal(['text/xml'], header['content-type'])
|
182
201
|
assert(header.include?('authorization'), "Authorization-Headers not sent")
|
183
202
|
assert_equal('The Delivery', body)
|
184
203
|
response
|
185
204
|
}
|
186
|
-
@transport.should_receive(:start).and_return { |host, port, block|
|
205
|
+
@transport.should_receive(:start).and_return { |host, port, block|
|
187
206
|
assert_equal('xmlconv.ywesee.com', host)
|
188
207
|
assert_equal(12345, port)
|
189
208
|
block.call(http_session)
|
@@ -203,9 +222,14 @@ module XmlConv
|
|
203
222
|
@destination.transport = @transport = flexmock('DestinationFtp::FTP_CLASS')
|
204
223
|
super
|
205
224
|
end
|
206
|
-
def
|
225
|
+
def test_path_absolute_writer
|
207
226
|
assert_equal('ftp:/', @destination.uri.to_s)
|
208
227
|
@destination.path = '/foo/bar'
|
228
|
+
assert_equal('ftp:/%2Ffoo/bar', @destination.uri.to_s)
|
229
|
+
end
|
230
|
+
def test_path_relative_writer
|
231
|
+
assert_equal('ftp:/', @destination.uri.to_s)
|
232
|
+
@destination.path = 'foo/bar'
|
209
233
|
assert_equal('ftp:/foo/bar', @destination.uri.to_s)
|
210
234
|
end
|
211
235
|
def test_host_writer
|
@@ -231,13 +255,13 @@ module XmlConv
|
|
231
255
|
delivery.should_receive(:to_s).and_return { 'The Delivery' }
|
232
256
|
delivery.should_receive(:filename).and_return { 'test.dat' }
|
233
257
|
ftp_session.should_receive(:chdir).and_return { |path|
|
234
|
-
assert_equal('
|
258
|
+
assert_equal('foo/bar/', path)
|
235
259
|
}
|
236
260
|
ftp_session.should_receive(:puttextfile).and_return { |local, remote|
|
237
261
|
assert_equal("The Delivery\n", File.read(local))
|
238
262
|
assert_equal('test.dat', remote)
|
239
263
|
}
|
240
|
-
@transport.should_receive(:open).and_return { |host, user, password, block|
|
264
|
+
@transport.should_receive(:open).and_return { |host, user, password, block|
|
241
265
|
assert_equal('xmlconv.ywesee.com', host)
|
242
266
|
assert_equal('testaccount', user)
|
243
267
|
assert_equal('password', password)
|
@@ -262,13 +286,13 @@ module XmlConv
|
|
262
286
|
ftp_session.should_receive(:chdir).and_return { |path|
|
263
287
|
assert_equal('foo/bar/', path)
|
264
288
|
}
|
265
|
-
expecteds = %w{
|
289
|
+
expecteds = %w{test.dat test.dat}
|
266
290
|
ftp_session.should_receive(:puttextfile).times(2)\
|
267
291
|
.and_return { |local, remote|
|
268
292
|
assert_equal("The Delivery\n", File.read(local))
|
269
293
|
assert_equal(expecteds.shift, remote)
|
270
294
|
}
|
271
|
-
@transport.should_receive(:open).and_return { |host, user, password, block|
|
295
|
+
@transport.should_receive(:open).and_return { |host, user, password, block|
|
272
296
|
assert_equal('xmlconv.ywesee.com', host)
|
273
297
|
assert_equal('testaccount', user)
|
274
298
|
assert_equal('password', password)
|
@@ -297,7 +321,7 @@ module XmlConv
|
|
297
321
|
assert_equal('/foo/tmp/test.dat', remote)
|
298
322
|
}
|
299
323
|
ftp_session.should_receive(:rename).with('/foo/tmp/test.dat', 'test.dat').times(1)
|
300
|
-
@transport.should_receive(:open).and_return { |host, user, password, block|
|
324
|
+
@transport.should_receive(:open).and_return { |host, user, password, block|
|
301
325
|
assert_equal('xmlconv.ywesee.com', host)
|
302
326
|
assert_equal('testaccount', user)
|
303
327
|
assert_equal('password', password)
|
@@ -349,7 +373,7 @@ module XmlConv
|
|
349
373
|
delivery.should_receive(:to_s).and_return { 'The Delivery' }
|
350
374
|
delivery.should_receive(:filename).and_return { 'test.dat' }
|
351
375
|
file_handle = StringIO.new('')
|
352
|
-
@transport.should_receive(:start).and_return { |host, user, opts, block|
|
376
|
+
@transport.should_receive(:start).and_return { |host, user, opts, block|
|
353
377
|
assert_equal('xmlconv.ywesee.com', host)
|
354
378
|
assert_equal('testaccount', user)
|
355
379
|
assert_equal([], opts[:keys])
|
@@ -380,7 +404,7 @@ module XmlConv
|
|
380
404
|
delivery.should_receive(:to_s).and_return { 'The Delivery' }
|
381
405
|
delivery.should_receive(:filename).and_return { 'test.dat' }
|
382
406
|
file_handle = StringIO.new('')
|
383
|
-
@transport.should_receive(:start).and_return { |host, user, opts, block|
|
407
|
+
@transport.should_receive(:start).and_return { |host, user, opts, block|
|
384
408
|
assert_equal('xmlconv.ywesee.com', host)
|
385
409
|
assert_equal('testaccount', user)
|
386
410
|
assert_equal([], opts[:keys])
|
@@ -18,14 +18,14 @@ module XmlConv
|
|
18
18
|
class TestPollingMission < ::Minitest::Test
|
19
19
|
def setup
|
20
20
|
@mission = PollingMission.new
|
21
|
-
@dir = File.expand_path('data/i2',
|
21
|
+
@dir = File.expand_path('data/i2',
|
22
22
|
File.dirname(__FILE__))
|
23
23
|
FileUtils.mkdir_p(@dir)
|
24
24
|
@file1 = File.expand_path('file1.txt', @dir)
|
25
25
|
File.open(@file1, 'w') { |fh| fh << "File 1\n" }
|
26
26
|
end
|
27
27
|
def teardown
|
28
|
-
FileUtils.rm_rf(@dir)
|
28
|
+
FileUtils.rm_rf(@dir)
|
29
29
|
end
|
30
30
|
def test_file_paths
|
31
31
|
@mission.directory = @dir
|
@@ -100,15 +100,17 @@ module XmlConv
|
|
100
100
|
end
|
101
101
|
class TestPopMission < ::Minitest::Test
|
102
102
|
def setup
|
103
|
+
::Mail::TestMailer.deliveries.clear
|
104
|
+
::Mail.defaults do delivery_method :test end
|
103
105
|
@popserver = TCPServer.new('127.0.0.1', 0)
|
104
|
-
addr = @popserver.addr
|
106
|
+
addr = @popserver.addr
|
105
107
|
@mission = PopMission.new
|
106
108
|
@mission.host = 'localhost'
|
107
109
|
@mission.port = addr.at(1)
|
108
110
|
@mission.user = "testuser"
|
109
111
|
@mission.pass = "test"
|
110
112
|
@mission.content_type = "text/xml"
|
111
|
-
@datadir = File.expand_path('data', File.dirname(__FILE__))
|
113
|
+
@datadir = File.expand_path('data', File.dirname(__FILE__))
|
112
114
|
@mission.backup_dir = File.join(@datadir, 'backup')
|
113
115
|
@mission.destination = File.join(@datadir, 'destination')
|
114
116
|
@mission.partner = 'Partner'
|
@@ -159,14 +161,14 @@ module XmlConv
|
|
159
161
|
def setup
|
160
162
|
@sys = flexmock('System')
|
161
163
|
@polling = PollingManager.new(@sys)
|
162
|
-
@dir = File.expand_path('data/i2',
|
164
|
+
@dir = File.expand_path('data/i2',
|
163
165
|
File.dirname(__FILE__))
|
164
166
|
FileUtils.mkdir_p(@dir)
|
165
167
|
@file1 = File.expand_path('file1.txt', @dir)
|
166
168
|
File.open(@file1, 'w') { |fh| fh << "File 1\n" }
|
167
169
|
end
|
168
170
|
def teardown
|
169
|
-
FileUtils.rm_rf(@dir)
|
171
|
+
FileUtils.rm_rf(@dir)
|
170
172
|
@sys.__verify
|
171
173
|
super
|
172
174
|
end
|
@@ -186,7 +188,7 @@ reader: XmlBdd
|
|
186
188
|
EOS
|
187
189
|
}
|
188
190
|
block = nil
|
189
|
-
block3 = Proc.new { |source|
|
191
|
+
block3 = Proc.new { |source|
|
190
192
|
flunk "too many sources"
|
191
193
|
}
|
192
194
|
block2 = Proc.new { |source|
|
@@ -49,18 +49,17 @@ module XmlConv
|
|
49
49
|
assert_respond_to(@transaction, :commit_time)
|
50
50
|
end
|
51
51
|
def test_execute
|
52
|
-
src = flexmock('source')
|
53
52
|
input = flexmock('input')
|
54
53
|
reader = flexmock('reader')
|
55
54
|
model = flexmock('model')
|
56
55
|
writer = flexmock('writer')
|
57
56
|
output = flexmock('output')
|
58
57
|
destination = flexmock('destination')
|
59
|
-
@transaction.input =
|
58
|
+
@transaction.input = 'abc'
|
60
59
|
@transaction.reader = reader
|
61
60
|
@transaction.writer = writer
|
62
61
|
@transaction.destination = destination
|
63
|
-
reader.should_receive(:parse).
|
62
|
+
reader.should_receive(:parse).and_return(input)
|
64
63
|
reader.should_receive(:convert).with(input).once.and_return(model)
|
65
64
|
writer.should_receive(:convert).with(model).once.and_return(output)
|
66
65
|
destination.should_receive(:deliver).with(output).once
|
@@ -68,7 +67,7 @@ module XmlConv
|
|
68
67
|
time1 = Time.now
|
69
68
|
result = @transaction.execute
|
70
69
|
time2 = Time.now
|
71
|
-
assert_equal(
|
70
|
+
assert_equal('abc', @transaction.input)
|
72
71
|
assert_equal(reader, @transaction.reader)
|
73
72
|
assert_equal(model, @transaction.model)
|
74
73
|
assert_equal(writer, @transaction.writer)
|
@@ -84,22 +83,22 @@ module XmlConv
|
|
84
83
|
Marshal.dump(@transaction)
|
85
84
|
end
|
86
85
|
def test_notify
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
86
|
+
::Mail::TestMailer.deliveries.clear
|
87
|
+
::Mail.defaults do delivery_method :test end
|
88
|
+
to_addr = 'foo@bar.com'
|
89
|
+
XmlConv::CONFIG.mail_from = 'from@some.com'
|
91
90
|
@transaction.instance_variable_set('@start_time', Time.now)
|
92
91
|
@transaction.error_recipients = ['bar']
|
93
92
|
@transaction.notify
|
94
93
|
assert_equal(0, ::Mail::TestMailer.deliveries.size)
|
95
|
-
@transaction.debug_recipients = [
|
94
|
+
@transaction.debug_recipients = [to_addr]
|
96
95
|
@transaction.notify
|
97
96
|
assert_equal(1, ::Mail::TestMailer.deliveries.size)
|
98
|
-
assert_equal([
|
97
|
+
assert_equal([to_addr], ::Mail::TestMailer.deliveries.last.to)
|
99
98
|
@transaction.error = 'error!'
|
100
99
|
@transaction.notify
|
101
100
|
assert_equal(2, ::Mail::TestMailer.deliveries.size)
|
102
|
-
assert_equal([
|
101
|
+
assert_equal([to_addr, 'bar'], ::Mail::TestMailer.deliveries.last.to)
|
103
102
|
end
|
104
103
|
end
|
105
104
|
end
|
data/xmlconv.gemspec
CHANGED
@@ -21,20 +21,11 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_dependency "ydbd-pg", '>= 0.5.1'
|
22
22
|
spec.add_dependency "ydbi", '>= 0.5.1'
|
23
23
|
spec.add_dependency "json"
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
spec.add_dependency "ydim", '1.0.0'
|
30
|
-
spec.add_dependency "hpricot", '0.8.2'
|
31
|
-
else
|
32
|
-
spec.add_dependency "sbsm"
|
33
|
-
spec.add_dependency "htmlgrid"
|
34
|
-
spec.add_dependency "ydim"
|
35
|
-
spec.add_dependency "syck"
|
36
|
-
spec.add_dependency "mail" # avoid it to make it run
|
37
|
-
end
|
24
|
+
spec.add_dependency "sbsm", '>= 1.4.3'
|
25
|
+
spec.add_dependency "htmlgrid"
|
26
|
+
spec.add_dependency "ydim"
|
27
|
+
spec.add_dependency "syck"
|
28
|
+
spec.add_dependency "mail"
|
38
29
|
spec.add_dependency "rclconf"
|
39
30
|
spec.add_dependency "needle"
|
40
31
|
spec.add_dependency "ypdf-writer"
|
@@ -43,13 +34,11 @@ Gem::Specification.new do |spec|
|
|
43
34
|
spec.add_runtime_dependency "yus"
|
44
35
|
|
45
36
|
spec.add_development_dependency "bundler"
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
spec.add_development_dependency "rspec"
|
53
|
-
end
|
37
|
+
spec.add_development_dependency "simplecov"
|
38
|
+
spec.add_development_dependency "rake"
|
39
|
+
spec.add_development_dependency "flexmock"
|
40
|
+
spec.add_development_dependency "minitest"
|
41
|
+
spec.add_development_dependency "minitest-should_syntax"
|
42
|
+
spec.add_development_dependency "rspec"
|
54
43
|
end
|
55
44
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xmlconv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masaomi Hatakeyama, Zeno R.R. Davatz, Niklaus Giger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: odba
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 1.4.3
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 1.4.3
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: htmlgrid
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -314,6 +314,7 @@ extensions: []
|
|
314
314
|
extra_rdoc_files: []
|
315
315
|
files:
|
316
316
|
- ".gitignore"
|
317
|
+
- ".travis.yml"
|
317
318
|
- Gemfile
|
318
319
|
- History.txt
|
319
320
|
- LICENSE
|
@@ -434,7 +435,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
434
435
|
version: '0'
|
435
436
|
requirements: []
|
436
437
|
rubyforge_project:
|
437
|
-
rubygems_version: 2.
|
438
|
+
rubygems_version: 2.6.8
|
438
439
|
signing_key:
|
439
440
|
specification_version: 4
|
440
441
|
summary: xmlconverter, convert XML to flat files
|
@@ -469,4 +470,3 @@ test_files:
|
|
469
470
|
- test/test_util/invoicer.rb
|
470
471
|
- test/test_util/polling_manager.rb
|
471
472
|
- test/test_util/transaction.rb
|
472
|
-
has_rdoc:
|