Skip to content

Instantly share code, notes, and snippets.

@garethgreenaway
Created December 19, 2019 21:23
Show Gist options
  • Save garethgreenaway/9c92e432ef2e40d317e0479f952a0615 to your computer and use it in GitHub Desktop.
Save garethgreenaway/9c92e432ef2e40d317e0479f952a0615 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
# Import python libs
from __future__ import absolute_import, print_function, unicode_literals
# Import Salt Testing libs
from tests.support.unit import TestCase
from tests.support.mock import patch, mock_open, MagicMock
# Import Salt Libs
import salt.pillar.s3 as s3_pillar
class S3PillarTestCase(TestCase):
'''
TestCase for salt.pillar.s3
'''
def setup_loader_modules(self):
s3_pillar_globals = {
'__utils__': {}
}
return {s3_pillar: s3_pillar_globals}
def test_refresh_buckets_cache_file(self):
key = 'XXXXXXXXXXXXXXXXXXXXX'
keyid = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
bucket = 'dummy_bucket'
service_url = 's3.amazonaws.com'
cache_file = 'dummy_file'
s3_creds = s3_pillar.S3Credentials(key, keyid, bucket, service_url)
mock_s3_query = MagicMock(return_value=None)
with patch.dict(s3_pillar.__utils__, {'s3.query': mock_s3_query}):
with patch('salt.utils.files.fopen', mock_open(read_data=b'')):
s3_pillar._refresh_buckets_cache_file(s3_creds, cache_file, False, '', '')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment