librevox 0.9 → 1.0.0.alpha2

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.
@@ -1,238 +0,0 @@
1
- require './spec/helper'
2
- require 'librevox/applications'
3
-
4
- module AppTest
5
- include Librevox::Applications
6
-
7
- extend self
8
-
9
- def application name, args="", params={}
10
- {
11
- :name => name,
12
- :args => args,
13
- :params => params
14
- }
15
- end
16
- end
17
-
18
- describe Librevox::Applications do
19
- describe "answer" do
20
- should "answer" do
21
- app = AppTest.answer
22
- app[:name].should == "answer"
23
- end
24
- end
25
-
26
- describe "att_xfer" do
27
- should "transfer to endpoint" do
28
- app = AppTest.att_xfer("user/davis")
29
- app[:name].should == "att_xfer"
30
- app[:args].should == "user/davis"
31
- end
32
- end
33
-
34
- describe "bind_meta_app" do
35
- should "bind meta app" do
36
- app = AppTest.bind_meta_app :key => "2",
37
- :listen_to => :a,
38
- :respond_on => :s,
39
- :application => "hangup"
40
-
41
- app[:name].should == "bind_meta_app"
42
- app[:args].should == "2 a s hangup"
43
- end
44
-
45
- should "bind meta app with parameters" do
46
- app = AppTest.bind_meta_app :key => "2",
47
- :listen_to => :a,
48
- :respond_on => :s,
49
- :application => "execute_extension",
50
- :parameters => "dx XML features"
51
-
52
- app[:name].should == "bind_meta_app"
53
- app[:args].should == "2 a s execute_extension::dx XML features"
54
- end
55
- end
56
-
57
- describe "bridge" do
58
- should "bridge to endpoints" do
59
- app = AppTest.bridge('user/coltrane')
60
- app[:name].should == "bridge"
61
- app[:args].should == 'user/coltrane'
62
-
63
- app = AppTest.bridge('user/coltrane', 'user/davis')
64
- app[:args].should == 'user/coltrane,user/davis'
65
- end
66
-
67
- should "bridge with variables" do
68
- app = AppTest.bridge('user/coltrane', 'user/davis', :foo => 'bar', :lol => 'cat')
69
- app[:name].should == "bridge"
70
-
71
- # fragile. hashes are not ordered in ruby 1.8
72
- app[:args].should == "{foo=bar,lol=cat}user/coltrane,user/davis"
73
- end
74
-
75
- should "bridge with failover" do
76
- app = AppTest.bridge(
77
- ['user/coltrane', 'user/davis'], ['user/sun-ra', 'user/taylor']
78
- )
79
-
80
- app[:name].should == "bridge"
81
- app[:args].should == "user/coltrane,user/davis|user/sun-ra,user/taylor"
82
- end
83
-
84
- # should "bridge with per endpoint variables" do
85
- # end
86
- end
87
-
88
- describe "deflect" do
89
- should "deflect call" do
90
- app = AppTest.deflect "sip:miles@davis.org"
91
- app[:name].should == "deflect"
92
- app[:args].should == "sip:miles@davis.org"
93
- end
94
- end
95
-
96
- describe "export" do
97
- should "export variable" do
98
- app = AppTest.export 'some_var'
99
- app[:name].should == "export"
100
- app[:args].should == "some_var"
101
- end
102
-
103
- should "only export to b-leg " do
104
- app = AppTest.export 'some_var', :local => false
105
- app[:name].should == "export"
106
- app[:args].should == "nolocal:some_var"
107
- end
108
- end
109
-
110
- describe "gentones" do
111
- should "generate tones" do
112
- app = AppTest.gentones("%(500,0,800)")
113
- app[:name].should == "gentones"
114
- app[:args].should == "%(500,0,800)"
115
- end
116
- end
117
-
118
- should "hangup" do
119
- app = AppTest.hangup
120
- app[:name].should == "hangup"
121
-
122
- app = AppTest.hangup("some cause")
123
- app[:args].should == "some cause"
124
- end
125
-
126
- describe "play_and_get_digits" do
127
- should "have defaults" do
128
- app = AppTest.play_and_get_digits "please-enter", "wrong-try-again"
129
- app[:name].should == "play_and_get_digits"
130
- app[:args].should == "1 2 3 5000 # please-enter wrong-try-again read_digits_var \\d+"
131
- app[:params][:variable].should == "read_digits_var"
132
- end
133
-
134
- should "take params" do
135
- app = AppTest.play_and_get_digits "please-enter", "invalid-choice",
136
- :min => 2,
137
- :max => 3,
138
- :tries => 4,
139
- :terminators => "0",
140
- :timeout => 10000,
141
- :variable => "other_var",
142
- :regexp => "[125]"
143
-
144
- app[:args].should == "2 3 4 10000 0 please-enter invalid-choice other_var [125]"
145
- app[:params][:variable].should == "other_var"
146
- end
147
- end
148
-
149
- should "playback" do
150
- app = AppTest.playback("uri://some/file.wav")
151
- app[:name].should == "playback"
152
- app[:args].should == "uri://some/file.wav"
153
- end
154
-
155
- describe "pre_answer" do
156
- should "pre_answer" do
157
- app = AppTest.pre_answer
158
- app[:name].should == "pre_answer"
159
- end
160
- end
161
-
162
- describe "read" do
163
- should "read with defaults" do
164
- app = AppTest.read "please-enter.wav"
165
- app[:name].should == "read"
166
- app[:args].should == "1 2 please-enter.wav read_digits_var 5000 #"
167
- app[:params][:variable].should == "read_digits_var"
168
- end
169
-
170
- should "take params" do
171
- app = AppTest.read "please-enter.wav",
172
- :min => 2,
173
- :max => 3,
174
- :terminators => "0",
175
- :timeout => 10000,
176
- :variable => "other_var"
177
-
178
- app[:args].should == "2 3 please-enter.wav other_var 10000 0"
179
- app[:params][:variable].should == "other_var"
180
- end
181
- end
182
-
183
- describe "record" do
184
- should "start recording" do
185
- app = AppTest.record "/path/to/file.mp3"
186
- app[:name].should == "record"
187
- app[:args].should == "/path/to/file.mp3"
188
- end
189
-
190
- should "start recording with time limit" do
191
- app = AppTest.record "/path/to/file.mp3", :limit => 15
192
- app[:name].should == "record"
193
- app[:args].should == "/path/to/file.mp3 15"
194
- end
195
- end
196
-
197
- describe "redirect" do
198
- should "redirect to URI" do
199
- app = AppTest.redirect("sip:miles@davis.org")
200
- app[:name].should == "redirect"
201
- app[:args].should == "sip:miles@davis.org"
202
- end
203
- end
204
-
205
- should "respond with code" do
206
- app = AppTest.respond 403
207
- app[:name].should == "respond"
208
- app[:args].should == "403"
209
- end
210
-
211
- should "set" do
212
- app = AppTest.set("foo", "bar")
213
- app[:name].should == "set"
214
- app[:args].should == "foo=bar"
215
- end
216
-
217
- should "transfer" do
218
- app = AppTest.transfer "new_extension"
219
- app[:name].should == "transfer"
220
- app[:args].should == "new_extension"
221
- end
222
-
223
- describe "unbind_meta_app" do
224
- should "unbind" do
225
- app = AppTest.unbind_meta_app 3
226
- app[:name].should == "unbind_meta_app"
227
- app[:args].should == "3"
228
- end
229
- end
230
-
231
- describe "unset" do
232
- should "unset a variable" do
233
- app = AppTest.unset('foo')
234
- app[:name].should == "unset"
235
- app[:args].should == "foo"
236
- end
237
- end
238
- end
@@ -1,103 +0,0 @@
1
- require './spec/helper'
2
- require 'librevox/commands'
3
-
4
- module CommandTest
5
- include Librevox::Commands
6
-
7
- extend self
8
-
9
- def command name, args=""
10
- {
11
- :name => name,
12
- :args => args
13
- }
14
- end
15
- end
16
-
17
- C = CommandTest
18
-
19
- describe Librevox::Commands do
20
- should "status" do
21
- cmd = C.status
22
- cmd[:name].should == "status"
23
- end
24
-
25
- describe "originate" do
26
- should "originate url to extension" do
27
- cmd = C.originate "user/coltrane", :extension => 4000
28
- cmd[:name].should == "originate"
29
- cmd[:args].should == "{}user/coltrane 4000"
30
- end
31
-
32
- should "send variables" do
33
- cmd = C.originate 'user/coltrane',
34
- :extension => 1234,
35
- :ignore_early_media => true,
36
- :other_option => "value"
37
-
38
- cmd[:args].should.match %r|^\{\S+\}user/coltrane 1234$|
39
- cmd[:args].should.match /ignore_early_media=true/
40
- cmd[:args].should.match /other_option=value/
41
- end
42
-
43
- should "take dialplan and context" do
44
- cmd = C.originate "user/coltrane",
45
- :extension => "4000",
46
- :dialplan => "XML",
47
- :context => "public"
48
- cmd[:name].should == "originate"
49
- cmd[:args].should == "{}user/coltrane 4000 XML public"
50
- end
51
- end
52
-
53
- should "fsctl" do
54
- cmd = C.fsctl :hupall, :normal_clearing
55
- cmd[:name].should == "fsctl"
56
- cmd[:args].should == "hupall normal_clearing"
57
- end
58
-
59
- should "huball" do
60
- cmd = C.hupall
61
- cmd[:name].should == "hupall"
62
-
63
- cmd = C.hupall("some_cause")
64
- cmd[:name].should == "hupall"
65
- cmd[:args].should == "some_cause"
66
- end
67
-
68
- describe "hash" do
69
- should "insert" do
70
- cmd = C.hash :insert, :firmafon, :foo, "some value or other"
71
- cmd[:name].should == "hash"
72
- cmd[:args].should == "insert/firmafon/foo/some value or other"
73
- end
74
-
75
- should "select" do
76
- cmd = C.hash :select, :firmafon, :foo
77
- cmd[:name].should == "hash"
78
- cmd[:args].should == "select/firmafon/foo"
79
- end
80
-
81
- should "delete" do
82
- cmd = C.hash :delete, :firmafon, :foo
83
- cmd[:name].should == "hash"
84
- cmd[:args].should == "delete/firmafon/foo"
85
- end
86
- end
87
-
88
- describe "uuid_park" do
89
- should "park" do
90
- cmd = C.uuid_park "1234-abcd"
91
- cmd[:name].should == "uuid_park"
92
- cmd[:args].should == "1234-abcd"
93
- end
94
- end
95
-
96
- describe "uuid_bridge" do
97
- should "bridge" do
98
- cmd = C.uuid_bridge "1234-abcd", "9090-ffff"
99
- cmd[:name].should == "uuid_bridge"
100
- cmd[:args].should == "1234-abcd 9090-ffff"
101
- end
102
- end
103
- end
@@ -1,67 +0,0 @@
1
- require './spec/helper'
2
- require 'librevox/response'
3
-
4
- include Librevox
5
-
6
- describe Response do
7
- should "parse headers to hash" do
8
- response = Response.new("Header1:some value\nOther-Header:other value")
9
-
10
- response.headers.should.include :header1
11
- response.headers[:header1].should.equal "some value"
12
-
13
- response.headers.should.include :other_header
14
- response.headers[:other_header].should.equal "other value"
15
- end
16
-
17
- should "parse key-value content to hash" do
18
- response = Response.new("", "Key:value\nOther-Key:other value")
19
-
20
- response.content.class.should.equal Hash
21
- response.content[:key].should.equal "value"
22
- response.content[:other_key].should.equal "other value"
23
- end
24
-
25
- should "not parse regular content" do
26
- response = Response.new("", "OK.")
27
-
28
- response.content.class.should.equal String
29
- response.content.should.equal "OK."
30
- end
31
-
32
- should "allow setting content from a hash" do
33
- response = Response.new
34
- response.content = {:key => 'value'}
35
- response.content.should.equal({:key => 'value'})
36
- end
37
-
38
- should "check for event" do
39
- response = Response.new("Content-Type: command/reply", "Event-Name: Hangup")
40
- response.event?.should.be.true
41
- response.event.should == "Hangup"
42
-
43
- response = Response.new("Content-Type: command/reply", "Foo-Bar: Baz")
44
- response.event?.should.be.false
45
- end
46
-
47
- should "check for api response" do
48
- response = Response.new("Content-Type: api/response", "+OK")
49
- response.api_response?.should.be.true
50
-
51
- response = Response.new("Content-Type: command/reply", "Foo-Bar: Baz")
52
- response.api_response?.should.be.false
53
- end
54
-
55
- should "check for command reply" do
56
- response = Response.new("Content-Type: command/reply", "+OK")
57
- response.command_reply?.should.be.true
58
-
59
- response = Response.new("Content-Type: api/response", "Foo-Bar: Baz")
60
- response.command_reply?.should.be.false
61
- end
62
-
63
- should "parse body from command reply" do
64
- response = Response.new("Content-Type: command/reply", "Foo-Bar: Baz\n\nMessage body")
65
- response.content[:body].should.equal "Message body"
66
- end
67
- end