bbmb 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/LICENSE.txt +339 -0
- data/Manifest.txt +91 -0
- data/README.txt +25 -0
- data/Rakefile +28 -0
- data/bin/admin +71 -0
- data/bin/bbmbd +61 -0
- data/lib/bbmb.rb +9 -0
- data/lib/bbmb/config.rb +106 -0
- data/lib/bbmb/html/state/change_password.rb +50 -0
- data/lib/bbmb/html/state/current_order.rb +81 -0
- data/lib/bbmb/html/state/customer.rb +109 -0
- data/lib/bbmb/html/state/customers.rb +52 -0
- data/lib/bbmb/html/state/favorites.rb +19 -0
- data/lib/bbmb/html/state/favorites_result.rb +21 -0
- data/lib/bbmb/html/state/global.rb +62 -0
- data/lib/bbmb/html/state/history.rb +95 -0
- data/lib/bbmb/html/state/info.rb +23 -0
- data/lib/bbmb/html/state/json.rb +16 -0
- data/lib/bbmb/html/state/login.rb +76 -0
- data/lib/bbmb/html/state/order.rb +21 -0
- data/lib/bbmb/html/state/orders.rb +19 -0
- data/lib/bbmb/html/state/result.rb +64 -0
- data/lib/bbmb/html/state/show_pass.rb +16 -0
- data/lib/bbmb/html/state/viral/admin.rb +41 -0
- data/lib/bbmb/html/state/viral/customer.rb +143 -0
- data/lib/bbmb/html/util/known_user.rb +51 -0
- data/lib/bbmb/html/util/multilingual.rb +18 -0
- data/lib/bbmb/html/util/session.rb +52 -0
- data/lib/bbmb/html/util/validator.rb +55 -0
- data/lib/bbmb/html/view/backorder.rb +24 -0
- data/lib/bbmb/html/view/change_password.rb +42 -0
- data/lib/bbmb/html/view/copyleft.rb +41 -0
- data/lib/bbmb/html/view/current_order.rb +482 -0
- data/lib/bbmb/html/view/customer.rb +152 -0
- data/lib/bbmb/html/view/customers.rb +145 -0
- data/lib/bbmb/html/view/favorites.rb +162 -0
- data/lib/bbmb/html/view/favorites_result.rb +26 -0
- data/lib/bbmb/html/view/foot.rb +21 -0
- data/lib/bbmb/html/view/head.rb +32 -0
- data/lib/bbmb/html/view/history.rb +60 -0
- data/lib/bbmb/html/view/info.rb +33 -0
- data/lib/bbmb/html/view/json.rb +20 -0
- data/lib/bbmb/html/view/list_prices.rb +51 -0
- data/lib/bbmb/html/view/login.rb +46 -0
- data/lib/bbmb/html/view/multilingual.rb +17 -0
- data/lib/bbmb/html/view/navigation.rb +30 -0
- data/lib/bbmb/html/view/order.rb +123 -0
- data/lib/bbmb/html/view/orders.rb +50 -0
- data/lib/bbmb/html/view/result.rb +107 -0
- data/lib/bbmb/html/view/search.rb +28 -0
- data/lib/bbmb/html/view/show_pass.rb +60 -0
- data/lib/bbmb/html/view/template.rb +61 -0
- data/lib/bbmb/model/customer.rb +96 -0
- data/lib/bbmb/model/order.rb +255 -0
- data/lib/bbmb/model/product.rb +99 -0
- data/lib/bbmb/model/promotion.rb +52 -0
- data/lib/bbmb/model/quota.rb +27 -0
- data/lib/bbmb/model/subject.rb +46 -0
- data/lib/bbmb/persistence/none.rb +6 -0
- data/lib/bbmb/persistence/odba.rb +42 -0
- data/lib/bbmb/persistence/odba/model/customer.rb +47 -0
- data/lib/bbmb/persistence/odba/model/order.rb +50 -0
- data/lib/bbmb/persistence/odba/model/product.rb +26 -0
- data/lib/bbmb/persistence/odba/model/quota.rb +12 -0
- data/lib/bbmb/util/invoicer.rb +126 -0
- data/lib/bbmb/util/mail.rb +140 -0
- data/lib/bbmb/util/multilingual.rb +57 -0
- data/lib/bbmb/util/numbers.rb +67 -0
- data/lib/bbmb/util/password_generator.rb +44 -0
- data/lib/bbmb/util/polling_manager.rb +135 -0
- data/lib/bbmb/util/server.rb +159 -0
- data/lib/bbmb/util/target_dir.rb +36 -0
- data/lib/bbmb/util/transfer_dat.rb +34 -0
- data/lib/bbmb/util/updater.rb +27 -0
- data/test/data/ydim.yml +2 -0
- data/test/model/test_customer.rb +75 -0
- data/test/model/test_order.rb +426 -0
- data/test/model/test_product.rb +238 -0
- data/test/model/test_promotion.rb +40 -0
- data/test/stub/persistence.rb +57 -0
- data/test/suite.rb +12 -0
- data/test/test_bbmb.rb +18 -0
- data/test/util/test_invoicer.rb +189 -0
- data/test/util/test_mail.rb +359 -0
- data/test/util/test_money.rb +71 -0
- data/test/util/test_password_generator.rb +27 -0
- data/test/util/test_polling_manager.rb +312 -0
- data/test/util/test_server.rb +189 -0
- data/test/util/test_target_dir.rb +82 -0
- data/test/util/test_transfer_dat.rb +45 -0
- metadata +190 -0
@@ -0,0 +1,312 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Util::TestPollingManager -- bbmb.ch -- 14.09.2006 -- hwyss@ywesee.com
|
3
|
+
|
4
|
+
$: << File.expand_path('../../lib', File.dirname(__FILE__))
|
5
|
+
|
6
|
+
require 'test/unit'
|
7
|
+
require 'flexmock'
|
8
|
+
require 'bbmb/util/polling_manager'
|
9
|
+
require 'fileutils'
|
10
|
+
|
11
|
+
module BBMB
|
12
|
+
module Util
|
13
|
+
class TestFileMission < Test::Unit::TestCase
|
14
|
+
include FlexMock::TestCase
|
15
|
+
def setup
|
16
|
+
@datadir = File.expand_path('../data', File.dirname(__FILE__))
|
17
|
+
BBMB.config = flexmock('config')
|
18
|
+
BBMB.config.should_receive(:bbmb_dir).and_return(@datadir)
|
19
|
+
@mission = FileMission.new
|
20
|
+
@dir = File.expand_path('../data/poll', File.dirname(__FILE__))
|
21
|
+
FileUtils.mkdir_p(@dir)
|
22
|
+
@mission.directory = @dir
|
23
|
+
end
|
24
|
+
def test_poll
|
25
|
+
path = File.join(@dir, 'test.csv')
|
26
|
+
File.open(path, 'w') { |fh| fh.puts 'data' }
|
27
|
+
@mission.poll { |name, io|
|
28
|
+
assert_equal('test.csv', name)
|
29
|
+
assert_equal("data\n", io.read)
|
30
|
+
}
|
31
|
+
assert_equal(true, File.exist?(path))
|
32
|
+
|
33
|
+
@mission.glob_pattern = '*.xls'
|
34
|
+
@mission.poll { |name, io|
|
35
|
+
flunk "glob_pattern *.xls should not match any files, matched #{name}"
|
36
|
+
}
|
37
|
+
|
38
|
+
@mission.glob_pattern = '*.csv'
|
39
|
+
@mission.poll { |name, io|
|
40
|
+
assert_equal('test.csv', name)
|
41
|
+
assert_equal("data\n", io.read)
|
42
|
+
}
|
43
|
+
end
|
44
|
+
def test_poll_path
|
45
|
+
path = File.join(@dir, 'test.csv')
|
46
|
+
File.open(path, 'w') { |fh| fh.puts 'data' }
|
47
|
+
@mission.poll_path(path) { |name, io|
|
48
|
+
assert_equal('test.csv', name)
|
49
|
+
assert_equal("data\n", io.read)
|
50
|
+
}
|
51
|
+
assert_equal(true, File.exist?(path))
|
52
|
+
end
|
53
|
+
def test_poll_path__delete
|
54
|
+
path = File.join(@dir, 'test.csv')
|
55
|
+
File.open(path, 'w') { |fh| fh.puts 'data' }
|
56
|
+
@mission.delete = true
|
57
|
+
@mission.poll_path(path) { |name, io|
|
58
|
+
assert_equal('test.csv', name)
|
59
|
+
assert_equal("data\n", io.read)
|
60
|
+
}
|
61
|
+
assert_equal(false, File.exist?(path))
|
62
|
+
end
|
63
|
+
def test_poll_path__backup
|
64
|
+
path = File.join(@dir, 'test.csv')
|
65
|
+
File.open(path, 'w') { |fh| fh.puts 'data' }
|
66
|
+
bdir = @mission.backup_dir = File.expand_path('../backup', @dir)
|
67
|
+
bpath = File.join(bdir, 'test.csv')
|
68
|
+
@mission.poll_path(path) { |name, io|
|
69
|
+
assert_equal('test.csv', name)
|
70
|
+
assert_equal("data\n", io.read)
|
71
|
+
}
|
72
|
+
assert_equal(true, File.exist?(path))
|
73
|
+
assert_equal(true, File.exist?(bpath))
|
74
|
+
assert_equal("data\n", File.read(bpath))
|
75
|
+
end
|
76
|
+
def test_poll_path__backup__error
|
77
|
+
path = File.join(@dir, 'test.csv')
|
78
|
+
File.open(path, 'w') { |fh| fh.puts 'data' }
|
79
|
+
bdir = @mission.backup_dir = File.expand_path('../backup', @dir)
|
80
|
+
bpath = File.join(bdir, 'test.csv')
|
81
|
+
flexstub(BBMB::Util::Mail).should_receive(:notify_error).times(1)
|
82
|
+
@mission.poll_path(path) { |name, io|
|
83
|
+
assert_equal('test.csv', name)
|
84
|
+
assert_equal("data\n", io.read)
|
85
|
+
raise "some error"
|
86
|
+
}
|
87
|
+
assert_equal(true, File.exist?(path))
|
88
|
+
assert_equal(true, File.exist?(bpath))
|
89
|
+
assert_equal("data\n", File.read(bpath))
|
90
|
+
end
|
91
|
+
end
|
92
|
+
class TestFtpMission < Test::Unit::TestCase
|
93
|
+
include FlexMock::TestCase
|
94
|
+
def setup
|
95
|
+
@datadir = File.expand_path('../data', File.dirname(__FILE__))
|
96
|
+
BBMB.config = flexmock('config')
|
97
|
+
BBMB.config.should_receive(:bbmb_dir).and_return(@datadir)
|
98
|
+
@mission = FtpMission.new
|
99
|
+
@mission.directory = "ftp://user:pass@ftp.server.com/path/to/dir"
|
100
|
+
end
|
101
|
+
def test_poll
|
102
|
+
session = flexmock 'ftp'
|
103
|
+
session.should_receive(:login).with('user', 'pass').times(2)
|
104
|
+
session.should_receive(:chdir).with('/path/to/dir').times(2)
|
105
|
+
session.should_receive(:nlst).and_return %w{test.csv test.txt}
|
106
|
+
session.should_receive(:get).and_return { |remote, local|
|
107
|
+
assert_equal('test.txt', remote)
|
108
|
+
File.open(local, 'w') { |fh| fh.puts "data" }
|
109
|
+
}
|
110
|
+
flexmock(Net::FTP).should_receive(:open).and_return { |host, block|
|
111
|
+
assert_equal('ftp.server.com', host)
|
112
|
+
block.call session
|
113
|
+
}
|
114
|
+
@mission.pattern = '.*\.txt'
|
115
|
+
@mission.poll { |name, io|
|
116
|
+
assert_equal('test.txt', name)
|
117
|
+
assert_equal("data\n", io.read)
|
118
|
+
}
|
119
|
+
|
120
|
+
@mission.pattern = '.*\.xls'
|
121
|
+
@mission.poll { |name, io|
|
122
|
+
flunk "pattern .*\.xls should not match any files, matched #{name}"
|
123
|
+
}
|
124
|
+
end
|
125
|
+
def test_poll_remote
|
126
|
+
@mission.backup_dir = '/backup/dir'
|
127
|
+
session = flexmock 'ftp'
|
128
|
+
session.should_receive(:get).and_return { |remote, local|
|
129
|
+
assert_equal('test.txt', remote)
|
130
|
+
assert_equal('/backup/dir/test.txt', local)
|
131
|
+
}
|
132
|
+
assert_equal('/backup/dir/test.txt',
|
133
|
+
@mission.poll_remote(session, 'test.txt'))
|
134
|
+
end
|
135
|
+
def test_poll_remote__delete
|
136
|
+
@mission.backup_dir = '/backup/dir'
|
137
|
+
@mission.delete = true
|
138
|
+
session = flexmock 'ftp'
|
139
|
+
session.should_receive(:get).and_return { |remote, local|
|
140
|
+
assert_equal('test.txt', remote)
|
141
|
+
assert_equal('/backup/dir/test.txt', local)
|
142
|
+
}
|
143
|
+
session.should_receive(:delete).with('test.txt').times(1)
|
144
|
+
assert_equal('/backup/dir/test.txt',
|
145
|
+
@mission.poll_remote(session, 'test.txt'))
|
146
|
+
end
|
147
|
+
end
|
148
|
+
class TestPopMission < Test::Unit::TestCase
|
149
|
+
include FlexMock::TestCase
|
150
|
+
def setup
|
151
|
+
@mission = PopMission.new
|
152
|
+
@mission.host = "mail.ywesee.com"
|
153
|
+
@mission.user = "data@bbmb.ch"
|
154
|
+
@mission.pass = "test"
|
155
|
+
end
|
156
|
+
def test_poll_message__normal
|
157
|
+
message = RMail::Message.new
|
158
|
+
part1 = RMail::Message.new
|
159
|
+
part1.body = "inline text"
|
160
|
+
message.add_part(part1)
|
161
|
+
part2 = RMail::Message.new
|
162
|
+
part2.body = "attached data"
|
163
|
+
part2.header.add("Content-Type",'TEXT/plain', nil,
|
164
|
+
'NAME' => "=?ISO-8859-1?Q?ywsarti.csv?=")
|
165
|
+
message.add_part(part2)
|
166
|
+
blk_called = false
|
167
|
+
@mission.poll_message(message) { |filename, data|
|
168
|
+
assert_equal('ywsarti.csv', filename)
|
169
|
+
assert_equal('attached data', data)
|
170
|
+
blk_called = true
|
171
|
+
}
|
172
|
+
assert(blk_called, "poll_message never called its block")
|
173
|
+
end
|
174
|
+
def test_poll_message__many_parameters
|
175
|
+
message = RMail::Message.new
|
176
|
+
part1 = RMail::Message.new
|
177
|
+
part1.body = "inline text"
|
178
|
+
message.add_part(part1)
|
179
|
+
part2 = RMail::Message.new
|
180
|
+
part2.body = "attached data"
|
181
|
+
part2.header.add("Content-Type",'TEXT/plain', nil,
|
182
|
+
[['NAME', "ywsarti.csv"], ["foo", "b.r"]])
|
183
|
+
message.add_part(part2)
|
184
|
+
blk_called = false
|
185
|
+
@mission.poll_message(message) { |filename, data|
|
186
|
+
assert_equal('ywsarti.csv', filename)
|
187
|
+
assert_equal('attached data', data)
|
188
|
+
blk_called = true
|
189
|
+
}
|
190
|
+
assert(blk_called, "poll_message never called its block")
|
191
|
+
end
|
192
|
+
def test_poll_message__no_quotes
|
193
|
+
message = RMail::Message.new
|
194
|
+
part1 = RMail::Message.new
|
195
|
+
part1.body = "inline text"
|
196
|
+
message.add_part(part1)
|
197
|
+
part2 = RMail::Message.new
|
198
|
+
part2.body = "attached data"
|
199
|
+
part2.header.add("Content-Type",'text/plain', nil,
|
200
|
+
[['filename', "ywsarti"], ["foo", "bar"]])
|
201
|
+
message.add_part(part2)
|
202
|
+
blk_called = false
|
203
|
+
@mission.poll_message(message) { |filename, data|
|
204
|
+
assert_equal('ywsarti', filename)
|
205
|
+
assert_equal('attached data', data)
|
206
|
+
blk_called = true
|
207
|
+
}
|
208
|
+
assert(blk_called, "poll_message never called its block")
|
209
|
+
end
|
210
|
+
def test_poll
|
211
|
+
src = <<-EOS
|
212
|
+
Content-Type: multipart/mixed; boundary="=-1158308026-727155-3822-1761-1-="
|
213
|
+
MIME-Version: 1.0
|
214
|
+
|
215
|
+
|
216
|
+
--=-1158308026-727155-3822-1761-1-=
|
217
|
+
|
218
|
+
inline text
|
219
|
+
--=-1158308026-727155-3822-1761-1-=
|
220
|
+
Content-Disposition: attachment; filename="ywsarti.csv"
|
221
|
+
|
222
|
+
attached data
|
223
|
+
--=-1158308026-727155-3822-1761-1-=--
|
224
|
+
EOS
|
225
|
+
flexstub(Net::POP3).should_receive(:start).with('mail.ywesee.com', 110,
|
226
|
+
'data@bbmb.ch',
|
227
|
+
'test', Proc).and_return { |host, port, user, pass, block|
|
228
|
+
pop = flexmock('pop')
|
229
|
+
pop.should_receive(:each_mail).and_return { |block2|
|
230
|
+
mail = flexmock('mail')
|
231
|
+
mail.should_receive(:pop).and_return(src)
|
232
|
+
mail.should_receive(:delete)
|
233
|
+
block2.call(mail)
|
234
|
+
}
|
235
|
+
block.call(pop)
|
236
|
+
}
|
237
|
+
@mission.poll { |name, data|
|
238
|
+
assert_equal('ywsarti.csv', name)
|
239
|
+
assert_equal('attached data', data)
|
240
|
+
}
|
241
|
+
end
|
242
|
+
def test_poll__error
|
243
|
+
src = <<-EOS
|
244
|
+
Content-Type: multipart/mixed; boundary="=-1158308026-727155-3822-1761-1-="
|
245
|
+
MIME-Version: 1.0
|
246
|
+
|
247
|
+
|
248
|
+
--=-1158308026-727155-3822-1761-1-=
|
249
|
+
|
250
|
+
inline text
|
251
|
+
--=-1158308026-727155-3822-1761-1-=
|
252
|
+
Content-Type: text/csv; filename="ywsarti.csv"
|
253
|
+
|
254
|
+
attached data
|
255
|
+
--=-1158308026-727155-3822-1761-1-=--
|
256
|
+
EOS
|
257
|
+
flexstub(Net::POP3).should_receive(:start).with('mail.ywesee.com', 110,
|
258
|
+
'data@bbmb.ch',
|
259
|
+
'test', Proc).and_return { |host, port, user, pass, block|
|
260
|
+
pop = flexmock('pop')
|
261
|
+
pop.should_receive(:each_mail).and_return { |block2|
|
262
|
+
mail = flexmock('mail')
|
263
|
+
mail.should_receive(:pop).and_return(src)
|
264
|
+
mail.should_receive(:delete)
|
265
|
+
block2.call(mail)
|
266
|
+
}
|
267
|
+
block.call(pop)
|
268
|
+
}
|
269
|
+
flexstub(BBMB::Util::Mail).should_receive(:notify_error)\
|
270
|
+
.times(1).and_return { assert true }
|
271
|
+
@mission.poll { |name, data|
|
272
|
+
raise "some error"
|
273
|
+
}
|
274
|
+
end
|
275
|
+
end
|
276
|
+
class TestPollingManager < Test::Unit::TestCase
|
277
|
+
include FlexMock::TestCase
|
278
|
+
def setup
|
279
|
+
@manager = PollingManager.new
|
280
|
+
@datadir = File.expand_path('data', File.dirname(__FILE__))
|
281
|
+
end
|
282
|
+
def test_load_sources
|
283
|
+
FileUtils.mkdir_p(@datadir)
|
284
|
+
path = File.join(@datadir, 'polling.yml')
|
285
|
+
mission = PopMission.new
|
286
|
+
mission.host = "mail.ywesee.com"
|
287
|
+
mission.user = "data@bbmb.ch"
|
288
|
+
mission.pass = "test"
|
289
|
+
File.open(path, 'w') { |fh| fh.puts mission.to_yaml }
|
290
|
+
config = flexmock("config")
|
291
|
+
config.should_receive(:polling_file).and_return(path)
|
292
|
+
BBMB.config = config
|
293
|
+
@manager.load_sources { |mission|
|
294
|
+
assert_equal("mail.ywesee.com", mission.host)
|
295
|
+
assert_equal("data@bbmb.ch", mission.user)
|
296
|
+
assert_equal("test", mission.pass)
|
297
|
+
}
|
298
|
+
ensure
|
299
|
+
FileUtils.rm_r(@datadir) if(File.exist?(@datadir))
|
300
|
+
end
|
301
|
+
def test_poll_sources
|
302
|
+
flexstub(@manager).should_receive(:load_sources).and_return { |block|
|
303
|
+
source = flexmock("source")
|
304
|
+
source.should_receive(:poll)
|
305
|
+
block.call(source)
|
306
|
+
assert(true)
|
307
|
+
}
|
308
|
+
@manager.poll_sources
|
309
|
+
end
|
310
|
+
end
|
311
|
+
end
|
312
|
+
end
|
@@ -0,0 +1,189 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Util::TestServer -- bbmb.ch -- 22.09.2006 -- hwyss@ywesee.com
|
3
|
+
|
4
|
+
$: << File.expand_path('../../lib', File.dirname(__FILE__))
|
5
|
+
$: << File.expand_path('..', File.dirname(__FILE__))
|
6
|
+
|
7
|
+
require 'test/unit'
|
8
|
+
require 'bbmb'
|
9
|
+
require 'bbmb/util/server'
|
10
|
+
require 'stub/persistence'
|
11
|
+
require 'flexmock'
|
12
|
+
|
13
|
+
module BBMB
|
14
|
+
module Util
|
15
|
+
class TestServer < Test::Unit::TestCase
|
16
|
+
include FlexMock::TestCase
|
17
|
+
def setup
|
18
|
+
@server = Server.new
|
19
|
+
Model::Customer.instances.clear
|
20
|
+
Model::Product.instances.clear
|
21
|
+
end
|
22
|
+
def test_inject_order__unknown_customer
|
23
|
+
assert_raises(RuntimeError) {
|
24
|
+
@server.inject_order('12345', [], {})
|
25
|
+
}
|
26
|
+
end
|
27
|
+
def test_inject_order
|
28
|
+
pr1 = Model::Product.new 1
|
29
|
+
pr1.pcode = '1234567'
|
30
|
+
pr2 = Model::Product.new 2
|
31
|
+
pr2.ean13 = '1234567890123'
|
32
|
+
pr3 = Model::Product.new 3
|
33
|
+
pr3.ean13 = '2345678901234'
|
34
|
+
pr3.pcode = '2345678'
|
35
|
+
customer = Model::Customer.new('12345')
|
36
|
+
flexmock(customer).should_receive(:inject_order).times(1).and_return { |order|
|
37
|
+
assert_instance_of(Model::Order, order)
|
38
|
+
ps1, ps2, ps3 = order.positions
|
39
|
+
assert_instance_of(Model::Order::Position, ps1)
|
40
|
+
assert_instance_of(Model::Order::Position, ps2)
|
41
|
+
assert_instance_of(Model::Order::Position, ps3)
|
42
|
+
assert_equal(3, ps1.quantity)
|
43
|
+
assert_equal(pr1, ps1.product)
|
44
|
+
assert_equal(4, ps2.quantity)
|
45
|
+
assert_equal(pr2, ps2.product)
|
46
|
+
assert_equal(5, ps3.quantity)
|
47
|
+
assert_equal(pr3, ps3.product)
|
48
|
+
assert_equal('My Comment', order.comment)
|
49
|
+
assert_equal('76543', order.reference)
|
50
|
+
}
|
51
|
+
prods = [
|
52
|
+
{:quantity => 3, :pcode => '1234567'},
|
53
|
+
{:quantity => 4, :ean13 => '1234567890123'},
|
54
|
+
{:quantity => 5, :pcode => '2345678', :ean13 => '2345678901234'},
|
55
|
+
]
|
56
|
+
infos = {
|
57
|
+
:comment => 'My Comment',
|
58
|
+
:reference => '76543',
|
59
|
+
}
|
60
|
+
assert_nothing_raised {
|
61
|
+
@server.inject_order('12345', prods, infos)
|
62
|
+
}
|
63
|
+
end
|
64
|
+
def test_inject_order__customer_by_ean13
|
65
|
+
pr1 = Model::Product.new 1
|
66
|
+
pr1.pcode = '1234567'
|
67
|
+
pr2 = Model::Product.new 2
|
68
|
+
pr2.ean13 = '1234567890123'
|
69
|
+
pr3 = Model::Product.new 3
|
70
|
+
pr3.ean13 = '2345678901234'
|
71
|
+
pr3.pcode = '2345678'
|
72
|
+
customer = Model::Customer.new('12345')
|
73
|
+
customer.ean13 = '1234567890123'
|
74
|
+
flexmock(customer).should_receive(:inject_order).times(1).and_return { |order|
|
75
|
+
assert_instance_of(Model::Order, order)
|
76
|
+
ps1, ps2, ps3 = order.positions
|
77
|
+
assert_instance_of(Model::Order::Position, ps1)
|
78
|
+
assert_instance_of(Model::Order::Position, ps2)
|
79
|
+
assert_instance_of(Model::Order::Position, ps3)
|
80
|
+
assert_equal(3, ps1.quantity)
|
81
|
+
assert_equal(pr1, ps1.product)
|
82
|
+
assert_equal(4, ps2.quantity)
|
83
|
+
assert_equal(pr2, ps2.product)
|
84
|
+
assert_equal(5, ps3.quantity)
|
85
|
+
assert_equal(pr3, ps3.product)
|
86
|
+
assert_equal('My Comment', order.comment)
|
87
|
+
assert_equal('76543', order.reference)
|
88
|
+
}
|
89
|
+
prods = [
|
90
|
+
{:quantity => 3, :pcode => '1234567'},
|
91
|
+
{:quantity => 4, :ean13 => '1234567890123'},
|
92
|
+
{:quantity => 5, :pcode => '2345678', :ean13 => '2345678901234'},
|
93
|
+
]
|
94
|
+
infos = {
|
95
|
+
:comment => 'My Comment',
|
96
|
+
:reference => '76543',
|
97
|
+
}
|
98
|
+
flexmock(BBMB::Util::Mail).should_receive(:send_order)\
|
99
|
+
.with(BBMB::Model::Order).times(1)
|
100
|
+
flexmock(BBMB::Util::TargetDir).should_receive(:send_order)\
|
101
|
+
.with(BBMB::Model::Order).times(1)
|
102
|
+
assert_nothing_raised {
|
103
|
+
@server.inject_order('1234567890123', prods, infos, :deliver => true)
|
104
|
+
}
|
105
|
+
end
|
106
|
+
def test_rename_user__new
|
107
|
+
BBMB.config = flexmock('config')
|
108
|
+
BBMB.config.should_receive(:auth_domain).times(1).and_return('ch.bbmb')
|
109
|
+
BBMB.auth = flexmock('auth')
|
110
|
+
session = flexmock('yus-session')
|
111
|
+
BBMB.auth.should_receive(:autosession).times(1).and_return { |domain, block|
|
112
|
+
assert_equal('ch.bbmb', domain)
|
113
|
+
block.call(session)
|
114
|
+
}
|
115
|
+
session.should_receive(:create_entity).times(1).and_return { |email|
|
116
|
+
assert_equal('test@bbmb.ch', email)
|
117
|
+
}
|
118
|
+
@server.rename_user(nil, 'test@bbmb.ch')
|
119
|
+
end
|
120
|
+
def test_rename_user__existing
|
121
|
+
BBMB.config = flexmock('config')
|
122
|
+
BBMB.config.should_receive(:auth_domain).times(1).and_return('ch.bbmb')
|
123
|
+
BBMB.auth = flexmock('auth')
|
124
|
+
session = flexmock('yus-session')
|
125
|
+
BBMB.auth.should_receive(:autosession).times(1).and_return { |domain, block|
|
126
|
+
assert_equal('ch.bbmb', domain)
|
127
|
+
block.call(session)
|
128
|
+
}
|
129
|
+
session.should_receive(:rename).times(1).and_return { |previous, email|
|
130
|
+
assert_equal('old@bbmb.ch', previous)
|
131
|
+
assert_equal('test@bbmb.ch', email)
|
132
|
+
}
|
133
|
+
@server.rename_user('old@bbmb.ch', 'test@bbmb.ch')
|
134
|
+
end
|
135
|
+
def test_rename_user__same
|
136
|
+
assert_nothing_raised {
|
137
|
+
@server.rename_user('test@bbmb.ch', 'test@bbmb.ch')
|
138
|
+
}
|
139
|
+
end
|
140
|
+
def test_run_invoicer
|
141
|
+
BBMB.logger = flexmock('logger')
|
142
|
+
BBMB.logger.should_ignore_missing
|
143
|
+
flexstub(Mail).should_receive(:notify_error).times(1).and_return { |error|
|
144
|
+
assert_instance_of(RuntimeError, error)
|
145
|
+
}
|
146
|
+
flexstub(Invoicer).should_receive(:run).times(1).and_return { |range|
|
147
|
+
assert_instance_of(Range, range)
|
148
|
+
raise "notify an error!"
|
149
|
+
}
|
150
|
+
invoicer = @server.run_invoicer
|
151
|
+
Timeout.timeout(5) {
|
152
|
+
until(invoicer.status == 'sleep')
|
153
|
+
sleep 0.1
|
154
|
+
end
|
155
|
+
}
|
156
|
+
invoicer.wakeup
|
157
|
+
assert_equal('run', invoicer.status)
|
158
|
+
until(invoicer.status == 'sleep')
|
159
|
+
sleep 0.1
|
160
|
+
end
|
161
|
+
invoicer.exit
|
162
|
+
end
|
163
|
+
def test_run_updater
|
164
|
+
BBMB.config = flexmock('config')
|
165
|
+
BBMB.config.should_receive(:update_hour).and_return(0)
|
166
|
+
BBMB.logger = flexmock('logger')
|
167
|
+
BBMB.logger.should_ignore_missing
|
168
|
+
flexstub(Mail).should_receive(:notify_error).times(1).and_return { |error|
|
169
|
+
assert_instance_of(RuntimeError, error)
|
170
|
+
}
|
171
|
+
flexstub(Updater).should_receive(:run).times(1).and_return {
|
172
|
+
raise "notify an error!"
|
173
|
+
}
|
174
|
+
updater = @server.run_updater
|
175
|
+
Timeout.timeout(5) {
|
176
|
+
until(updater.status == 'sleep')
|
177
|
+
sleep 0.1
|
178
|
+
end
|
179
|
+
}
|
180
|
+
updater.wakeup
|
181
|
+
assert_equal('run', updater.status)
|
182
|
+
until(updater.status == 'sleep')
|
183
|
+
sleep 0.1
|
184
|
+
end
|
185
|
+
updater.exit
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|