|
2 | 2 | from unittest import mock |
3 | 3 |
|
4 | 4 | import pytest |
| 5 | +from defusedxml.minidom import parseString |
5 | 6 |
|
6 | 7 | from cumulusci.core.config import ( |
7 | 8 | BaseProjectConfig, |
|
27 | 28 | RecordTypeParser, |
28 | 29 | UpdatePackageXml, |
29 | 30 | metadata_sort_key, |
| 31 | + process_common_components, |
30 | 32 | ) |
31 | 33 | from cumulusci.utils import temporary_dir, touch |
32 | 34 |
|
@@ -398,3 +400,77 @@ def test_run_task(self): |
398 | 400 | with open(output_path, "r") as f: |
399 | 401 | result = f.read() |
400 | 402 | assert expected == result |
| 403 | + |
| 404 | + |
| 405 | +class TestProcessComponents: |
| 406 | + response = """<?xml version="1.0" encoding="UTF-8"?> |
| 407 | + <soapenv:Envelope |
| 408 | + xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" |
| 409 | + xmlns="http://soap.sforce.com/2006/04/metadata"> |
| 410 | + <soapenv:Body> <checkRetrieveStatusResponse> |
| 411 | + <result> |
| 412 | + <done>true</done> |
| 413 | + <fileProperties> |
| 414 | + <createdById>0058N000006PycGQAS</createdById> |
| 415 | + <createdByName>User User</createdByName> |
| 416 | + <createdDate>2024-10-08T22:54:34.372Z</createdDate> |
| 417 | + <fileName>unpackaged/labels/CustomLabels.labels</fileName> |
| 418 | + <fullName>CustomLabels</fullName> |
| 419 | + <id>000000000000000AAA</id> |
| 420 | + <lastModifiedById>0058N000006PycGQAS</lastModifiedById> |
| 421 | + <lastModifiedByName>User User</lastModifiedByName> |
| 422 | + <lastModifiedDate>2024-10-08T22:54:34.372Z</lastModifiedDate> |
| 423 | + <type>CustomLabels</type> |
| 424 | + </fileProperties> |
| 425 | + <id>09S8N000002vlujUAA</id> |
| 426 | + <messages> |
| 427 | + <problem>Entity of type 'ApexClass' 'TestClass' cannot be found</problem> |
| 428 | + <fileName>unpackaged/package.xml</fileName> |
| 429 | + </messages> |
| 430 | + <messages> |
| 431 | + <problem>Entity of type 'CustomObject' 'TestObject' cannot be found</problem> |
| 432 | + <fileName>unpackaged/package.xml</fileName> |
| 433 | + </messages> |
| 434 | + <messages> |
| 435 | + <problem>Entity of type 'CustomObject' 'AnotherObject' cannot be found</problem> |
| 436 | + <fileName>unpackaged/package.xml</fileName> |
| 437 | + </messages> |
| 438 | + </result></checkRetrieveStatusResponse></soapenv:Body></soapenv:Envelope> |
| 439 | + """ |
| 440 | + |
| 441 | + def test_process_common_components(self): |
| 442 | + |
| 443 | + response_messages = parseString(self.response).getElementsByTagName("messages") |
| 444 | + |
| 445 | + components = { |
| 446 | + "ApexClass": {"TestClass", "AnotherClass"}, |
| 447 | + "CustomObject": {"TestObject", "AnotherObject"}, |
| 448 | + } |
| 449 | + |
| 450 | + result = process_common_components(response_messages, components) |
| 451 | + |
| 452 | + expected_components = { |
| 453 | + "ApexClass": {"AnotherClass"}, |
| 454 | + } |
| 455 | + |
| 456 | + assert result == expected_components |
| 457 | + assert "ApexClass" in result |
| 458 | + assert "AnotherClass" in result["ApexClass"] |
| 459 | + assert "TestClass" not in result["ApexClass"] |
| 460 | + assert "CustomObject" not in result |
| 461 | + |
| 462 | + def test_process_common_components_no_response_messages(self): |
| 463 | + components = { |
| 464 | + "ApexClass": {"TestClass", "AnotherClass"}, |
| 465 | + "CustomObject": {"TestObject", "AnotherObject"}, |
| 466 | + } |
| 467 | + |
| 468 | + result = process_common_components([], components) |
| 469 | + |
| 470 | + # If there are no response messages, the components list should remain unchanged |
| 471 | + assert result == components |
| 472 | + |
| 473 | + def test_process_common_components_no_components(self): |
| 474 | + response_messages = parseString(self.response).getElementsByTagName("messages") |
| 475 | + result = process_common_components(response_messages, {}) |
| 476 | + assert result == {} |
0 commit comments