def test_set_v2(self): """ Test salt.sdb.vault.set function with kv v2 backend """ version = { "v2": True, "data": "path/data/to/foo", "metadata": "path/metadata/to/foo", "type": "kv", } mock_version = MagicMock(return_value=version) mock_vault = MagicMock() mock_vault.return_value.status_code = 200 with patch.dict(vault.__utils__, {"vault.make_request": mock_vault}), patch.dict( vault.__utils__, {"vault.is_v2": mock_version}): vault.set_("sdb://myvault/path/to/foo/bar", "super awesome") self.assertEqual( mock_vault.call_args_list, [ call( "POST", "v1/path/data/to/foo", json={"data": { "bar": "super awesome" }}, ) ], )
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_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_set_question_mark(self): """ Test salt.sdb.vault.set_ while using the old deprecated solution with a question mark. """ version = {"v2": False, "data": None, "metadata": None, "type": None} mock_version = MagicMock(return_value=version) mock_vault = MagicMock() mock_vault.return_value.status_code = 200 with patch.dict(vault.__utils__, {"vault.make_request": mock_vault}), patch.dict( vault.__utils__, {"vault.is_v2": mock_version}): vault.set_("sdb://myvault/path/to/foo?bar", "super awesome") self.assertEqual( mock_vault.call_args_list, [ call( "POST", "v1/sdb://myvault/path/to/foo", json={"bar": "super awesome"}, ) ], )