# Path: cloudify_secrets/sdk.py
# class SecretsSDK(object):
# 
#     DEFAULT_SEPARATOR = '__'
# 
#     @staticmethod
#     def _try_to_serialize(value):
#         if isinstance(value, (dict, list, tuple)):
#             return json.dumps(value)
# 
#         return str(value)
# 
#     @staticmethod
#     def _try_to_parse(value):
#         try:
#             return json.loads(value)
#         except ValueError:
#             return value
# 
#     def __init__(self, logger, rest_client, separator=DEFAULT_SEPARATOR, **_):
#         self._logger = logger
#         self._rest_client = rest_client
#         self._separator = separator
# 
#     def _handle_variant(self, key, variant=None):
#         if variant:
#             return '{0}{1}{2}'.format(key, self._separator, variant)
# 
#         return key
# 
#     def _write(self, rest_client_method, entries, variant=None):
#         result = {}
# 
#         for key, value in entries.items():
#             self._logger.debug(
#                 'Creating secret "{0}" with value: {1}'
#                 .format(key, value)
#             )
# 
#             result[key] = rest_client_method(
#                 key=self._handle_variant(key, variant),
#                 value=self._try_to_serialize(value)
#             )
# 
#         return result
# 
#     def create(self, entries, variant=None, **_):
#         return self._write(self._rest_client.secrets.create, entries, variant)
# 
#     def update(self, entries, variant=None, **_):
#         return self._write(self._rest_client.secrets.patch, entries, variant)
# 
#     def delete(self, secrets, variant=None, **_):
#         for key in secrets.keys():
#             self._logger.debug(
#                 'Deleting secret "{0}" ...'.format(key)
#             )
# 
#             self._rest_client.secrets.delete(
#                 key=self._handle_variant(key, variant)
#             )
# 
#     def read(self, keys, variant=None, **_):
#         result = {}
# 
#         for key in keys:
#             self._logger.debug('Reading secret "{0}" ...'.format(key))
# 
#             response = self._rest_client.secrets.get(
#                 key=self._handle_variant(key, variant)
#             )
# 
#             response['value'] = self._try_to_parse(response['value'])
#             result[key] = response
# 
#         return result


import json
import unittest
import mock
from cloudify_secrets.sdk import SecretsSDK
        expected_second_key = 'some_key_2---lab1'
        expected_third_key = 'some_key_3---lab1'
        expected_fourth_key = 'some_key_4---lab1'

        expected_calls = [
            mock.call(key=expected_first_key),
            mock.call(key=expected_second_key),
            mock.call(key=expected_third_key),
            mock.call(key=expected_fourth_key)
        ]

        self.rest_client_secrets_delete_mock.assert_has_calls(
            expected_calls,
            any_order=True
        )

    def test_read(self):
        # given
        first_key = 'some_key_1'
        second_key = 'some_key_2'
        third_key = 'some_key_3'
        fourth_key = 'some_key_4'

        properties = {
            'keys': [first_key, second_key, third_key, fourth_key],
            'variant': 'lab1',
            'separator': '---'
        }

        # when

# Path: cloudify_secrets/sdk.py
# class SecretsSDK(object):
# 
#     DEFAULT_SEPARATOR = '__'
# 
#     @staticmethod
#     def _try_to_serialize(value):
#         if isinstance(value, (dict, list, tuple)):
#             return json.dumps(value)
# 
#         return str(value)
# 
#     @staticmethod
#     def _try_to_parse(value):
#         try:
#             return json.loads(value)
#         except ValueError:
#             return value
# 
#     def __init__(self, logger, rest_client, separator=DEFAULT_SEPARATOR, **_):
#         self._logger = logger
#         self._rest_client = rest_client
#         self._separator = separator
# 
#     def _handle_variant(self, key, variant=None):
#         if variant:
#             return '{0}{1}{2}'.format(key, self._separator, variant)
# 
#         return key
# 
#     def _write(self, rest_client_method, entries, variant=None):
#         result = {}
# 
#         for key, value in entries.items():
#             self._logger.debug(
#                 'Creating secret "{0}" with value: {1}'
#                 .format(key, value)
#             )
# 
#             result[key] = rest_client_method(
#                 key=self._handle_variant(key, variant),
#                 value=self._try_to_serialize(value)
#             )
# 
#         return result
# 
#     def create(self, entries, variant=None, **_):
#         return self._write(self._rest_client.secrets.create, entries, variant)
# 
#     def update(self, entries, variant=None, **_):
#         return self._write(self._rest_client.secrets.patch, entries, variant)
# 
#     def delete(self, secrets, variant=None, **_):
#         for key in secrets.keys():
#             self._logger.debug(
#                 'Deleting secret "{0}" ...'.format(key)
#             )
# 
#             self._rest_client.secrets.delete(
#                 key=self._handle_variant(key, variant)
#             )
# 
#     def read(self, keys, variant=None, **_):
#         result = {}
# 
#         for key in keys:
#             self._logger.debug('Reading secret "{0}" ...'.format(key))
# 
#             response = self._rest_client.secrets.get(
#                 key=self._handle_variant(key, variant)
#             )
# 
#             response['value'] = self._try_to_parse(response['value'])
#             result[key] = response
# 
#         return result


# Path: cloudify_secrets/tests/test_sdk.py
import json
import unittest
import mock
from cloudify_secrets.sdk import SecretsSDK

        expected_second_key = 'some_key_2---lab1'
        expected_third_key = 'some_key_3---lab1'
        expected_fourth_key = 'some_key_4---lab1'

        expected_calls = [
            mock.call(key=expected_first_key),
            mock.call(key=expected_second_key),
            mock.call(key=expected_third_key),
            mock.call(key=expected_fourth_key)
        ]

        self.rest_client_secrets_delete_mock.assert_has_calls(
            expected_calls,
            any_order=True
        )

    def test_read(self):
        # given
        first_key = 'some_key_1'
        second_key = 'some_key_2'
        third_key = 'some_key_3'
        fourth_key = 'some_key_4'

        properties = {
            'keys': [first_key, second_key, third_key, fourth_key],
            'variant': 'lab1',
            'separator': '---'
        }

        # when

        sdk = SecretsSDK(mock.Mock(), self.rest_client_mock, **properties)