# -*- coding: utf-8 -*-
'''
Test case for the vault SDB module
'''

# 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.mixins import LoaderModuleMockMixin
from tests.support.mock import (
    MagicMock,
    call,
    patch)

# Import Salt libs
import salt.sdb.vault as vault


class TestVaultSDB(LoaderModuleMockMixin, TestCase):
    '''
    Test case for the vault SDB module
    '''
    def setup_loader_modules(self):
        return {
            vault: {
                '__opts__': {
                    'vault': {
                        'url': "http://127.0.0.1",
                        "auth": {
                            'token': 'test',
                            'method': 'token'
                        }
                    }
                }
            }
        }

    def test_set(self):
        '''
        Test salt.sdb.vault.set function
        '''
        mock_vault = MagicMock()
        mock_vault.return_value.status_code = 200
        with patch.dict(vault.__utils__, {'vault.make_request': mock_vault}):
            vault.set_('sdb://myvault/path/to/foo/bar', 'super awesome')

        assert mock_vault.call_args_list == [call('POST',
                                                  'v1/sdb://myvault/path/to/foo',
                                                  None, json={'bar': 'super awesome'})]

    def test_set_question_mark(self):
        '''
        Test salt.sdb.vault.set_ while using the old
        deprecated solution with a question mark.
        '''
        mock_vault = MagicMock()
        mock_vault.return_value.status_code = 200
        with patch.dict(vault.__utils__, {'vault.make_request': mock_vault}):
            vault.set_('sdb://myvault/path/to/foo?bar', 'super awesome')

        assert mock_vault.call_args_list == [call('POST',
                                                  'v1/sdb://myvault/path/to/foo',
                                                  None, json={'bar': 'super awesome'})]

    def test_get(self):
        '''
        Test salt.sdb.vault.get function
        '''
        mock_vault = MagicMock()
        mock_vault.return_value.status_code = 200
        mock_vault.content.return_value = [{'data': {'bar', 'test'}}]
        with patch.dict(vault.__utils__, {'vault.make_request': mock_vault}):
            vault.get('sdb://myvault/path/to/foo/bar')

        assert mock_vault.call_args_list == [call('GET',
                                                  'v1/sdb://myvault/path/to/foo',
                                                  None)]

    def test_get_question_mark(self):
        '''
        Test salt.sdb.vault.get while using the old
        deprecated solution with a question mark.
        '''
        mock_vault = MagicMock()
        mock_vault.return_value.status_code = 200
        mock_vault.content.return_value = [{'data': {'bar', 'test'}}]
        with patch.dict(vault.__utils__, {'vault.make_request': mock_vault}):
            vault.get('sdb://myvault/path/to/foo?bar')
        assert mock_vault.call_args_list == [call('GET',
                                                  'v1/sdb://myvault/path/to/foo',
                                                  None)]

@@ -3291,28 +3291,413 @@
                      None)%5D%0A
+%0A    def test_get_missing(self):%0A        '''%0A        Test salt.sdb.vault.get function returns None%0A        if vault does not have a value%0A        '''%0A        mock_vault = MagicMock()%0A        mock_vault.return_value.status_code = 404%0A        with patch.dict(vault.__utils__, %7B'vault.make_request': mock_vault%7D):%0A            self.assertIsNone(vault.get('sdb://myvault/path/to/foo/bar'))%0A

Add test for vault get where vault does not have any value