コード例 #1
0
def test_read_aws_cache_catch_exception(ensure_cache_dir: MagicMock,
                                        is_file: MagicMock,
                                        json_load: MagicMock, open: MagicMock):
    is_file.return_value = True
    json_load.side_effect = Exception('Some exception')

    cache.read_aws_cache('cache-file')
コード例 #2
0
def test_read_aws_cache_no_file(ensure_cache_dir: MagicMock, is_file: MagicMock, json_load: MagicMock, open: MagicMock):
    is_file.return_value = False

    result = cache.read_aws_cache('cache-file')

    ensure_cache_dir.assert_called()
    assert result == {}
コード例 #3
0
def test_read_aws_cache_no_expiration(ensure_cache_dir: MagicMock, is_file: MagicMock, json_load: MagicMock, open: MagicMock):
    is_file.return_value = True
    json_load.return_value = {
        'AccessKeyId': 'AKIA...',
        'SecretAccessKey': 'SECRET',
        'SessionToken': 'LONGSECRET',
    }

    result = cache.read_aws_cache('cache-file')

    ensure_cache_dir.assert_called()
    open.assert_called()
    json_load.assert_called()
    assert result == json_load.return_value
コード例 #4
0
def test_read_aws_cache(ensure_cache_dir: MagicMock, is_file: MagicMock, json_load: MagicMock, open: MagicMock):
    is_file.return_value = True
    json_load.return_value = {
        'AccessKeyId': 'AKIA...',
        'SecretAccessKey': 'SECRET',
        'SessionToken': 'LONGSECRET',
        'Expiration': '2065-10-24 12:24:36',
    }

    result = cache.read_aws_cache('cache-file')

    ensure_cache_dir.assert_called()
    open.assert_called()
    json_load.assert_called()
    assert type(result.get('Expiration')) is datetime