Skip to content

Commit

Permalink
Fix unittests and condition
Browse files Browse the repository at this point in the history
  • Loading branch information
thefrieddan1 committed Apr 8, 2024
1 parent 557d615 commit 5c9257d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -455,38 +455,48 @@ def test__enhance_pack_properties__internal_and_external(


@pytest.mark.parametrize(
"marketplace_version, current_toversion, new_toversion, expected_toversion",
"marketplace_version, new_from_version, current_toversion, new_toversion, expected_toversion",
[
(MarketplaceVersions.XSOAR, "7.9.9", "8.2.0", "7.9.9"),
(MarketplaceVersions.XSOAR, "6.2.0", "7.9.9", "7.9.9"),
(MarketplaceVersions.XSOAR, "7.9.9", DEFAULT_CONTENT_ITEM_TO_VERSION, ""),
(MarketplaceVersions.XSOAR_SAAS, "6.2.0", "8.5.0", "8.5.0"),
(MarketplaceVersions.XSOAR, "8.0.0", "7.9.9", "8.2.0", "7.9.9"),
(MarketplaceVersions.XSOAR, "5.5.0", "6.2.0", "7.9.9", "7.9.9"),
(
MarketplaceVersions.XSOAR,
"5.5.0",
"7.9.9",
DEFAULT_CONTENT_ITEM_TO_VERSION,
"",
),
(MarketplaceVersions.XSOAR_SAAS, "8.0.0", "6.2.0", "8.5.0", "8.5.0"),
],
)
def test_replace_item_if_has_higher_toversion(
marketplace_version, current_toversion, new_toversion, expected_toversion
marketplace_version,
new_from_version,
current_toversion,
new_toversion,
expected_toversion,
):
content_item_metadata = {"toversion": current_toversion}
marketplace = marketplace_version
"""Tests the _replace_item_if_has_higher_toversion
updates to the highest version supported by the MarketplaceVersions.XSOAR
ARGS:
marketplace_version: MarketplaceVersions the flow is running on.
current_toversion: current toversion of content item in the pack metadata
new_toversion: a new toversion of content item
expected_toversion
Given:
- a Pack Metadata and an integration uploading to MarketplaceVersions.XSOAR
When:
- Calling the _replace_item_if_has_higher_toversion method.
Then:
- Verify that the content_item_metadata toversion is set correctly.
Scenario 1: On MarketplaceVersions.XSOAR should not update the metadata to a version higher than 7.9.9
Scenario 2: On MarketplaceVersions.XSOAR should update to higher version while still lower than the max 7.9.9
Scenario 3: On all marketplaces will update the metdata of content item toversion to empty if new toversion is DEFAULT_CONTENT_ITEM_TO_VERSION
Scenario 4: On MarketplaceVersions.XSOAR_SAAS should update metadata to the highest version.
updates to the highest version supported by the MarketplaceVersions.XSOAR
ARGS:
marketplace_version: MarketplaceVersions the flow is running on.
new_from_version: the fromversion of content item in the pack metadata
current_toversion: current toversion of content item in the pack metadata
new_toversion: a new toversion of content item
expected_toversion
Given:
- a Pack Metadata and an integration uploading to MarketplaceVersions.XSOAR
When:
- Calling the _replace_item_if_has_higher_toversion method.
Then:
- Verify that the content_item_metadata toversion is set correctly.
Scenario 1: On MarketplaceVersions.XSOAR should not update the metadata to a version higher than 7.9.9
Scenario 2: On MarketplaceVersions.XSOAR should update to higher version while still lower than the max 7.9.9
Scenario 3: On all marketplaces will update the metdata of content item toversion to empty if new toversion is DEFAULT_CONTENT_ITEM_TO_VERSION
Scenario 4: On MarketplaceVersions.XSOAR_SAAS should update metadata to the highest version.
"""

content_item_metadata = {"toversion": current_toversion}
marketplace = marketplace_version
my_instance = PackMetadata(
name="test",
display_name="",
Expand All @@ -509,6 +519,7 @@ def test_replace_item_if_has_higher_toversion(
) # type: ignore
integration = mock_integration()
integration.toversion = new_toversion
integration.fromversion = new_from_version
my_instance._replace_item_if_has_higher_toversion(
integration, content_item_metadata, integration.summary(), marketplace
)
Expand Down
6 changes: 2 additions & 4 deletions demisto_sdk/commands/content_graph/objects/pack_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,11 +462,9 @@ def _replace_item_if_has_higher_toversion(
"""
if marketplace == MarketplaceVersions.XSOAR and parse(
content_item.fromversion
) > Version("7.9.9"):
) >= Version("8.0.0"):
logger.debug(
f"Content_item: {content_item.name} has a fromversion\
{content_item.fromversion} higher than applicable\
for XSOAR6 marketplace. Skipping metadata update."
f"Content_item: {content_item.name} has a fromversion {content_item.fromversion} higher than applicable for XSOAR6 marketplace. Skipping metadata update."
)
return
if parse(content_item.toversion) > parse(
Expand Down

0 comments on commit 5c9257d

Please sign in to comment.