-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jasper Aikema
committed
Jul 9, 2024
1 parent
fe43336
commit e3b5c1e
Showing
3 changed files
with
78 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import sys,os,time | ||
import sys, os, time | ||
import unittest | ||
import json | ||
from unittest import mock | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import sys, os | ||
import unittest | ||
from requests.exceptions import ConnectionError | ||
from unittest import mock | ||
|
||
sys.path.append(os.getcwd()) | ||
from contents.salt import SaltApiNodeStepPlugin | ||
|
||
|
||
class TestSaltApiNodeStepPlugin(unittest.TestCase): | ||
|
||
def setUp(self): | ||
|
||
self.PARAM_ENDPOINT = "https://localhost" | ||
self.PARAM_EAUTH = "pam" | ||
self.PARAM_MINION_NAME = "minion" | ||
self.PARAM_FUNCTION = "some.function" | ||
self.PARAM_USER = "user" | ||
self.PARAM_PASSWORD = "password&!@$*" | ||
self.AUTH_TOKEN = "123qwe" | ||
self.OUTPUT_JID = "20130213093536481553" | ||
self.HOST_RESPONSE = "\"some response\"" | ||
|
||
self.plugin = SaltApiNodeStepPlugin(self.PARAM_ENDPOINT, self.PARAM_USER, self.PARAM_PASSWORD) | ||
|
||
@mock.patch('requests.post') | ||
def test_logout(self, mock_post): | ||
mock_post.return_value.status_code = 200 | ||
mock_post.return_value.json.return_value = {} | ||
|
||
result = self.plugin.logoutQuietly(self.AUTH_TOKEN) | ||
|
||
self.assertIsNone(result) | ||
mock_post.assert_called_once_with( | ||
self.PARAM_ENDPOINT+'/logout', | ||
headers={"X-Auth-Token": self.AUTH_TOKEN} | ||
) | ||
|
||
@mock.patch('requests.post') | ||
def test_logout_throws_IOException_remains_quiet(self, mock_post): | ||
mock_post.side_effect = ConnectionError('test ConnectionError') | ||
|
||
result = self.plugin.logoutQuietly(self.AUTH_TOKEN) | ||
|
||
self.assertIsNone(result) | ||
|
||
@mock.patch('requests.post') | ||
def test_logout_throws_interrupted_exception_remains_quiet(self, mock_post): | ||
mock_post.side_effect = InterruptedError('test InterruptedError') | ||
|
||
result = self.plugin.logoutQuietly(self.AUTH_TOKEN) | ||
|
||
self.assertIsNone(result) |