Adding discovery document caching to Service interface
This commit is contained in:
1 parent
0d7b3d040f
commit
0fd0dca2f4
4 files changed
+349
-15
No files matched your search
@@ -57,7 +57,8 @@ describe Google::APIClient::Service do
|
||||
{
|
||||
:application_name => APPLICATION_NAME,
|
||||
:authenticated => false,
|
||||
:connection => conn
|
||||
:connection => conn,
|
||||
:cache_store => nil
|
||||
}
|
||||
)
|
||||
|
||||
@@ -76,7 +77,8 @@ describe Google::APIClient::Service do
|
||||
{
|
||||
:application_name => APPLICATION_NAME,
|
||||
:authenticated => false,
|
||||
:connection => conn
|
||||
:connection => conn,
|
||||
:cache_store => nil
|
||||
}
|
||||
)
|
||||
req = adsense.adunits.list(:adClientId => '1').execute()
|
||||
@@ -93,7 +95,8 @@ describe Google::APIClient::Service do
|
||||
{
|
||||
:application_name => APPLICATION_NAME,
|
||||
:authenticated => false,
|
||||
:connection => conn
|
||||
:connection => conn,
|
||||
:cache_store => nil
|
||||
}
|
||||
)
|
||||
req = adsense.accounts.adclients.list(:accountId => '1').execute()
|
||||
@@ -102,7 +105,7 @@ describe Google::APIClient::Service do
|
||||
describe 'with no connection' do
|
||||
before do
|
||||
@adsense = Google::APIClient::Service.new('adsense', 'v1.3',
|
||||
{:application_name => APPLICATION_NAME})
|
||||
{:application_name => APPLICATION_NAME, :cache_store => nil})
|
||||
end
|
||||
|
||||
it 'should return a resource when using a valid resource name' do
|
||||
@@ -152,7 +155,8 @@ describe Google::APIClient::Service do
|
||||
{
|
||||
:application_name => APPLICATION_NAME,
|
||||
:authenticated => false,
|
||||
:connection => conn
|
||||
:connection => conn,
|
||||
:cache_store => nil
|
||||
}
|
||||
)
|
||||
req = prediction.trainedmodels.insert(:project => '1').body({'id' => '1'}).execute()
|
||||
@@ -171,7 +175,8 @@ describe Google::APIClient::Service do
|
||||
{
|
||||
:application_name => APPLICATION_NAME,
|
||||
:authenticated => false,
|
||||
:connection => conn
|
||||
:connection => conn,
|
||||
:cache_store => nil
|
||||
}
|
||||
)
|
||||
req = prediction.trainedmodels.insert(:project => '1').body('{"id":"1"}').execute()
|
||||
@@ -181,7 +186,7 @@ describe Google::APIClient::Service do
|
||||
describe 'with no connection' do
|
||||
before do
|
||||
@prediction = Google::APIClient::Service.new('prediction', 'v1.5',
|
||||
{:application_name => APPLICATION_NAME})
|
||||
{:application_name => APPLICATION_NAME, :cache_store => nil})
|
||||
end
|
||||
|
||||
it 'should return a valid request with a body' do
|
||||
@@ -227,7 +232,8 @@ describe Google::APIClient::Service do
|
||||
{
|
||||
:application_name => APPLICATION_NAME,
|
||||
:authenticated => false,
|
||||
:connection => conn
|
||||
:connection => conn,
|
||||
:cache_store => nil
|
||||
}
|
||||
)
|
||||
req = drive.files.insert(:uploadType => 'multipart').body(@metadata).media(@media).execute()
|
||||
@@ -237,7 +243,7 @@ describe Google::APIClient::Service do
|
||||
describe 'with no connection' do
|
||||
before do
|
||||
@drive = Google::APIClient::Service.new('drive', 'v1',
|
||||
{:application_name => APPLICATION_NAME})
|
||||
{:application_name => APPLICATION_NAME, :cache_store => nil})
|
||||
end
|
||||
|
||||
it 'should return a valid request with a body and media upload' do
|
||||
@@ -265,7 +271,8 @@ describe Google::APIClient::Service do
|
||||
describe 'with the Discovery API' do
|
||||
it 'should make a valid end-to-end request' do
|
||||
discovery = Google::APIClient::Service.new('discovery', 'v1',
|
||||
{:application_name => APPLICATION_NAME, :authenticated => false})
|
||||
{:application_name => APPLICATION_NAME, :authenticated => false,
|
||||
:cache_store => nil})
|
||||
result = discovery.apis.get_rest(:api => 'discovery', :version => 'v1').execute
|
||||
result.should_not be_nil
|
||||
result.data.name.should == 'discovery'
|
||||
@@ -280,7 +287,7 @@ describe Google::APIClient::Service::Result do
|
||||
describe 'with the plus API' do
|
||||
before do
|
||||
@plus = Google::APIClient::Service.new('plus', 'v1',
|
||||
{:application_name => APPLICATION_NAME})
|
||||
{:application_name => APPLICATION_NAME, :cache_store => nil})
|
||||
@reference = Google::APIClient::Reference.new({
|
||||
:api_method => @plus.activities.list.method,
|
||||
:parameters => {
|
||||
@@ -478,7 +485,8 @@ describe Google::APIClient::Service::BatchRequest do
|
||||
describe 'with the discovery API' do
|
||||
before do
|
||||
@discovery = Google::APIClient::Service.new('discovery', 'v1',
|
||||
{:application_name => APPLICATION_NAME, :authorization => nil})
|
||||
{:application_name => APPLICATION_NAME, :authorization => nil,
|
||||
:cache_store => nil})
|
||||
end
|
||||
|
||||
describe 'with two valid requests' do
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
# encoding:utf-8
|
||||
|
||||
# Copyright 2013 Google Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
require 'google/api_client/service/simple_file_store'
|
||||
|
||||
describe Google::APIClient::Service::SimpleFileStore do
|
||||
|
||||
FILE_NAME = 'test.cache'
|
||||
|
||||
before(:all) do
|
||||
File.delete(FILE_NAME) if File.exists?(FILE_NAME)
|
||||
end
|
||||
|
||||
describe 'with no cache file' do
|
||||
before(:each) do
|
||||
File.delete(FILE_NAME) if File.exists?(FILE_NAME)
|
||||
@cache = Google::APIClient::Service::SimpleFileStore.new(FILE_NAME)
|
||||
end
|
||||
|
||||
it 'should return nil when asked if a key exists' do
|
||||
@cache.exist?('invalid').should be_nil
|
||||
File.exists?(FILE_NAME).should be_false
|
||||
end
|
||||
|
||||
it 'should return nil when asked to read a key' do
|
||||
@cache.read('invalid').should be_nil
|
||||
File.exists?(FILE_NAME).should be_false
|
||||
end
|
||||
|
||||
it 'should return nil when asked to fetch a key' do
|
||||
@cache.fetch('invalid').should be_nil
|
||||
File.exists?(FILE_NAME).should be_false
|
||||
end
|
||||
|
||||
it 'should create a cache file when asked to fetch a key with a default' do
|
||||
@cache.fetch('new_key') do
|
||||
'value'
|
||||
end.should == 'value'
|
||||
File.exists?(FILE_NAME).should be_true
|
||||
end
|
||||
|
||||
it 'should create a cache file when asked to write a key' do
|
||||
@cache.write('new_key', 'value')
|
||||
File.exists?(FILE_NAME).should be_true
|
||||
end
|
||||
|
||||
it 'should return nil when asked to delete a key' do
|
||||
@cache.delete('invalid').should be_nil
|
||||
File.exists?(FILE_NAME).should be_false
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with an existing cache' do
|
||||
before(:each) do
|
||||
File.delete(FILE_NAME) if File.exists?(FILE_NAME)
|
||||
@cache = Google::APIClient::Service::SimpleFileStore.new(FILE_NAME)
|
||||
@cache.write('existing_key', 'existing_value')
|
||||
end
|
||||
|
||||
it 'should return true when asked if an existing key exists' do
|
||||
@cache.exist?('existing_key').should be_true
|
||||
end
|
||||
|
||||
it 'should return false when asked if a nonexistent key exists' do
|
||||
@cache.exist?('invalid').should be_false
|
||||
end
|
||||
|
||||
it 'should return the value for an existing key when asked to read it' do
|
||||
@cache.read('existing_key').should == 'existing_value'
|
||||
end
|
||||
|
||||
it 'should return nil for a nonexistent key when asked to read it' do
|
||||
@cache.read('invalid').should be_nil
|
||||
end
|
||||
|
||||
it 'should return the value for an existing key when asked to read it' do
|
||||
@cache.read('existing_key').should == 'existing_value'
|
||||
end
|
||||
|
||||
it 'should return nil for a nonexistent key when asked to fetch it' do
|
||||
@cache.fetch('invalid').should be_nil
|
||||
end
|
||||
|
||||
it 'should return and save the default value for a nonexistent key when asked to fetch it with a default' do
|
||||
@cache.fetch('new_key') do
|
||||
'value'
|
||||
end.should == 'value'
|
||||
@cache.read('new_key').should == 'value'
|
||||
end
|
||||
|
||||
it 'should remove an existing value and return true when asked to delete it' do
|
||||
@cache.delete('existing_key').should be_true
|
||||
@cache.read('existing_key').should be_nil
|
||||
end
|
||||
|
||||
it 'should return false when asked to delete a nonexistent key' do
|
||||
@cache.delete('invalid').should be_false
|
||||
end
|
||||
|
||||
it 'should convert keys to strings when storing them' do
|
||||
@cache.write(:symbol_key, 'value')
|
||||
@cache.read('symbol_key').should == 'value'
|
||||
end
|
||||
|
||||
it 'should convert keys to strings when reading them' do
|
||||
@cache.read(:existing_key).should == 'existing_value'
|
||||
end
|
||||
|
||||
it 'should convert keys to strings when fetching them' do
|
||||
@cache.fetch(:existing_key).should == 'existing_value'
|
||||
end
|
||||
|
||||
it 'should convert keys to strings when deleting them' do
|
||||
@cache.delete(:existing_key).should be_true
|
||||
@cache.read('existing_key').should be_nil
|
||||
end
|
||||
end
|
||||
|
||||
after(:all) do
|
||||
File.delete(FILE_NAME) if File.exists?(FILE_NAME)
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user