Significant performance improvements to the tests.
This commit is contained in:
parent
e5e0118b50
commit
3f50b2dcbd
|
@ -18,20 +18,26 @@ require 'google/api_client'
|
||||||
require 'google/api_client/version'
|
require 'google/api_client/version'
|
||||||
|
|
||||||
describe Google::APIClient::BatchRequest do
|
describe Google::APIClient::BatchRequest do
|
||||||
let(:client) { Google::APIClient.new }
|
CLIENT = Google::APIClient.new
|
||||||
|
|
||||||
|
after do
|
||||||
|
# Reset client to not-quite-pristine state
|
||||||
|
CLIENT.key = nil
|
||||||
|
CLIENT.user_ip = nil
|
||||||
|
end
|
||||||
|
|
||||||
it 'should raise an error if making an empty batch request' do
|
it 'should raise an error if making an empty batch request' do
|
||||||
batch = Google::APIClient::BatchRequest.new
|
batch = Google::APIClient::BatchRequest.new
|
||||||
|
|
||||||
(lambda do
|
(lambda do
|
||||||
client.execute(batch)
|
CLIENT.execute(batch)
|
||||||
end).should raise_error(Google::APIClient::BatchError)
|
end).should raise_error(Google::APIClient::BatchError)
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'with the discovery API' do
|
describe 'with the discovery API' do
|
||||||
before do
|
before do
|
||||||
client.authorization = nil
|
CLIENT.authorization = nil
|
||||||
@discovery = client.discovered_api('discovery', 'v1')
|
@discovery = CLIENT.discovered_api('discovery', 'v1')
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'with two valid requests' do
|
describe 'with two valid requests' do
|
||||||
|
@ -67,7 +73,7 @@ describe Google::APIClient::BatchRequest do
|
||||||
batch.add(@call1, ids[0])
|
batch.add(@call1, ids[0])
|
||||||
batch.add(@call2, ids[1])
|
batch.add(@call2, ids[1])
|
||||||
|
|
||||||
client.execute(batch)
|
CLIENT.execute(batch)
|
||||||
block_called.should == 2
|
block_called.should == 2
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -84,7 +90,7 @@ describe Google::APIClient::BatchRequest do
|
||||||
result.status.should == 200
|
result.status.should == 200
|
||||||
end
|
end
|
||||||
|
|
||||||
client.execute(batch)
|
CLIENT.execute(batch)
|
||||||
call1_returned.should == true
|
call1_returned.should == true
|
||||||
call2_returned.should == true
|
call2_returned.should == true
|
||||||
end
|
end
|
||||||
|
@ -137,7 +143,7 @@ describe Google::APIClient::BatchRequest do
|
||||||
batch.add(@call1, ids[0])
|
batch.add(@call1, ids[0])
|
||||||
batch.add(@call2, ids[1])
|
batch.add(@call2, ids[1])
|
||||||
|
|
||||||
client.execute(batch)
|
CLIENT.execute(batch)
|
||||||
block_called.should == 2
|
block_called.should == 2
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -155,7 +161,7 @@ describe Google::APIClient::BatchRequest do
|
||||||
result.status.should < 500
|
result.status.should < 500
|
||||||
end
|
end
|
||||||
|
|
||||||
client.execute(batch)
|
CLIENT.execute(batch)
|
||||||
call1_returned.should == true
|
call1_returned.should == true
|
||||||
call2_returned.should == true
|
call2_returned.should == true
|
||||||
end
|
end
|
||||||
|
@ -164,8 +170,8 @@ describe Google::APIClient::BatchRequest do
|
||||||
|
|
||||||
describe 'with the calendar API' do
|
describe 'with the calendar API' do
|
||||||
before do
|
before do
|
||||||
client.authorization = nil
|
CLIENT.authorization = nil
|
||||||
@calendar = client.discovered_api('calendar', 'v3')
|
@calendar = CLIENT.discovered_api('calendar', 'v3')
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'with two valid requests' do
|
describe 'with two valid requests' do
|
||||||
|
|
|
@ -29,7 +29,13 @@ require 'google/api_client'
|
||||||
require 'google/api_client/version'
|
require 'google/api_client/version'
|
||||||
|
|
||||||
describe Google::APIClient do
|
describe Google::APIClient do
|
||||||
let(:client) { Google::APIClient.new }
|
CLIENT = Google::APIClient.new
|
||||||
|
|
||||||
|
after do
|
||||||
|
# Reset client to not-quite-pristine state
|
||||||
|
CLIENT.key = nil
|
||||||
|
CLIENT.user_ip = nil
|
||||||
|
end
|
||||||
|
|
||||||
it 'should raise a type error for bogus authorization' do
|
it 'should raise a type error for bogus authorization' do
|
||||||
(lambda do
|
(lambda do
|
||||||
|
@ -39,53 +45,53 @@ describe Google::APIClient do
|
||||||
|
|
||||||
it 'should not be able to retrieve the discovery document for a bogus API' do
|
it 'should not be able to retrieve the discovery document for a bogus API' do
|
||||||
(lambda do
|
(lambda do
|
||||||
client.discovery_document('bogus')
|
CLIENT.discovery_document('bogus')
|
||||||
end).should raise_error(Google::APIClient::TransmissionError)
|
end).should raise_error(Google::APIClient::TransmissionError)
|
||||||
(lambda do
|
(lambda do
|
||||||
client.discovered_api('bogus')
|
CLIENT.discovered_api('bogus')
|
||||||
end).should raise_error(Google::APIClient::TransmissionError)
|
end).should raise_error(Google::APIClient::TransmissionError)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should raise an error for bogus services' do
|
it 'should raise an error for bogus services' do
|
||||||
(lambda do
|
(lambda do
|
||||||
client.discovered_api(42)
|
CLIENT.discovered_api(42)
|
||||||
end).should raise_error(TypeError)
|
end).should raise_error(TypeError)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should raise an error for bogus services' do
|
it 'should raise an error for bogus services' do
|
||||||
(lambda do
|
(lambda do
|
||||||
client.preferred_version(42)
|
CLIENT.preferred_version(42)
|
||||||
end).should raise_error(TypeError)
|
end).should raise_error(TypeError)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should raise an error for bogus methods' do
|
it 'should raise an error for bogus methods' do
|
||||||
(lambda do
|
(lambda do
|
||||||
client.generate_request(42)
|
CLIENT.generate_request(42)
|
||||||
end).should raise_error(TypeError)
|
end).should raise_error(TypeError)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not return a preferred version for bogus service names' do
|
it 'should not return a preferred version for bogus service names' do
|
||||||
client.preferred_version('bogus').should == nil
|
CLIENT.preferred_version('bogus').should == nil
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'with the prediction API' do
|
describe 'with the prediction API' do
|
||||||
before do
|
before do
|
||||||
client.authorization = nil
|
CLIENT.authorization = nil
|
||||||
# The prediction API no longer exposes a v1, so we have to be
|
# The prediction API no longer exposes a v1, so we have to be
|
||||||
# careful about looking up the wrong API version.
|
# careful about looking up the wrong API version.
|
||||||
@prediction = client.discovered_api('prediction', 'v1.2')
|
@prediction = CLIENT.discovered_api('prediction', 'v1.2')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should correctly determine the discovery URI' do
|
it 'should correctly determine the discovery URI' do
|
||||||
client.discovery_uri('prediction').should ===
|
CLIENT.discovery_uri('prediction').should ===
|
||||||
'https://www.googleapis.com/discovery/v1/apis/prediction/v1/rest'
|
'https://www.googleapis.com/discovery/v1/apis/prediction/v1/rest'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should correctly determine the discovery URI if :user_ip is set' do
|
it 'should correctly determine the discovery URI if :user_ip is set' do
|
||||||
client.user_ip = '127.0.0.1'
|
CLIENT.user_ip = '127.0.0.1'
|
||||||
request = client.generate_request(
|
request = CLIENT.generate_request(
|
||||||
:http_method => 'GET',
|
:http_method => 'GET',
|
||||||
:uri => client.discovery_uri('prediction', 'v1.2'),
|
:uri => CLIENT.discovery_uri('prediction', 'v1.2'),
|
||||||
:authenticated => false
|
:authenticated => false
|
||||||
)
|
)
|
||||||
request.to_env(Faraday.default_connection)[:url].to_s.should === (
|
request.to_env(Faraday.default_connection)[:url].to_s.should === (
|
||||||
|
@ -95,10 +101,10 @@ describe Google::APIClient do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should correctly determine the discovery URI if :key is set' do
|
it 'should correctly determine the discovery URI if :key is set' do
|
||||||
client.key = 'qwerty'
|
CLIENT.key = 'qwerty'
|
||||||
request = client.generate_request(
|
request = CLIENT.generate_request(
|
||||||
:http_method => 'GET',
|
:http_method => 'GET',
|
||||||
:uri => client.discovery_uri('prediction', 'v1.2'),
|
:uri => CLIENT.discovery_uri('prediction', 'v1.2'),
|
||||||
:authenticated => false
|
:authenticated => false
|
||||||
)
|
)
|
||||||
request.to_env(Faraday.default_connection)[:url].to_s.should === (
|
request.to_env(Faraday.default_connection)[:url].to_s.should === (
|
||||||
|
@ -108,11 +114,11 @@ describe Google::APIClient do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should correctly determine the discovery URI if both are set' do
|
it 'should correctly determine the discovery URI if both are set' do
|
||||||
client.key = 'qwerty'
|
CLIENT.key = 'qwerty'
|
||||||
client.user_ip = '127.0.0.1'
|
CLIENT.user_ip = '127.0.0.1'
|
||||||
request = client.generate_request(
|
request = CLIENT.generate_request(
|
||||||
:http_method => 'GET',
|
:http_method => 'GET',
|
||||||
:uri => client.discovery_uri('prediction', 'v1.2'),
|
:uri => CLIENT.discovery_uri('prediction', 'v1.2'),
|
||||||
:authenticated => false
|
:authenticated => false
|
||||||
)
|
)
|
||||||
Addressable::URI.parse(
|
Addressable::URI.parse(
|
||||||
|
@ -124,59 +130,59 @@ describe Google::APIClient do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should correctly generate API objects' do
|
it 'should correctly generate API objects' do
|
||||||
client.discovered_api('prediction', 'v1.2').name.should == 'prediction'
|
CLIENT.discovered_api('prediction', 'v1.2').name.should == 'prediction'
|
||||||
client.discovered_api('prediction', 'v1.2').version.should == 'v1.2'
|
CLIENT.discovered_api('prediction', 'v1.2').version.should == 'v1.2'
|
||||||
client.discovered_api(:prediction, 'v1.2').name.should == 'prediction'
|
CLIENT.discovered_api(:prediction, 'v1.2').name.should == 'prediction'
|
||||||
client.discovered_api(:prediction, 'v1.2').version.should == 'v1.2'
|
CLIENT.discovered_api(:prediction, 'v1.2').version.should == 'v1.2'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should discover methods' do
|
it 'should discover methods' do
|
||||||
client.discovered_method(
|
CLIENT.discovered_method(
|
||||||
'prediction.training.insert', 'prediction', 'v1.2'
|
'prediction.training.insert', 'prediction', 'v1.2'
|
||||||
).name.should == 'insert'
|
).name.should == 'insert'
|
||||||
client.discovered_method(
|
CLIENT.discovered_method(
|
||||||
:'prediction.training.insert', :prediction, 'v1.2'
|
:'prediction.training.insert', :prediction, 'v1.2'
|
||||||
).name.should == 'insert'
|
).name.should == 'insert'
|
||||||
client.discovered_method(
|
CLIENT.discovered_method(
|
||||||
'prediction.training.delete', 'prediction', 'v1.2'
|
'prediction.training.delete', 'prediction', 'v1.2'
|
||||||
).name.should == 'delete'
|
).name.should == 'delete'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should define the origin API in discovered methods' do
|
it 'should define the origin API in discovered methods' do
|
||||||
client.discovered_method(
|
CLIENT.discovered_method(
|
||||||
'prediction.training.insert', 'prediction', 'v1.2'
|
'prediction.training.insert', 'prediction', 'v1.2'
|
||||||
).api.name.should == 'prediction'
|
).api.name.should == 'prediction'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not find methods that are not in the discovery document' do
|
it 'should not find methods that are not in the discovery document' do
|
||||||
client.discovered_method(
|
CLIENT.discovered_method(
|
||||||
'prediction.bogus', 'prediction', 'v1.2'
|
'prediction.bogus', 'prediction', 'v1.2'
|
||||||
).should == nil
|
).should == nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should raise an error for bogus methods' do
|
it 'should raise an error for bogus methods' do
|
||||||
(lambda do
|
(lambda do
|
||||||
client.discovered_method(42, 'prediction', 'v1.2')
|
CLIENT.discovered_method(42, 'prediction', 'v1.2')
|
||||||
end).should raise_error(TypeError)
|
end).should raise_error(TypeError)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should raise an error for bogus methods' do
|
it 'should raise an error for bogus methods' do
|
||||||
(lambda do
|
(lambda do
|
||||||
client.generate_request(client.discovered_api('prediction', 'v1.2'))
|
CLIENT.generate_request(CLIENT.discovered_api('prediction', 'v1.2'))
|
||||||
end).should raise_error(TypeError)
|
end).should raise_error(TypeError)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should correctly determine the preferred version' do
|
it 'should correctly determine the preferred version' do
|
||||||
client.preferred_version('prediction').version.should_not == 'v1'
|
CLIENT.preferred_version('prediction').version.should_not == 'v1'
|
||||||
client.preferred_version(:prediction).version.should_not == 'v1'
|
CLIENT.preferred_version(:prediction).version.should_not == 'v1'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should return a batch path' do
|
it 'should return a batch path' do
|
||||||
client.discovered_api('prediction', 'v1.2').batch_path.should_not be_nil
|
CLIENT.discovered_api('prediction', 'v1.2').batch_path.should_not be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should generate valid requests' do
|
it 'should generate valid requests' do
|
||||||
request = client.generate_request(
|
request = CLIENT.generate_request(
|
||||||
:api_method => @prediction.training.insert,
|
:api_method => @prediction.training.insert,
|
||||||
:parameters => {'data' => '12345'}
|
:parameters => {'data' => '12345'}
|
||||||
)
|
)
|
||||||
|
@ -188,7 +194,7 @@ describe Google::APIClient do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should generate valid requests when repeated parameters are passed' do
|
it 'should generate valid requests when repeated parameters are passed' do
|
||||||
request = client.generate_request(
|
request = CLIENT.generate_request(
|
||||||
:api_method => @prediction.training.insert,
|
:api_method => @prediction.training.insert,
|
||||||
:parameters => [['data', '1'], ['data','2']]
|
:parameters => [['data', '1'], ['data','2']]
|
||||||
)
|
)
|
||||||
|
@ -198,7 +204,7 @@ describe Google::APIClient do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should generate requests against the correct URIs' do
|
it 'should generate requests against the correct URIs' do
|
||||||
request = client.generate_request(
|
request = CLIENT.generate_request(
|
||||||
:api_method => @prediction.training.insert,
|
:api_method => @prediction.training.insert,
|
||||||
:parameters => {'data' => '12345'}
|
:parameters => {'data' => '12345'}
|
||||||
)
|
)
|
||||||
|
@ -207,7 +213,7 @@ describe Google::APIClient do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should generate requests against the correct URIs' do
|
it 'should generate requests against the correct URIs' do
|
||||||
request = client.generate_request(
|
request = CLIENT.generate_request(
|
||||||
:api_method => @prediction.training.insert,
|
:api_method => @prediction.training.insert,
|
||||||
:parameters => {'data' => '12345'}
|
:parameters => {'data' => '12345'}
|
||||||
)
|
)
|
||||||
|
@ -216,24 +222,26 @@ describe Google::APIClient do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should allow modification to the base URIs for testing purposes' do
|
it 'should allow modification to the base URIs for testing purposes' do
|
||||||
prediction = client.discovered_api('prediction', 'v1.2')
|
# Using a new client instance here to avoid caching rebased discovery doc
|
||||||
prediction.method_base =
|
prediction_rebase =
|
||||||
'https://testing-domain.googleapis.com/prediction/v1.2/'
|
Google::APIClient.new.discovered_api('prediction', 'v1.2')
|
||||||
request = client.generate_request(
|
prediction_rebase.method_base =
|
||||||
:api_method => prediction.training.insert,
|
'https://testing-domain.example.com/prediction/v1.2/'
|
||||||
|
request = CLIENT.generate_request(
|
||||||
|
:api_method => prediction_rebase.training.insert,
|
||||||
:parameters => {'data' => '123'}
|
:parameters => {'data' => '123'}
|
||||||
)
|
)
|
||||||
request.to_env(Faraday.default_connection)[:url].to_s.should === (
|
request.to_env(Faraday.default_connection)[:url].to_s.should === (
|
||||||
'https://testing-domain.googleapis.com/' +
|
'https://testing-domain.example.com/' +
|
||||||
'prediction/v1.2/training?data=123'
|
'prediction/v1.2/training?data=123'
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should generate OAuth 1 requests' do
|
it 'should generate OAuth 1 requests' do
|
||||||
client.authorization = :oauth_1
|
CLIENT.authorization = :oauth_1
|
||||||
client.authorization.token_credential_key = '12345'
|
CLIENT.authorization.token_credential_key = '12345'
|
||||||
client.authorization.token_credential_secret = '12345'
|
CLIENT.authorization.token_credential_secret = '12345'
|
||||||
request = client.generate_request(
|
request = CLIENT.generate_request(
|
||||||
:api_method => @prediction.training.insert,
|
:api_method => @prediction.training.insert,
|
||||||
:parameters => {'data' => '12345'}
|
:parameters => {'data' => '12345'}
|
||||||
)
|
)
|
||||||
|
@ -242,9 +250,9 @@ describe Google::APIClient do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should generate OAuth 2 requests' do
|
it 'should generate OAuth 2 requests' do
|
||||||
client.authorization = :oauth_2
|
CLIENT.authorization = :oauth_2
|
||||||
client.authorization.access_token = '12345'
|
CLIENT.authorization.access_token = '12345'
|
||||||
request = client.generate_request(
|
request = CLIENT.generate_request(
|
||||||
:api_method => @prediction.training.insert,
|
:api_method => @prediction.training.insert,
|
||||||
:parameters => {'data' => '12345'}
|
:parameters => {'data' => '12345'}
|
||||||
)
|
)
|
||||||
|
@ -253,10 +261,10 @@ describe Google::APIClient do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not be able to execute improperly authorized requests' do
|
it 'should not be able to execute improperly authorized requests' do
|
||||||
client.authorization = :oauth_1
|
CLIENT.authorization = :oauth_1
|
||||||
client.authorization.token_credential_key = '12345'
|
CLIENT.authorization.token_credential_key = '12345'
|
||||||
client.authorization.token_credential_secret = '12345'
|
CLIENT.authorization.token_credential_secret = '12345'
|
||||||
result = client.execute(
|
result = CLIENT.execute(
|
||||||
@prediction.training.insert,
|
@prediction.training.insert,
|
||||||
{'data' => '12345'}
|
{'data' => '12345'}
|
||||||
)
|
)
|
||||||
|
@ -264,9 +272,9 @@ describe Google::APIClient do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not be able to execute improperly authorized requests' do
|
it 'should not be able to execute improperly authorized requests' do
|
||||||
client.authorization = :oauth_2
|
CLIENT.authorization = :oauth_2
|
||||||
client.authorization.access_token = '12345'
|
CLIENT.authorization.access_token = '12345'
|
||||||
result = client.execute(
|
result = CLIENT.execute(
|
||||||
@prediction.training.insert,
|
@prediction.training.insert,
|
||||||
{'data' => '12345'}
|
{'data' => '12345'}
|
||||||
)
|
)
|
||||||
|
@ -275,10 +283,10 @@ describe Google::APIClient do
|
||||||
|
|
||||||
it 'should not be able to execute improperly authorized requests' do
|
it 'should not be able to execute improperly authorized requests' do
|
||||||
(lambda do
|
(lambda do
|
||||||
client.authorization = :oauth_1
|
CLIENT.authorization = :oauth_1
|
||||||
client.authorization.token_credential_key = '12345'
|
CLIENT.authorization.token_credential_key = '12345'
|
||||||
client.authorization.token_credential_secret = '12345'
|
CLIENT.authorization.token_credential_secret = '12345'
|
||||||
result = client.execute!(
|
result = CLIENT.execute!(
|
||||||
@prediction.training.insert,
|
@prediction.training.insert,
|
||||||
{'data' => '12345'}
|
{'data' => '12345'}
|
||||||
)
|
)
|
||||||
|
@ -287,9 +295,9 @@ describe Google::APIClient do
|
||||||
|
|
||||||
it 'should not be able to execute improperly authorized requests' do
|
it 'should not be able to execute improperly authorized requests' do
|
||||||
(lambda do
|
(lambda do
|
||||||
client.authorization = :oauth_2
|
CLIENT.authorization = :oauth_2
|
||||||
client.authorization.access_token = '12345'
|
CLIENT.authorization.access_token = '12345'
|
||||||
result = client.execute!(
|
result = CLIENT.execute!(
|
||||||
@prediction.training.insert,
|
@prediction.training.insert,
|
||||||
{'data' => '12345'}
|
{'data' => '12345'}
|
||||||
)
|
)
|
||||||
|
@ -297,9 +305,9 @@ describe Google::APIClient do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should correctly handle unnamed parameters' do
|
it 'should correctly handle unnamed parameters' do
|
||||||
client.authorization = :oauth_2
|
CLIENT.authorization = :oauth_2
|
||||||
client.authorization.access_token = '12345'
|
CLIENT.authorization.access_token = '12345'
|
||||||
result = client.execute(
|
result = CLIENT.execute(
|
||||||
@prediction.training.insert,
|
@prediction.training.insert,
|
||||||
{},
|
{},
|
||||||
MultiJson.dump({"id" => "bucket/object"}),
|
MultiJson.dump({"id" => "bucket/object"}),
|
||||||
|
@ -311,41 +319,41 @@ describe Google::APIClient do
|
||||||
|
|
||||||
describe 'with the plus API' do
|
describe 'with the plus API' do
|
||||||
before do
|
before do
|
||||||
client.authorization = nil
|
CLIENT.authorization = nil
|
||||||
@plus = client.discovered_api('plus')
|
@plus = CLIENT.discovered_api('plus')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should correctly determine the discovery URI' do
|
it 'should correctly determine the discovery URI' do
|
||||||
client.discovery_uri('plus').should ===
|
CLIENT.discovery_uri('plus').should ===
|
||||||
'https://www.googleapis.com/discovery/v1/apis/plus/v1/rest'
|
'https://www.googleapis.com/discovery/v1/apis/plus/v1/rest'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should find APIs that are in the discovery document' do
|
it 'should find APIs that are in the discovery document' do
|
||||||
client.discovered_api('plus').name.should == 'plus'
|
CLIENT.discovered_api('plus').name.should == 'plus'
|
||||||
client.discovered_api('plus').version.should == 'v1'
|
CLIENT.discovered_api('plus').version.should == 'v1'
|
||||||
client.discovered_api(:plus).name.should == 'plus'
|
CLIENT.discovered_api(:plus).name.should == 'plus'
|
||||||
client.discovered_api(:plus).version.should == 'v1'
|
CLIENT.discovered_api(:plus).version.should == 'v1'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should find methods that are in the discovery document' do
|
it 'should find methods that are in the discovery document' do
|
||||||
# TODO(bobaman) Fix this when the RPC names are correct
|
# TODO(bobaman) Fix this when the RPC names are correct
|
||||||
client.discovered_method(
|
CLIENT.discovered_method(
|
||||||
'plus.activities.list', 'plus'
|
'plus.activities.list', 'plus'
|
||||||
).name.should == 'list'
|
).name.should == 'list'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should define the origin API in discovered methods' do
|
it 'should define the origin API in discovered methods' do
|
||||||
client.discovered_method(
|
CLIENT.discovered_method(
|
||||||
'plus.activities.list', 'plus'
|
'plus.activities.list', 'plus'
|
||||||
).api.name.should == 'plus'
|
).api.name.should == 'plus'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not find methods that are not in the discovery document' do
|
it 'should not find methods that are not in the discovery document' do
|
||||||
client.discovered_method('plus.bogus', 'plus').should == nil
|
CLIENT.discovered_method('plus.bogus', 'plus').should == nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should generate requests against the correct URIs' do
|
it 'should generate requests against the correct URIs' do
|
||||||
request = client.generate_request(
|
request = CLIENT.generate_request(
|
||||||
:api_method => @plus.activities.list,
|
:api_method => @plus.activities.list,
|
||||||
:parameters => {
|
:parameters => {
|
||||||
'userId' => '107807692475771887386', 'collection' => 'public'
|
'userId' => '107807692475771887386', 'collection' => 'public'
|
||||||
|
@ -360,7 +368,7 @@ describe Google::APIClient do
|
||||||
|
|
||||||
it 'should correctly validate parameters' do
|
it 'should correctly validate parameters' do
|
||||||
(lambda do
|
(lambda do
|
||||||
client.generate_request(
|
CLIENT.generate_request(
|
||||||
:api_method => @plus.activities.list,
|
:api_method => @plus.activities.list,
|
||||||
:parameters => {'alt' => 'json'},
|
:parameters => {'alt' => 'json'},
|
||||||
:authenticated => false
|
:authenticated => false
|
||||||
|
@ -370,7 +378,7 @@ describe Google::APIClient do
|
||||||
|
|
||||||
it 'should correctly validate parameters' do
|
it 'should correctly validate parameters' do
|
||||||
(lambda do
|
(lambda do
|
||||||
client.generate_request(
|
CLIENT.generate_request(
|
||||||
:api_method => @plus.activities.list,
|
:api_method => @plus.activities.list,
|
||||||
:parameters => {
|
:parameters => {
|
||||||
'userId' => '107807692475771887386', 'collection' => 'bogus'
|
'userId' => '107807692475771887386', 'collection' => 'bogus'
|
||||||
|
@ -383,42 +391,42 @@ describe Google::APIClient do
|
||||||
|
|
||||||
describe 'with the latitude API' do
|
describe 'with the latitude API' do
|
||||||
before do
|
before do
|
||||||
client.authorization = nil
|
CLIENT.authorization = nil
|
||||||
@latitude = client.discovered_api('latitude')
|
@latitude = CLIENT.discovered_api('latitude')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should correctly determine the discovery URI' do
|
it 'should correctly determine the discovery URI' do
|
||||||
client.discovery_uri('latitude').should ===
|
CLIENT.discovery_uri('latitude').should ===
|
||||||
'https://www.googleapis.com/discovery/v1/apis/latitude/v1/rest'
|
'https://www.googleapis.com/discovery/v1/apis/latitude/v1/rest'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should find APIs that are in the discovery document' do
|
it 'should find APIs that are in the discovery document' do
|
||||||
client.discovered_api('latitude').name.should == 'latitude'
|
CLIENT.discovered_api('latitude').name.should == 'latitude'
|
||||||
client.discovered_api('latitude').version.should == 'v1'
|
CLIENT.discovered_api('latitude').version.should == 'v1'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should return a batch path' do
|
it 'should return a batch path' do
|
||||||
client.discovered_api('latitude').batch_path.should_not be_nil
|
CLIENT.discovered_api('latitude').batch_path.should_not be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should find methods that are in the discovery document' do
|
it 'should find methods that are in the discovery document' do
|
||||||
client.discovered_method(
|
CLIENT.discovered_method(
|
||||||
'latitude.currentLocation.get', 'latitude'
|
'latitude.currentLocation.get', 'latitude'
|
||||||
).name.should == 'get'
|
).name.should == 'get'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should define the origin API in discovered methods' do
|
it 'should define the origin API in discovered methods' do
|
||||||
client.discovered_method(
|
CLIENT.discovered_method(
|
||||||
'latitude.currentLocation.get', 'latitude'
|
'latitude.currentLocation.get', 'latitude'
|
||||||
).api.name.should == 'latitude'
|
).api.name.should == 'latitude'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not find methods that are not in the discovery document' do
|
it 'should not find methods that are not in the discovery document' do
|
||||||
client.discovered_method('latitude.bogus', 'latitude').should == nil
|
CLIENT.discovered_method('latitude.bogus', 'latitude').should == nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should generate requests against the correct URIs' do
|
it 'should generate requests against the correct URIs' do
|
||||||
request = client.generate_request(
|
request = CLIENT.generate_request(
|
||||||
:api_method => 'latitude.currentLocation.get',
|
:api_method => 'latitude.currentLocation.get',
|
||||||
:authenticated => false
|
:authenticated => false
|
||||||
)
|
)
|
||||||
|
@ -427,7 +435,7 @@ describe Google::APIClient do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should generate requests against the correct URIs' do
|
it 'should generate requests against the correct URIs' do
|
||||||
request = client.generate_request(
|
request = CLIENT.generate_request(
|
||||||
:api_method => @latitude.current_location.get,
|
:api_method => @latitude.current_location.get,
|
||||||
:authenticated => false
|
:authenticated => false
|
||||||
)
|
)
|
||||||
|
@ -436,7 +444,7 @@ describe Google::APIClient do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not be able to execute requests without authorization' do
|
it 'should not be able to execute requests without authorization' do
|
||||||
result = client.execute(
|
result = CLIENT.execute(
|
||||||
:api_method => 'latitude.currentLocation.get',
|
:api_method => 'latitude.currentLocation.get',
|
||||||
:authenticated => false
|
:authenticated => false
|
||||||
)
|
)
|
||||||
|
@ -446,42 +454,42 @@ describe Google::APIClient do
|
||||||
|
|
||||||
describe 'with the moderator API' do
|
describe 'with the moderator API' do
|
||||||
before do
|
before do
|
||||||
client.authorization = nil
|
CLIENT.authorization = nil
|
||||||
@moderator = client.discovered_api('moderator')
|
@moderator = CLIENT.discovered_api('moderator')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should correctly determine the discovery URI' do
|
it 'should correctly determine the discovery URI' do
|
||||||
client.discovery_uri('moderator').should ===
|
CLIENT.discovery_uri('moderator').should ===
|
||||||
'https://www.googleapis.com/discovery/v1/apis/moderator/v1/rest'
|
'https://www.googleapis.com/discovery/v1/apis/moderator/v1/rest'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should find APIs that are in the discovery document' do
|
it 'should find APIs that are in the discovery document' do
|
||||||
client.discovered_api('moderator').name.should == 'moderator'
|
CLIENT.discovered_api('moderator').name.should == 'moderator'
|
||||||
client.discovered_api('moderator').version.should == 'v1'
|
CLIENT.discovered_api('moderator').version.should == 'v1'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should find methods that are in the discovery document' do
|
it 'should find methods that are in the discovery document' do
|
||||||
client.discovered_method(
|
CLIENT.discovered_method(
|
||||||
'moderator.profiles.get', 'moderator'
|
'moderator.profiles.get', 'moderator'
|
||||||
).name.should == 'get'
|
).name.should == 'get'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should define the origin API in discovered methods' do
|
it 'should define the origin API in discovered methods' do
|
||||||
client.discovered_method(
|
CLIENT.discovered_method(
|
||||||
'moderator.profiles.get', 'moderator'
|
'moderator.profiles.get', 'moderator'
|
||||||
).api.name.should == 'moderator'
|
).api.name.should == 'moderator'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not find methods that are not in the discovery document' do
|
it 'should not find methods that are not in the discovery document' do
|
||||||
client.discovered_method('moderator.bogus', 'moderator').should == nil
|
CLIENT.discovered_method('moderator.bogus', 'moderator').should == nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should return a batch path' do
|
it 'should return a batch path' do
|
||||||
client.discovered_api('moderator').batch_path.should_not be_nil
|
CLIENT.discovered_api('moderator').batch_path.should_not be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should generate requests against the correct URIs' do
|
it 'should generate requests against the correct URIs' do
|
||||||
request = client.generate_request(
|
request = CLIENT.generate_request(
|
||||||
:api_method => 'moderator.profiles.get',
|
:api_method => 'moderator.profiles.get',
|
||||||
:authenticated => false
|
:authenticated => false
|
||||||
)
|
)
|
||||||
|
@ -490,7 +498,7 @@ describe Google::APIClient do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should generate requests against the correct URIs' do
|
it 'should generate requests against the correct URIs' do
|
||||||
request = client.generate_request(
|
request = CLIENT.generate_request(
|
||||||
:api_method => @moderator.profiles.get,
|
:api_method => @moderator.profiles.get,
|
||||||
:authenticated => false
|
:authenticated => false
|
||||||
)
|
)
|
||||||
|
@ -499,7 +507,7 @@ describe Google::APIClient do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not be able to execute requests without authorization' do
|
it 'should not be able to execute requests without authorization' do
|
||||||
result = client.execute(
|
result = CLIENT.execute(
|
||||||
'moderator.profiles.get',
|
'moderator.profiles.get',
|
||||||
{},
|
{},
|
||||||
'',
|
'',
|
||||||
|
@ -512,36 +520,36 @@ describe Google::APIClient do
|
||||||
|
|
||||||
describe 'with the adsense API' do
|
describe 'with the adsense API' do
|
||||||
before do
|
before do
|
||||||
client.authorization = nil
|
CLIENT.authorization = nil
|
||||||
@adsense = client.discovered_api('adsense', 'v1')
|
@adsense = CLIENT.discovered_api('adsense', 'v1')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should correctly determine the discovery URI' do
|
it 'should correctly determine the discovery URI' do
|
||||||
client.discovery_uri('adsense').should ===
|
CLIENT.discovery_uri('adsense').should ===
|
||||||
'https://www.googleapis.com/discovery/v1/apis/adsense/v1/rest'
|
'https://www.googleapis.com/discovery/v1/apis/adsense/v1/rest'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should find APIs that are in the discovery document' do
|
it 'should find APIs that are in the discovery document' do
|
||||||
client.discovered_api('adsense').name.should == 'adsense'
|
CLIENT.discovered_api('adsense').name.should == 'adsense'
|
||||||
client.discovered_api('adsense').version.should == 'v1'
|
CLIENT.discovered_api('adsense').version.should == 'v1'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should return a batch path' do
|
it 'should return a batch path' do
|
||||||
client.discovered_api('adsense').batch_path.should_not be_nil
|
CLIENT.discovered_api('adsense').batch_path.should_not be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should find methods that are in the discovery document' do
|
it 'should find methods that are in the discovery document' do
|
||||||
client.discovered_method(
|
CLIENT.discovered_method(
|
||||||
'adsense.reports.generate', 'adsense'
|
'adsense.reports.generate', 'adsense'
|
||||||
).name.should == 'generate'
|
).name.should == 'generate'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not find methods that are not in the discovery document' do
|
it 'should not find methods that are not in the discovery document' do
|
||||||
client.discovered_method('adsense.bogus', 'adsense').should == nil
|
CLIENT.discovered_method('adsense.bogus', 'adsense').should == nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should generate requests against the correct URIs' do
|
it 'should generate requests against the correct URIs' do
|
||||||
request = client.generate_request(
|
request = CLIENT.generate_request(
|
||||||
:api_method => 'adsense.adclients.list',
|
:api_method => 'adsense.adclients.list',
|
||||||
:authenticated => false
|
:authenticated => false
|
||||||
)
|
)
|
||||||
|
@ -550,7 +558,7 @@ describe Google::APIClient do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should generate requests against the correct URIs' do
|
it 'should generate requests against the correct URIs' do
|
||||||
request = client.generate_request(
|
request = CLIENT.generate_request(
|
||||||
:api_method => @adsense.adclients.list,
|
:api_method => @adsense.adclients.list,
|
||||||
:authenticated => false
|
:authenticated => false
|
||||||
)
|
)
|
||||||
|
@ -559,7 +567,7 @@ describe Google::APIClient do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not be able to execute requests without authorization' do
|
it 'should not be able to execute requests without authorization' do
|
||||||
result = client.execute(
|
result = CLIENT.execute(
|
||||||
:api_method => 'adsense.adclients.list',
|
:api_method => 'adsense.adclients.list',
|
||||||
:authenticated => false
|
:authenticated => false
|
||||||
)
|
)
|
||||||
|
@ -568,7 +576,7 @@ describe Google::APIClient do
|
||||||
|
|
||||||
it 'should fail when validating missing required parameters' do
|
it 'should fail when validating missing required parameters' do
|
||||||
(lambda do
|
(lambda do
|
||||||
client.generate_request(
|
CLIENT.generate_request(
|
||||||
:api_method => @adsense.reports.generate,
|
:api_method => @adsense.reports.generate,
|
||||||
:authenticated => false
|
:authenticated => false
|
||||||
)
|
)
|
||||||
|
@ -577,7 +585,7 @@ describe Google::APIClient do
|
||||||
|
|
||||||
it 'should succeed when validating parameters in a correct call' do
|
it 'should succeed when validating parameters in a correct call' do
|
||||||
(lambda do
|
(lambda do
|
||||||
client.generate_request(
|
CLIENT.generate_request(
|
||||||
:api_method => @adsense.reports.generate,
|
:api_method => @adsense.reports.generate,
|
||||||
:parameters => {
|
:parameters => {
|
||||||
'startDate' => '2000-01-01',
|
'startDate' => '2000-01-01',
|
||||||
|
@ -592,7 +600,7 @@ describe Google::APIClient do
|
||||||
|
|
||||||
it 'should fail when validating parameters with invalid values' do
|
it 'should fail when validating parameters with invalid values' do
|
||||||
(lambda do
|
(lambda do
|
||||||
client.generate_request(
|
CLIENT.generate_request(
|
||||||
:api_method => @adsense.reports.generate,
|
:api_method => @adsense.reports.generate,
|
||||||
:parameters => {
|
:parameters => {
|
||||||
'startDate' => '2000-01-01',
|
'startDate' => '2000-01-01',
|
||||||
|
@ -607,7 +615,7 @@ describe Google::APIClient do
|
||||||
|
|
||||||
it 'should succeed when validating repeated parameters in a correct call' do
|
it 'should succeed when validating repeated parameters in a correct call' do
|
||||||
(lambda do
|
(lambda do
|
||||||
client.generate_request(
|
CLIENT.generate_request(
|
||||||
:api_method => @adsense.reports.generate,
|
:api_method => @adsense.reports.generate,
|
||||||
:parameters => {
|
:parameters => {
|
||||||
'startDate' => '2000-01-01',
|
'startDate' => '2000-01-01',
|
||||||
|
@ -622,7 +630,7 @@ describe Google::APIClient do
|
||||||
|
|
||||||
it 'should fail when validating incorrect repeated parameters' do
|
it 'should fail when validating incorrect repeated parameters' do
|
||||||
(lambda do
|
(lambda do
|
||||||
client.generate_request(
|
CLIENT.generate_request(
|
||||||
:api_method => @adsense.reports.generate,
|
:api_method => @adsense.reports.generate,
|
||||||
:parameters => {
|
:parameters => {
|
||||||
'startDate' => '2000-01-01',
|
'startDate' => '2000-01-01',
|
||||||
|
@ -638,8 +646,8 @@ describe Google::APIClient do
|
||||||
|
|
||||||
describe 'with the Drive API' do
|
describe 'with the Drive API' do
|
||||||
before do
|
before do
|
||||||
client.authorization = nil
|
CLIENT.authorization = nil
|
||||||
@drive = client.discovered_api('drive', 'v1')
|
@drive = CLIENT.discovered_api('drive', 'v1')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should include media upload info methods' do
|
it 'should include media upload info methods' do
|
||||||
|
|
|
@ -58,10 +58,16 @@ describe Google::APIClient::UploadIO do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe Google::APIClient::ResumableUpload do
|
describe Google::APIClient::ResumableUpload do
|
||||||
let(:client) { Google::APIClient.new }
|
CLIENT = Google::APIClient.new
|
||||||
|
|
||||||
|
after do
|
||||||
|
# Reset client to not-quite-pristine state
|
||||||
|
CLIENT.key = nil
|
||||||
|
CLIENT.user_ip = nil
|
||||||
|
end
|
||||||
|
|
||||||
before do
|
before do
|
||||||
@drive = client.discovered_api('drive', 'v1')
|
@drive = CLIENT.discovered_api('drive', 'v1')
|
||||||
@file = File.expand_path('files/sample.txt', fixtures_path)
|
@file = File.expand_path('files/sample.txt', fixtures_path)
|
||||||
@media = Google::APIClient::UploadIO.new(@file, 'text/plain')
|
@media = Google::APIClient::UploadIO.new(@file, 'text/plain')
|
||||||
@uploader = Google::APIClient::ResumableUpload.new(
|
@uploader = Google::APIClient::ResumableUpload.new(
|
||||||
|
|
|
@ -18,12 +18,12 @@ require 'google/api_client'
|
||||||
require 'google/api_client/version'
|
require 'google/api_client/version'
|
||||||
|
|
||||||
describe Google::APIClient::Result do
|
describe Google::APIClient::Result do
|
||||||
let(:client) { Google::APIClient.new }
|
CLIENT = Google::APIClient.new
|
||||||
|
|
||||||
describe 'with the plus API' do
|
describe 'with the plus API' do
|
||||||
before do
|
before do
|
||||||
client.authorization = nil
|
CLIENT.authorization = nil
|
||||||
@plus = client.discovered_api('plus', 'v1')
|
@plus = CLIENT.discovered_api('plus', 'v1')
|
||||||
@reference = Google::APIClient::Reference.new({
|
@reference = Google::APIClient::Reference.new({
|
||||||
:api_method => @plus.activities.list,
|
:api_method => @plus.activities.list,
|
||||||
:parameters => {
|
:parameters => {
|
||||||
|
|
Loading…
Reference in New Issue