3scale-3scale_ws_api_for_ruby 0.4.9 → 0.4.10
Sign up to get free protection for your applications and to get access to all the features.
- data/test/interface_test.rb +33 -28
- metadata +1 -1
data/test/interface_test.rb
CHANGED
@@ -1,20 +1,25 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'activesupport'
|
3
|
+
|
4
|
+
gem 'fakeweb', '>=1.2.4'
|
3
5
|
require 'fake_web'
|
6
|
+
|
7
|
+
gem 'mocha', '0.9.5'
|
4
8
|
require 'mocha'
|
9
|
+
|
5
10
|
require 'test/unit'
|
6
11
|
|
7
12
|
require "#{File.dirname(__FILE__)}/../lib/3scale/interface"
|
8
13
|
|
9
14
|
class InterfaceTest < Test::Unit::TestCase
|
10
15
|
def setup
|
11
|
-
@interface = ThreeScale::Interface.new('http://3scale.net', 'some_key')
|
16
|
+
@interface = ThreeScale::Interface.new('http://server.3scale.net', 'some_key')
|
12
17
|
end
|
13
18
|
|
14
19
|
def test_start_should_raise_exception_on_invalid_user_key
|
15
|
-
FakeWeb.register_uri('http://3scale.net/transactions.xml',
|
20
|
+
FakeWeb.register_uri(:post, 'http://server.3scale.net/transactions.xml',
|
16
21
|
:status => ['403', 'Forbidden'],
|
17
|
-
:
|
22
|
+
:body => stub_error('user.invalid_key'))
|
18
23
|
|
19
24
|
assert_raise ThreeScale::UserKeyInvalid do
|
20
25
|
@interface.start('invalid_key')
|
@@ -22,9 +27,9 @@ class InterfaceTest < Test::Unit::TestCase
|
|
22
27
|
end
|
23
28
|
|
24
29
|
def test_start_should_raise_exception_on_invalid_provider_key
|
25
|
-
FakeWeb.register_uri('http://3scale.net/transactions.xml',
|
30
|
+
FakeWeb.register_uri(:post, 'http://server.3scale.net/transactions.xml',
|
26
31
|
:status => ['403', 'Forbidden'],
|
27
|
-
:
|
32
|
+
:body => stub_error('provider.invalid_key'))
|
28
33
|
|
29
34
|
assert_raise ThreeScale::ProviderKeyInvalid do
|
30
35
|
@interface.start('valid_key')
|
@@ -32,9 +37,9 @@ class InterfaceTest < Test::Unit::TestCase
|
|
32
37
|
end
|
33
38
|
|
34
39
|
def test_start_should_raise_exception_on_inactive_contract
|
35
|
-
FakeWeb.register_uri('http://3scale.net/transactions.xml',
|
40
|
+
FakeWeb.register_uri(:post, 'http://server.3scale.net/transactions.xml',
|
36
41
|
:status => ['403', 'Forbidden'],
|
37
|
-
:
|
42
|
+
:body => stub_error('user.inactive_contract'))
|
38
43
|
|
39
44
|
assert_raise ThreeScale::ContractNotActive do
|
40
45
|
@interface.start('valid_key', 'clicks' => 1)
|
@@ -42,9 +47,9 @@ class InterfaceTest < Test::Unit::TestCase
|
|
42
47
|
end
|
43
48
|
|
44
49
|
def test_start_should_raise_exception_on_invalid_metric
|
45
|
-
FakeWeb.register_uri('http://3scale.net/transactions.xml',
|
50
|
+
FakeWeb.register_uri(:post, 'http://server.3scale.net/transactions.xml',
|
46
51
|
:status => ['400', 'Bad Request'],
|
47
|
-
:
|
52
|
+
:body => stub_error('provider.invalid_metric'))
|
48
53
|
|
49
54
|
assert_raise ThreeScale::MetricInvalid do
|
50
55
|
@interface.start('valid_key', 'clicks' => 1)
|
@@ -52,9 +57,9 @@ class InterfaceTest < Test::Unit::TestCase
|
|
52
57
|
end
|
53
58
|
|
54
59
|
def test_start_should_raise_exception_on_exceeded_limits
|
55
|
-
FakeWeb.register_uri('http://3scale.net/transactions.xml',
|
60
|
+
FakeWeb.register_uri(:post, 'http://server.3scale.net/transactions.xml',
|
56
61
|
:status => ['403', 'Forbidden'],
|
57
|
-
:
|
62
|
+
:body => stub_error('user.exceeded_limits'))
|
58
63
|
|
59
64
|
assert_raise ThreeScale::LimitsExceeded do
|
60
65
|
@interface.start('valid_key', 'clicks' => 1)
|
@@ -62,7 +67,7 @@ class InterfaceTest < Test::Unit::TestCase
|
|
62
67
|
end
|
63
68
|
|
64
69
|
def test_start_should_raise_exception_on_unexpected_error
|
65
|
-
FakeWeb.register_uri('http://3scale.net/transactions.xml',
|
70
|
+
FakeWeb.register_uri(:post, 'http://server.3scale.net/transactions.xml',
|
66
71
|
:status => ['500', 'Internal Server Error'])
|
67
72
|
|
68
73
|
assert_raise ThreeScale::UnknownError do
|
@@ -79,9 +84,9 @@ class InterfaceTest < Test::Unit::TestCase
|
|
79
84
|
end
|
80
85
|
|
81
86
|
def test_start_should_return_transaction_data_on_success
|
82
|
-
FakeWeb.register_uri('http://3scale.net/transactions.xml',
|
87
|
+
FakeWeb.register_uri(:post, 'http://server.3scale.net/transactions.xml',
|
83
88
|
:status => ['200', 'OK'],
|
84
|
-
:
|
89
|
+
:body => {:id => '42', :provider_verification_key => 'some_key',
|
85
90
|
:contract_name => 'ultimate'}.to_xml(:root => 'transaction',
|
86
91
|
:dasherize => false))
|
87
92
|
|
@@ -93,9 +98,9 @@ class InterfaceTest < Test::Unit::TestCase
|
|
93
98
|
end
|
94
99
|
|
95
100
|
def test_confirm_should_raise_exception_on_invalid_transaction
|
96
|
-
FakeWeb.register_uri('http://3scale.net/transactions/42/confirm.xml',
|
101
|
+
FakeWeb.register_uri(:post, 'http://server.3scale.net/transactions/42/confirm.xml',
|
97
102
|
:status => ['404', 'Not Found'],
|
98
|
-
:
|
103
|
+
:body => stub_error('provider.invalid_transaction_id'))
|
99
104
|
|
100
105
|
assert_raise ThreeScale::TransactionNotFound do
|
101
106
|
@interface.confirm(42)
|
@@ -103,9 +108,9 @@ class InterfaceTest < Test::Unit::TestCase
|
|
103
108
|
end
|
104
109
|
|
105
110
|
def test_confirm_should_raise_exception_on_invalid_provider_key
|
106
|
-
FakeWeb.register_uri('http://3scale.net/transactions/42/confirm.xml',
|
111
|
+
FakeWeb.register_uri(:post, 'http://server.3scale.net/transactions/42/confirm.xml',
|
107
112
|
:status => ['403', 'Forbidden'],
|
108
|
-
:
|
113
|
+
:body => stub_error('provider.invalid_key'))
|
109
114
|
|
110
115
|
assert_raise ThreeScale::ProviderKeyInvalid do
|
111
116
|
@interface.confirm(42)
|
@@ -113,9 +118,9 @@ class InterfaceTest < Test::Unit::TestCase
|
|
113
118
|
end
|
114
119
|
|
115
120
|
def test_confirm_should_raise_exception_on_invalid_metric
|
116
|
-
FakeWeb.register_uri('http://3scale.net/transactions/42/confirm.xml',
|
121
|
+
FakeWeb.register_uri(:post, 'http://server.3scale.net/transactions/42/confirm.xml',
|
117
122
|
:status => ['400', 'Bad Request'],
|
118
|
-
:
|
123
|
+
:body => stub_error('provider.invalid_metric'))
|
119
124
|
|
120
125
|
assert_raise ThreeScale::MetricInvalid do
|
121
126
|
@interface.confirm(42, 'clicks' => 1)
|
@@ -123,7 +128,7 @@ class InterfaceTest < Test::Unit::TestCase
|
|
123
128
|
end
|
124
129
|
|
125
130
|
def test_confirm_should_raise_exception_on_unexpected_error
|
126
|
-
FakeWeb.register_uri('http://3scale.net/transactions/42/confirm.xml',
|
131
|
+
FakeWeb.register_uri(:post, 'http://server.3scale.net/transactions/42/confirm.xml',
|
127
132
|
:status => ['500', 'Internal Server Error'])
|
128
133
|
|
129
134
|
assert_raise ThreeScale::UnknownError do
|
@@ -132,7 +137,7 @@ class InterfaceTest < Test::Unit::TestCase
|
|
132
137
|
end
|
133
138
|
|
134
139
|
def test_confirm_should_return_true_on_success
|
135
|
-
FakeWeb.register_uri('http://3scale.net/transactions/42/confirm.xml',
|
140
|
+
FakeWeb.register_uri(:post, 'http://server.3scale.net/transactions/42/confirm.xml',
|
136
141
|
:status => ['200', 'OK'])
|
137
142
|
|
138
143
|
result = @interface.confirm(42, 'clicks' => 1)
|
@@ -148,9 +153,9 @@ class InterfaceTest < Test::Unit::TestCase
|
|
148
153
|
end
|
149
154
|
|
150
155
|
def test_cancel_should_raise_exception_on_invalid_transaction
|
151
|
-
FakeWeb.register_uri('http://3scale.net/transactions/42.xml?provider_key=some_key',
|
156
|
+
FakeWeb.register_uri(:delete, 'http://server.3scale.net/transactions/42.xml?provider_key=some_key',
|
152
157
|
:status => ['404', 'Not Found'],
|
153
|
-
:
|
158
|
+
:body => stub_error('provider.invalid_transaction_id'))
|
154
159
|
|
155
160
|
assert_raise ThreeScale::TransactionNotFound do
|
156
161
|
@interface.cancel(42)
|
@@ -158,9 +163,9 @@ class InterfaceTest < Test::Unit::TestCase
|
|
158
163
|
end
|
159
164
|
|
160
165
|
def test_cancel_should_raise_exception_on_invalid_provider_key
|
161
|
-
FakeWeb.register_uri('http://3scale.net/transactions/42.xml?provider_key=some_key',
|
166
|
+
FakeWeb.register_uri(:delete, 'http://server.3scale.net/transactions/42.xml?provider_key=some_key',
|
162
167
|
:status => ['403', 'Forbidden'],
|
163
|
-
:
|
168
|
+
:body => stub_error('provider.invalid_key'))
|
164
169
|
|
165
170
|
assert_raise ThreeScale::ProviderKeyInvalid do
|
166
171
|
@interface.cancel(42)
|
@@ -168,7 +173,7 @@ class InterfaceTest < Test::Unit::TestCase
|
|
168
173
|
end
|
169
174
|
|
170
175
|
def test_cancel_should_raise_exception_on_unexpected_error
|
171
|
-
FakeWeb.register_uri('http://3scale.net/transactions/42.xml?provider_key=some_key',
|
176
|
+
FakeWeb.register_uri(:delete, 'http://server.3scale.net/transactions/42.xml?provider_key=some_key',
|
172
177
|
:status => ['500', 'Internal Server Error'])
|
173
178
|
|
174
179
|
assert_raise ThreeScale::UnknownError do
|
@@ -177,7 +182,7 @@ class InterfaceTest < Test::Unit::TestCase
|
|
177
182
|
end
|
178
183
|
|
179
184
|
def test_cancel_should_return_true_on_success
|
180
|
-
FakeWeb.register_uri('http://3scale.net/transactions/42.xml?provider_key=some_key',
|
185
|
+
FakeWeb.register_uri(:delete, 'http://server.3scale.net/transactions/42.xml?provider_key=some_key',
|
181
186
|
:status => ['200', 'OK'])
|
182
187
|
|
183
188
|
result = @interface.cancel(42)
|