This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix condition for raising ValueError (#89)
* fix condition for raising ValueError * add ut for task_status * put check status outside wait method * add docstring to get_all_tasks * bump patch version Co-authored-by: danielui <[email protected]>
- Loading branch information
Showing
3 changed files
with
65 additions
and
12 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "vmngclient" | ||
version = "0.5.0" | ||
version = "0.5.1" | ||
description = "Universal vManage API" | ||
authors = ["kagorski <[email protected]>"] | ||
readme = "README.md" | ||
|
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,29 +1,71 @@ | ||
import unittest | ||
from unittest.mock import patch | ||
|
||
from vmngclient.api.task_status_api import TaskStatus, wait_for_completed | ||
from vmngclient.api.task_status_api import TaskStatus, get_all_tasks, wait_for_completed | ||
|
||
|
||
class TestTaskStatusApi(unittest.TestCase): | ||
def setUp(self): | ||
self.task = TaskStatus("Success", "success", []) | ||
self.action_data = [{"status": "Success", "statusId": "success", "activity": []}] | ||
|
||
@patch("vmngclient.session.vManageSession") | ||
def test_wait_for_completed_success(self, mock_session): | ||
|
||
# Prepare mock data | ||
mock_session.get_data.return_value = [{"status": "Success", "statusId": "success", "activity": []}] | ||
mock_session.get_data.return_value = self.action_data | ||
|
||
# Assert | ||
answer = wait_for_completed(mock_session, "mock_action_id", 3000, 5) | ||
self.assertEqual(answer, self.task, "job status incorrect") | ||
|
||
@patch("vmngclient.session.vManageSession") | ||
def test_wait_for_completed_status_out_of_range(self, mock_session): | ||
|
||
# Prepare mock data | ||
mock_session.get_data.return_value = [{"status": "Other_status", "statusId": "other_status", "activity": []}] | ||
|
||
# Assert | ||
answer = wait_for_completed(mock_session, "mock_action_id", 1, 1) | ||
self.assertEqual(answer, None, "job status incorrect") | ||
|
||
@patch("vmngclient.api.task_status_api.sleep") | ||
@patch("vmngclient.api.task_status_api.get_all_tasks") | ||
@patch("vmngclient.session.vManageSession") | ||
def test_raise_index_error_actionid_in_tasks_ids_data_exists(self, mock_session, mock_get_tasks, mock_sleep): | ||
# Arrange | ||
mock_session.get_data.side_effect = [IndexError(), self.action_data] | ||
mock_get_tasks.return_value = ["action_id"] | ||
# Act | ||
answer = wait_for_completed(mock_session, "action_id", 1, 1) | ||
# Assert | ||
self.assertEqual(answer, self.task) | ||
|
||
@patch("vmngclient.api.task_status_api.sleep") | ||
@patch("vmngclient.api.task_status_api.get_all_tasks") | ||
@patch("vmngclient.session.vManageSession") | ||
def test_raise_index_error_actionid_in_tasks_ids_data_dosnt_exists(self, mock_session, mock_get_tasks, mock_sleep): | ||
# Arrange | ||
mock_session.get_data.side_effect = [IndexError(), []] | ||
mock_get_tasks.return_value = ["action_id"] | ||
# Act&Assert | ||
self.assertRaises(IndexError, wait_for_completed, mock_session, "action_id", 1, 1) | ||
|
||
@patch("vmngclient.api.task_status_api.sleep") | ||
@patch("vmngclient.api.task_status_api.get_all_tasks") | ||
@patch("vmngclient.session.vManageSession") | ||
def test_raise_index_error_actionid_not_in_tasks(self, mock_session, mock_get_tasks, mock_sleep): | ||
# Arrange | ||
mock_session.get_data.side_effect = IndexError() | ||
mock_get_tasks.return_value = ["no_id"] | ||
# Act&Assert | ||
self.assertRaises(ValueError, wait_for_completed, mock_session, "action_id", 1, 1) | ||
|
||
@patch("vmngclient.session.vManageSession") | ||
def test_get_all_tasks(self, mock_session): | ||
# Arrange | ||
mock_session.get_json.return_value = { | ||
"runningTasks": [{"processId": "processId_1"}, {"processId": "processId_2"}] | ||
} | ||
# Act | ||
answer = get_all_tasks(mock_session) | ||
# Assert | ||
self.assertEqual(answer, ["processId_1", "processId_2"]) |