Skip to content

Commit

Permalink
@W-16780066 - Adding more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vsbharath committed Oct 4, 2024
1 parent 6fc65c2 commit 21fe76a
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 1 deletion.
61 changes: 61 additions & 0 deletions cumulusci/core/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import datetime
import os
import re
from unittest.mock import MagicMock

import pytest
import pytz
Expand Down Expand Up @@ -139,3 +140,63 @@ def test_process_list_of_pairs_dict_arg__duplicate_value(self):
error_message = re.escape("Var specified twice: foo")
with pytest.raises(TaskOptionsError, match=error_message):
utils.process_list_of_pairs_dict_arg(duplicate)


class TestProcessComponents:
def test_process_common_components(self):

mock_message_1 = MagicMock()
mock_message_1.firstChild.nextSibling.firstChild.nodeValue = (
"Entity of type 'ApexClass' named 'TestClass' is available"
)

mock_message_2 = MagicMock()
mock_message_2.firstChild.nextSibling.firstChild.nodeValue = (
"Entity of type 'CustomObject' is not available in this organization"
)

response_messages = [mock_message_1, mock_message_2]

components = {
"ApexClass": {"TestClass", "AnotherClass"},
"CustomObject": {"TestObject", "AnotherObject"},
}

result = utils.process_common_components(response_messages, components)

expected_components = {
"ApexClass": {"AnotherClass"},
}

assert result == expected_components
assert "ApexClass" in result
assert "AnotherClass" in result["ApexClass"]
assert "TestClass" not in result["ApexClass"]
assert "CustomObject" not in result

def test_process_common_components_no_response_messages(self):
components = {
"ApexClass": {"TestClass", "AnotherClass"},
"CustomObject": {"TestObject", "AnotherObject"},
}

result = utils.process_common_components([], components)

# If there are no response messages, the components list should remain unchanged
assert result == components

def test_process_common_components_no_components(self):
response_messages = [
MagicMock(
firstChild=MagicMock(
nextSibling=MagicMock(
firstChild=MagicMock(
nodeValue="Entity of type 'ApexClass' named 'TestClass' is available"
)
)
)
)
]

result = utils.process_common_components(response_messages, {})
assert result == {}
21 changes: 20 additions & 1 deletion cumulusci/utils/xml/test/test_metadata_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@

import pytest

from cumulusci.utils.xml.metadata_tree import METADATA_NAMESPACE, fromstring, parse
from cumulusci.utils.xml.metadata_tree import (
METADATA_NAMESPACE,
fromstring,
parse,
parse_package_xml_types,
)

standard_xml = f"""<Data xmlns='{METADATA_NAMESPACE}'>
<foo>Foo</foo>
Expand Down Expand Up @@ -230,3 +235,17 @@ def test_namespaced_to_string__output_namespaces(self):
assert (
" ".join(xml_out.split()).strip() == " ".join(expected_out.split()).strip()
), xml_out.strip()

def test_parse_package_xml_types(self):
from cumulusci.tasks.metadata import tests

path = (
Path(tests.__file__).parent
/ "package_metadata/namespaced_report_folder/package.xml"
)
tree = parse(path)
result = parse_package_xml_types("name", tree)

expected = {"Report": ["namespace__TestFolder/TestReport"]}

assert result == expected

0 comments on commit 21fe76a

Please sign in to comment.