From 9871eda3c944be6986ecf8712f2f977c9c477c7a Mon Sep 17 00:00:00 2001 From: gruebel Date: Sun, 15 Dec 2019 17:44:54 +0100 Subject: [PATCH] Add codepipeline.list_pipelines --- IMPLEMENTATION_COVERAGE.md | 4 +- moto/codepipeline/models.py | 15 +++ moto/codepipeline/responses.py | 5 + tests/test_codepipeline/test_codepipeline.py | 115 +++++++++++++++++++ 4 files changed, 137 insertions(+), 2 deletions(-) diff --git a/IMPLEMENTATION_COVERAGE.md b/IMPLEMENTATION_COVERAGE.md index 297e842eb..b4e0b1ee6 100644 --- a/IMPLEMENTATION_COVERAGE.md +++ b/IMPLEMENTATION_COVERAGE.md @@ -1263,7 +1263,7 @@ - [ ] update_deployment_group ## codepipeline -8% implemented +11% implemented - [ ] acknowledge_job - [ ] acknowledge_third_party_job - [ ] create_custom_action_type @@ -1282,7 +1282,7 @@ - [ ] list_action_executions - [ ] list_action_types - [ ] list_pipeline_executions -- [ ] list_pipelines +- [X] list_pipelines - [ ] list_tags_for_resource - [ ] list_webhooks - [ ] poll_for_jobs diff --git a/moto/codepipeline/models.py b/moto/codepipeline/models.py index de89f21f3..758c41555 100644 --- a/moto/codepipeline/models.py +++ b/moto/codepipeline/models.py @@ -127,6 +127,21 @@ class CodePipelineBackend(BaseBackend): return codepipeline.pipeline + def list_pipelines(self): + pipelines = [] + + for name, codepipeline in self.pipelines.items(): + pipelines.append( + { + "name": name, + "version": codepipeline.pipeline["version"], + "created": codepipeline.metadata["created"], + "updated": codepipeline.metadata["updated"], + } + ) + + return sorted(pipelines, key=lambda i: i["name"]) + codepipeline_backends = {} for region in Session().get_available_regions("codepipeline"): diff --git a/moto/codepipeline/responses.py b/moto/codepipeline/responses.py index c1aa4dc76..6611f9257 100644 --- a/moto/codepipeline/responses.py +++ b/moto/codepipeline/responses.py @@ -29,3 +29,8 @@ class CodePipelineResponse(BaseResponse): ) return json.dumps({"pipeline": pipeline}) + + def list_pipelines(self): + pipelines = self.codepipeline_backend.list_pipelines() + + return json.dumps({"pipelines": pipelines}) diff --git a/tests/test_codepipeline/test_codepipeline.py b/tests/test_codepipeline/test_codepipeline.py index f4d7e1ccb..12b3b7975 100644 --- a/tests/test_codepipeline/test_codepipeline.py +++ b/tests/test_codepipeline/test_codepipeline.py @@ -698,6 +698,121 @@ def test_update_pipeline_errors(): ) +@freeze_time("2019-01-01 12:00:00") +@mock_codepipeline +def test_list_pipelines(): + client = boto3.client("codepipeline", region_name="us-east-1") + client.create_pipeline( + pipeline={ + "name": "test-pipeline-1", + "roleArn": get_role_arn(), + "artifactStore": { + "type": "S3", + "location": "codepipeline-us-east-1-123456789012", + }, + "stages": [ + { + "name": "Stage-1", + "actions": [ + { + "name": "Action-1", + "actionTypeId": { + "category": "Source", + "owner": "AWS", + "provider": "S3", + "version": "1", + }, + "configuration": { + "S3Bucket": "test-bucket", + "S3ObjectKey": "test-object", + }, + "outputArtifacts": [{"name": "artifact"},], + }, + ], + }, + { + "name": "Stage-2", + "actions": [ + { + "name": "Action-1", + "actionTypeId": { + "category": "Approval", + "owner": "AWS", + "provider": "Manual", + "version": "1", + }, + }, + ], + }, + ], + }, + ) + client.create_pipeline( + pipeline={ + "name": "test-pipeline-2", + "roleArn": get_role_arn(), + "artifactStore": { + "type": "S3", + "location": "codepipeline-us-east-1-123456789012", + }, + "stages": [ + { + "name": "Stage-1", + "actions": [ + { + "name": "Action-1", + "actionTypeId": { + "category": "Source", + "owner": "AWS", + "provider": "S3", + "version": "1", + }, + "configuration": { + "S3Bucket": "test-bucket", + "S3ObjectKey": "test-object", + }, + "outputArtifacts": [{"name": "artifact"},], + }, + ], + }, + { + "name": "Stage-2", + "actions": [ + { + "name": "Action-1", + "actionTypeId": { + "category": "Approval", + "owner": "AWS", + "provider": "Manual", + "version": "1", + }, + }, + ], + }, + ], + }, + ) + + response = client.list_pipelines() + + response["pipelines"].should.equal( + [ + { + "name": "test-pipeline-1", + "version": 1, + "created": datetime.now(timezone.utc), + "updated": datetime.now(timezone.utc), + }, + { + "name": "test-pipeline-2", + "version": 1, + "created": datetime.now(timezone.utc), + "updated": datetime.now(timezone.utc), + }, + ] + ) + + @mock_iam def get_role_arn(): iam = boto3.client("iam", region_name="us-east-1")