From d4af7a219ef5aeafe8bb6bda2f28805e8e07ca37 Mon Sep 17 00:00:00 2001 From: Kyrylo Maksymenko Date: Tue, 24 May 2022 12:09:46 +0300 Subject: [PATCH] test getting deleted tag --- tests/cp/vcenter/handlers/__init__.py | 0 .../handlers/test_vsphere_sdk_handler.py | 21 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 tests/cp/vcenter/handlers/__init__.py create mode 100644 tests/cp/vcenter/handlers/test_vsphere_sdk_handler.py diff --git a/tests/cp/vcenter/handlers/__init__.py b/tests/cp/vcenter/handlers/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/cp/vcenter/handlers/test_vsphere_sdk_handler.py b/tests/cp/vcenter/handlers/test_vsphere_sdk_handler.py new file mode 100644 index 0000000..4c9cf29 --- /dev/null +++ b/tests/cp/vcenter/handlers/test_vsphere_sdk_handler.py @@ -0,0 +1,21 @@ +from unittest.mock import Mock + +from cloudshell.cp.vcenter.handlers.vsphere_api_handler import TagAlreadyExists +from cloudshell.cp.vcenter.handlers.vsphere_sdk_handler import VSphereSDKHandler + + +def test_tag_was_deleted_while_we_searching_for_it(logger): + # - try to create a tag - get the error that it exists + # - try to get it - get the error that we can't find it + # (it can be deleted in another thread or even Shell's venv) + # - try to create the tag one more time + client = Mock( + create_tag=Mock( + side_effect=(TagAlreadyExists("tag name", "category_id"), "tag_id") + ), + get_all_category_tags=Mock(side_effect=([], "tag_id")), + get_tag_info=Mock(side_effect=({"name": "tag name", "id": "tag_id"},)), + ) + + handler = VSphereSDKHandler(client, None, logger) + assert handler._get_or_create_tag("tag_name", "category_id") == "tag_id"