test/client_test.rb in 3scale_client-2.8.2 vs test/client_test.rb in 3scale_client-2.9.0
- old
+ new
@@ -117,10 +117,11 @@
FakeWeb.register_uri(:get, "http://#{@host}/transactions/authorize.xml?provider_key=1234abcd&app_id=foo", :status => ['200', 'OK'], :body => body)
response = @client.authorize(:app_id => 'foo')
assert response.success?
+ assert !response.limits_exceeded?
assert_equal 'Ultimate', response.plan
assert_equal 2, response.usage_reports.size
assert_equal :day, response.usage_reports[0].period
assert_equal Time.utc(2010, 4, 26), response.usage_reports[0].period_start
@@ -186,22 +187,24 @@
FakeWeb.register_uri(:get, "http://#{@host}/transactions/authorize.xml?provider_key=1234abcd&app_id=foo", :status => ['409'], :body => body)
response = @client.authorize(:app_id => 'foo')
assert !response.success?
+ assert response.limits_exceeded?
assert_equal 'usage limits are exceeded', response.error_message
- assert response.usage_reports[0].exceeded?
+ assert response.usage_reports.any? { |report| report.exceeded? }
end
def test_authorize_with_invalid_app_id
body = '<error code="application_not_found">application with id="foo" was not found</error>'
FakeWeb.register_uri(:get, "http://#{@host}/transactions/authorize.xml?provider_key=1234abcd&app_id=foo", :status => ['403', 'Forbidden'], :body => body)
response = @client.authorize(:app_id => 'foo')
assert !response.success?
+ assert !response.limits_exceeded?
assert_equal 'application_not_found', response.error_code
assert_equal 'application with id="foo" was not found', response.error_message
end
def test_authorize_with_server_error
@@ -225,10 +228,11 @@
response = @client.authorize(:app_id => 'foo',
:usage => { 'metric1' => 1, 'metric2' => 2 })
assert response.success?
+ assert !response.limits_exceeded?
end
def test_authorize_with_usage_and_limits_exceeded
url = "http://#{@host}/transactions/authorize.xml?provider_key=1234abcd"\
"&app_id=foo&%5Busage%5D%5Bhits%5D=1"
@@ -252,10 +256,11 @@
FakeWeb.register_uri(:get, url, :status => ['409'], :body => body)
response = @client.authorize(:app_id => 'foo', :usage => { 'hits' => 1 })
assert !response.success?
+ assert response.limits_exceeded?
assert_equal 'usage limits are exceeded', response.error_message
end
def test_hierarchy
# Hierarchies can be retrieved in authorize, authrep, and oauth_authorize
@@ -345,10 +350,11 @@
FakeWeb.register_uri(:get, "http://#{@host}/transactions/oauth_authorize.xml?provider_key=1234abcd&app_id=foo&redirect_url=http%3A%2F%2Flocalhost%3A8080%2Foauth%2Foauth_redirect", :status => ['200', 'OK'], :body => body)
response = @client.oauth_authorize(:app_id => 'foo', :redirect_url => "http://localhost:8080/oauth/oauth_redirect")
assert response.success?
+ assert !response.limits_exceeded?
assert_equal '883bdb8dbc3b6b77dbcf26845560fdbb', response.app_key
assert_equal 'http://localhost:8080/oauth/oauth_redirect', response.redirect_url
assert_equal 'Ultimate', response.plan
@@ -397,22 +403,24 @@
FakeWeb.register_uri(:get, "http://#{@host}/transactions/oauth_authorize.xml?provider_key=1234abcd&app_id=foo", :status => ['409'], :body => body)
response = @client.oauth_authorize(:app_id => 'foo')
assert !response.success?
+ assert response.limits_exceeded?
assert_equal 'usage limits are exceeded', response.error_message
- assert response.usage_reports[0].exceeded?
+ assert response.usage_reports.any? { |report| report.exceeded? }
end
def test_oauth_authorize_with_invalid_app_id
body = '<error code="application_not_found">application with id="foo" was not found</error>'
FakeWeb.register_uri(:get, "http://#{@host}/transactions/oauth_authorize.xml?provider_key=1234abcd&app_id=foo", :status => ['403', 'Forbidden'], :body => body)
response = @client.oauth_authorize(:app_id => 'foo')
assert !response.success?
+ assert !response.limits_exceeded?
assert_equal 'application_not_found', response.error_code
assert_equal 'application with id="foo" was not found', response.error_message
end
def test_oauth_authorize_with_server_error
@@ -437,10 +445,11 @@
response = @client.oauth_authorize(
:app_id => 'foo', :usage => { 'metric1' => 1, 'metric2' => 2 })
assert response.success?
+ assert !response.limits_exceeded?
end
def test_oauth_authorize_with_usage_and_limits_exceeded
url = "http://#{@host}/transactions/oauth_authorize.xml"\
"?provider_key=1234abcd&app_id=foo&%5Busage%5D%5Bhits%5D=1"
@@ -465,10 +474,11 @@
response = @client.oauth_authorize(:app_id => 'foo',
:usage => { 'hits' => 1 })
assert !response.success?
+ assert response.limits_exceeded?
assert_equal 'usage limits are exceeded', response.error_message
end
def test_report_raises_an_exception_if_no_transactions_given
assert_raises ArgumentError do
@@ -651,10 +661,11 @@
client = ThreeScale::Client.new(:provider_key => 'foo')
response = client.authorize(:app_id => 'foo')
assert response.success?
+ assert !response.limits_exceeded?
request = FakeWeb.last_request
assert_equal "plugin-ruby-v#{version}", request["X-3scale-User-Agent"]
assert_equal "su1.3scale.net", request["host"]
end
@@ -683,9 +694,10 @@
client = ThreeScale::Client.new(:provider_key => 'foo')
response = client.authrep(:app_id => 'abc')
assert response.success?
+ assert !response.limits_exceeded?
request = FakeWeb.last_request
assert_equal "plugin-ruby-v#{version}", request["X-3scale-User-Agent"]
assert_equal "su1.3scale.net", request["host"]
end