Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix private sheet test #90

Merged
merged 8 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,12 @@ jobs:
run: bundle exec rubocop
- name: Run tests
run: bundle exec rake test
- run: 'echo "$GOOGLE_APPLICATION_CREDENTIALS" > account_secret.json'
shell: bash
env:
GOOGLE_APPLICATION_CREDENTIALS: ${{secrets.GOOGLE_APPLICATION_CREDENTIALS}}
- name: Run private google sheet tests
if: matrix.ruby == '3.2.0' # Limit execution on latest ruby version to prevent reaching rate limits
run: bundle exec rake test_private_google_sheet
env:
GOOGLE_APPLICATION_CREDENTIALS: 'account_secret.json'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ ad_localize/tmp/
.ruby-version
pkg/
exports/
account_secret.json
12 changes: 7 additions & 5 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2023-12-12 14:55:05 UTC using RuboCop version 1.58.0.
# on 2023-12-12 15:16:08 UTC using RuboCop version 1.58.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand All @@ -14,7 +14,7 @@ Gemspec/OrderedDependencies:
Exclude:
- 'ad_localize.gemspec'

# Offense count: 86
# Offense count: 87
# This cop supports safe autocorrection (--autocorrect).
Layout/EmptyLineAfterMagicComment:
Enabled: false
Expand Down Expand Up @@ -184,14 +184,15 @@ Style/NegatedIf:
Exclude:
- 'lib/ad_localize/interactors/generate_strings.rb'

# Offense count: 2
# Offense count: 3
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle, AllowedMethods, AllowedPatterns.
# SupportedStyles: predicate, comparison
Style/NumericPredicate:
Exclude:
- 'spec/**/*'
- 'test/repositories/drive_repository_test.rb'
- 'test/repositories/private_drive_repository_test.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Expand Down Expand Up @@ -283,19 +284,20 @@ Style/StringConcatenation:
- 'lib/ad_localize/serializers/strings_serializer.rb'
- 'lib/ad_localize/serializers/templated_serializer.rb'

# Offense count: 142
# Offense count: 146
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
# SupportedStyles: single_quotes, double_quotes
Style/StringLiterals:
Enabled: false

# Offense count: 3
# Offense count: 4
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/ZeroLengthPredicate:
Exclude:
- 'lib/ad_localize/mappers/locale_wording_to_hash.rb'
- 'test/repositories/drive_repository_test.rb'
- 'test/repositories/private_drive_repository_test.rb'

# Offense count: 15
# This cop supports safe autocorrection (--autocorrect).
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- Updated dependencies
- Increase number of retries to 5 and timeout delay to 120s when accessing Google APIs. This reduces the amount of rate limit error when using private Google spreadsheet.

## 6.1.0
### Added
Expand Down
8 changes: 7 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ require "rake/testtask"
Rake::TestTask.new(:test) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/**/*_test.rb"]
t.test_files = FileList["test/**/*_test.rb"].exclude("**/private_drive_repository_test.rb")
end

Rake::TestTask.new(:test_private_google_sheet) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/**/private_drive_repository_test.rb"]
end

task :default => :test
2 changes: 1 addition & 1 deletion lib/ad_localize/repositories/drive_repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def download_sheets_by_id(spreadsheet_id:, sheet_ids:)
sheet_ids.filter_map do |sheet_id|
begin
url = export_url(spreadsheet_id: spreadsheet_id, sheet_id: sheet_id)
string = @drive_service.http(:get, url, options: { retries: 3, max_elapsed_time: 60 })
string = @drive_service.http(:get, url, options: { retries: 5, max_elapsed_time: 120 })
next unless string

tempfile = Tempfile.new
Expand Down
18 changes: 0 additions & 18 deletions test/repositories/drive_repository_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,12 @@ class DriveRepositoryTest < TestCase
end
end

test 'download private sheets' do
skip('This test needs CI update to work')
spreadsheet_id = '149EE3axc9e0knaCZuf7nTjj0vR7EyRhGgGT3MqWKpwM'
sheet_ids = %w[0 877315405]
files = DriveRepository.new.download_sheets_by_id(spreadsheet_id: spreadsheet_id, sheet_ids: sheet_ids)
assert_equal 2, files.size
assert_not_equal files.first.read, files.second.read
files.each do |file|
assert file.size > 0
end
end

test 'download all sheets in public spreadsheet' do
spreadsheet_id = '10tmRtgFi1hG53fCcTTHgBjS5or_eCrHkwq4kJCLrYRA'
files = DriveRepository.new.download_all_sheets(spreadsheet_id: spreadsheet_id)
assert_empty files
end

test 'download all sheets in private spreadsheet' do
spreadsheet_id = '149EE3axc9e0knaCZuf7nTjj0vR7EyRhGgGT3MqWKpwM'
files = DriveRepository.new.download_all_sheets(spreadsheet_id: spreadsheet_id)
assert_empty files
end

test 'handle error on download specific sheets' do
spreadsheet_id = '10tmRtgFi1hG53fCcTTHgBjS5or_eCrHkwq4kJCLrYRA'
fake_sheet_ids = %w[-2 -1]
Expand Down
29 changes: 29 additions & 0 deletions test/repositories/private_drive_repository_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true
require 'test_helper'

module AdLocalize
module Repositories
class PrivateDriveRepositoryTest < TestCase
test 'download private sheets' do
spreadsheet_id = '149EE3axc9e0knaCZuf7nTjj0vR7EyRhGgGT3MqWKpwM'
sheet_ids = %w[0 877315405]
files = DriveRepository.new.download_sheets_by_id(spreadsheet_id: spreadsheet_id, sheet_ids: sheet_ids)
assert_equal 2, files.size
assert_not_equal files.first.read, files.second.read
files.each do |file|
assert file.size > 0
end
end

test 'download all sheets in private spreadsheet' do
spreadsheet_id = '149EE3axc9e0knaCZuf7nTjj0vR7EyRhGgGT3MqWKpwM'
files = DriveRepository.new.download_all_sheets(spreadsheet_id: spreadsheet_id)
assert_equal 2, files.size
assert_not_equal files.first.read, files.second.read
files.each do |file|
assert file.size > 0
end
end
end
end
end
Loading