-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix the utility to grab S3 JSON files
This additionally adds new test coverage and works around a travis-ci/issues/7940 .
- Loading branch information
Showing
4 changed files
with
71 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
pytest | ||
pytest-cov | ||
flake8 | ||
moto | ||
responses | ||
coveralls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import boto3 | ||
import os | ||
import taar.recommenders.utils as utils | ||
from moto import mock_s3 | ||
|
||
|
||
@mock_s3 | ||
def test_get_non_existing(): | ||
bucket = 'test-bucket' | ||
key = 'non-existing.json' | ||
|
||
conn = boto3.resource('s3', region_name='us-west-2') | ||
conn.create_bucket(Bucket=bucket) | ||
|
||
assert utils.get_s3_json_content(bucket, key) is None | ||
assert os.path.exists(utils.get_s3_cache_filename(bucket, key)) is False | ||
|
||
|
||
@mock_s3 | ||
def test_get_corrupted(): | ||
bucket = 'test-bucket' | ||
key = 'corrupted.json' | ||
|
||
conn = boto3.resource('s3', region_name='us-west-2') | ||
conn.create_bucket(Bucket=bucket) | ||
|
||
# Write a corrupted file to the mocked S3. | ||
conn.Object(bucket, key).put(Body='This is invalid JSON.') | ||
|
||
assert utils.get_s3_json_content(bucket, key) is None | ||
assert os.path.exists(utils.get_s3_cache_filename(bucket, key)) is False |