From 9522d078edbc2a84f06c31e8848cac45b819b6aa Mon Sep 17 00:00:00 2001 From: KshitijaChoudhari Date: Mon, 30 Mar 2026 12:15:06 +0530 Subject: [PATCH] Add missing RunSource enum values for runs.list_for_organization - Add terraform, tfe-run-trigger, and tfe-infrastructure-lifecycle sources - Add comprehensive unit tests for all RunSource enum values - Update example file to demonstrate all run source types - Fix bug in example file list indexing - Apply proper code formatting --- examples/run.py | 28 +++++++++++++++++++++++++++- src/pytfe/models/run.py | 3 +++ tests/units/test_run.py | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/examples/run.py b/examples/run.py index 96010b0..b95746b 100644 --- a/examples/run.py +++ b/examples/run.py @@ -130,6 +130,32 @@ def main(): except Exception as e: print(f"Error reading run details: {e}") + # Demonstrate RunSource enum values + _print_header("Run Source Types Demonstration") + + from pytfe.models.run import RunSource + + print("Available Run Source types and their meanings:") + print( + f"- {RunSource.Run_Source_API.value}: Runs created via Terraform Enterprise/Cloud API" + ) + print( + f"- {RunSource.Run_Source_Configuration_Version.value}: Runs triggered by VCS configuration version uploads" + ) + print(f"- {RunSource.Run_Source_UI.value}: Runs created via Terraform Cloud UI") + print( + f"- {RunSource.Run_Source_Terraform_Cloud.value}: Runs from Terraform CLI with cloud backend" + ) + print(f"- {RunSource.Run_Source_Terraform.value}: Runs from Terraform CLI") + print( + f"- {RunSource.Run_Source_Run_Trigger.value}: Runs triggered by run triggers" + ) + print( + f"- {RunSource.Run_Source_Infra_Lifecycle.value}: Runs from infrastructure lifecycle events" + ) + print() + print("The SDK now supports all these run source types for proper validation.") + # 3) Optionally create a new run if args.create_run: _print_header("Creating a new plan-only run") @@ -218,7 +244,7 @@ def main(): print("No runs available for actions demo") return - demo_run = run_list.items[0] + demo_run = run_list[0] print(f"Demonstrating actions for run: {demo_run.id}") print(f"Current status: {demo_run.status}") diff --git a/src/pytfe/models/run.py b/src/pytfe/models/run.py index 7ae158a..3f6b451 100644 --- a/src/pytfe/models/run.py +++ b/src/pytfe/models/run.py @@ -24,6 +24,9 @@ class RunSource(str, Enum): Run_Source_Configuration_Version = "tfe-configuration-version" Run_Source_UI = "tfe-ui" Run_Source_Terraform_Cloud = "terraform+cloud" + Run_Source_Terraform = "terraform" + Run_Source_Run_Trigger = "tfe-run-trigger" + Run_Source_Infra_Lifecycle = "tfe-infrastructure-lifecycle" class RunStatus(str, Enum): diff --git a/tests/units/test_run.py b/tests/units/test_run.py index fa7ad87..5b38cb7 100644 --- a/tests/units/test_run.py +++ b/tests/units/test_run.py @@ -417,3 +417,37 @@ def test_discard_run_success(self, runs_service): assert call_args[0][0] == "POST" assert call_args[0][1] == "/api/v2/runs/run-discard-123/actions/discard" assert call_args[1]["json_body"]["comment"] == "Discarding run" + + def test_run_source_enum_values(self): + """Test that all RunSource enum values work with Run model validation.""" + + # Test all RunSource enum values + test_sources = [ + ("tfe-api", RunSource.Run_Source_API), + ("tfe-configuration-version", RunSource.Run_Source_Configuration_Version), + ("tfe-ui", RunSource.Run_Source_UI), + ("terraform+cloud", RunSource.Run_Source_Terraform_Cloud), + ("terraform", RunSource.Run_Source_Terraform), + ("tfe-run-trigger", RunSource.Run_Source_Run_Trigger), + ("tfe-infrastructure-lifecycle", RunSource.Run_Source_Infra_Lifecycle), + ] + + for source_value, expected_enum in test_sources: + # Test that Run model can be created with this source + # Use the same format as the service methods (attributes flattened with id) + run_data = { + "id": f"run-test-{source_value.replace('+', '').replace('-', '_')}", + "status": "pending", + "source": source_value, + "message": f"Test run with source {source_value}", + "created-at": "2023-01-01T12:00:00Z", + "has-changes": False, + "is-destroy": False, + } + + # This should not raise an exception + run = Run.model_validate(run_data) + + # Verify the source was correctly parsed + assert run.source == expected_enum + assert run.source.value == source_value