Skip to content

Commit

Permalink
handled exception
Browse files Browse the repository at this point in the history
  • Loading branch information
lakshmi2506 committed Feb 6, 2024
1 parent 4c0e689 commit 1cae470
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
19 changes: 11 additions & 8 deletions metecho/api/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,21 +631,24 @@ def unsaved_changes(scratch_org, originating_user_id):


def nonsource_types(scratch_org):
scratch_org.non_source_changes = {}
with dataset_env(scratch_org) as (
project_config,
org_config,
sf,
schema,
repo,
):
components = ListNonSourceTrackable(
org_config=org_config,
project_config=project_config,
task_config=TaskConfig({"options": {}}),
)()
scratch_org.non_source_changes = {}
for types in components:
scratch_org.non_source_changes[types] = []
try:
components = ListNonSourceTrackable(
org_config=org_config,
project_config=project_config,
task_config=TaskConfig({"options": {}}),
)()
for types in components:
scratch_org.non_source_changes[types] = []
except Exception as e:
logger.error(f"Error in listing non-source-trackable metadatatypes: {e}")


def get_unsaved_changes(scratch_org, *, originating_user_id):
Expand Down
25 changes: 17 additions & 8 deletions metecho/api/tests/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,10 @@ def test_create_org_and_run_flow__no_setup_flow():


@pytest.mark.django_db
def test_get_unsaved_changes(scratch_org_factory, patch_dataset_env):
@pytest.mark.parametrize("ListNonSourceTrackable_exception", [False, True])
def test_get_unsaved_changes(
scratch_org_factory, patch_dataset_env, ListNonSourceTrackable_exception
):
scratch_org = scratch_org_factory(
latest_revision_numbers={"TypeOne": {"NameOne": 10}}
)
Expand All @@ -494,9 +497,12 @@ def test_get_unsaved_changes(scratch_org_factory, patch_dataset_env):
{"source": ["src"], "config": [], "post": [], "pre": []},
False,
)
ListNonSourceTrackable.return_value = MagicMock(
return_value=["TypeThree", "TypeFour"]
)
if ListNonSourceTrackable_exception:
ListNonSourceTrackable.return_value = MagicMock(side_effect=Exception)
else:
ListNonSourceTrackable.return_value = MagicMock(
return_value=["TypeThree", "TypeFour"]
)
get_latest_revision_numbers = stack.enter_context(
patch(f"{PATCH_ROOT}.get_latest_revision_numbers")
)
Expand All @@ -512,10 +518,13 @@ def test_get_unsaved_changes(scratch_org_factory, patch_dataset_env):
"TypeOne": ["NameOne"],
"TypeTwo": ["NameTwo"],
}
assert scratch_org.non_source_changes == {
"TypeThree": [],
"TypeFour": [],
}
if ListNonSourceTrackable_exception:
assert scratch_org.non_source_changes == {}
else:
assert scratch_org.non_source_changes == {
"TypeThree": [],
"TypeFour": [],
}
assert scratch_org.latest_revision_numbers == {"TypeOne": {"NameOne": 10}}


Expand Down

0 comments on commit 1cae470

Please sign in to comment.