| 
									
										
										
										
											2019-12-26 14:23:53 +01:00
										 |  |  | import boto3 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-18 19:44:29 +00:00
										 |  |  | import sure  # noqa # pylint: disable=unused-import | 
					
						
							| 
									
										
										
										
											2019-12-26 14:23:53 +01:00
										 |  |  | from moto import mock_codecommit | 
					
						
							| 
									
										
										
										
											2022-08-13 09:49:43 +00:00
										 |  |  | from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID | 
					
						
							| 
									
										
										
										
											2019-12-26 14:23:53 +01:00
										 |  |  | from botocore.exceptions import ClientError | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  | import pytest | 
					
						
							| 
									
										
										
										
											2019-12-26 14:23:53 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_codecommit | 
					
						
							|  |  |  | def test_create_repository(): | 
					
						
							|  |  |  |     client = boto3.client("codecommit", region_name="eu-central-1") | 
					
						
							|  |  |  |     response = client.create_repository( | 
					
						
							| 
									
										
										
										
											2019-12-26 15:02:24 +01:00
										 |  |  |         repositoryName="repository_one", repositoryDescription="description repo one" | 
					
						
							| 
									
										
										
										
											2019-12-26 14:23:53 +01:00
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response.should_not.be.none | 
					
						
							|  |  |  |     response["repositoryMetadata"].should_not.be.none | 
					
						
							|  |  |  |     response["repositoryMetadata"]["creationDate"].should_not.be.none | 
					
						
							|  |  |  |     response["repositoryMetadata"]["lastModifiedDate"].should_not.be.none | 
					
						
							|  |  |  |     response["repositoryMetadata"]["repositoryId"].should_not.be.empty | 
					
						
							|  |  |  |     response["repositoryMetadata"]["repositoryName"].should.equal("repository_one") | 
					
						
							| 
									
										
										
										
											2019-12-26 15:02:24 +01:00
										 |  |  |     response["repositoryMetadata"]["repositoryDescription"].should.equal( | 
					
						
							|  |  |  |         "description repo one" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     response["repositoryMetadata"]["cloneUrlSsh"].should.equal( | 
					
						
							| 
									
										
										
										
											2022-11-17 21:41:08 -01:00
										 |  |  |         "ssh://git-codecommit.eu-central-1.amazonaws.com/v1/repos/repository_one" | 
					
						
							| 
									
										
										
										
											2019-12-26 15:02:24 +01:00
										 |  |  |     ) | 
					
						
							|  |  |  |     response["repositoryMetadata"]["cloneUrlHttp"].should.equal( | 
					
						
							| 
									
										
										
										
											2022-11-17 21:41:08 -01:00
										 |  |  |         "https://git-codecommit.eu-central-1.amazonaws.com/v1/repos/repository_one" | 
					
						
							| 
									
										
										
										
											2019-12-26 15:02:24 +01:00
										 |  |  |     ) | 
					
						
							|  |  |  |     response["repositoryMetadata"]["Arn"].should.equal( | 
					
						
							| 
									
										
										
										
											2022-11-17 21:41:08 -01:00
										 |  |  |         f"arn:aws:codecommit:eu-central-1:{ACCOUNT_ID}:repository_one" | 
					
						
							| 
									
										
										
										
											2019-12-26 15:02:24 +01:00
										 |  |  |     ) | 
					
						
							| 
									
										
										
										
											2019-12-26 14:23:53 +01:00
										 |  |  |     response["repositoryMetadata"]["accountId"].should.equal(ACCOUNT_ID) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-26 16:06:53 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | @mock_codecommit | 
					
						
							|  |  |  | def test_create_repository_without_description(): | 
					
						
							|  |  |  |     client = boto3.client("codecommit", region_name="eu-central-1") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-26 15:02:24 +01:00
										 |  |  |     response = client.create_repository(repositoryName="repository_two") | 
					
						
							| 
									
										
										
										
											2019-12-26 14:23:53 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     response.should_not.be.none | 
					
						
							|  |  |  |     response.get("repositoryMetadata").should_not.be.none | 
					
						
							| 
									
										
										
										
											2019-12-26 15:02:24 +01:00
										 |  |  |     response.get("repositoryMetadata").get("repositoryName").should.equal( | 
					
						
							|  |  |  |         "repository_two" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2019-12-26 14:23:53 +01:00
										 |  |  |     response.get("repositoryMetadata").get("repositoryDescription").should.be.none | 
					
						
							| 
									
										
										
										
											2019-12-26 16:06:53 +01:00
										 |  |  |     response["repositoryMetadata"].should_not.be.none | 
					
						
							|  |  |  |     response["repositoryMetadata"]["creationDate"].should_not.be.none | 
					
						
							|  |  |  |     response["repositoryMetadata"]["lastModifiedDate"].should_not.be.none | 
					
						
							|  |  |  |     response["repositoryMetadata"]["repositoryId"].should_not.be.empty | 
					
						
							|  |  |  |     response["repositoryMetadata"]["cloneUrlSsh"].should.equal( | 
					
						
							| 
									
										
										
										
											2022-11-17 21:41:08 -01:00
										 |  |  |         "ssh://git-codecommit.eu-central-1.amazonaws.com/v1/repos/repository_two" | 
					
						
							| 
									
										
										
										
											2019-12-26 16:06:53 +01:00
										 |  |  |     ) | 
					
						
							|  |  |  |     response["repositoryMetadata"]["cloneUrlHttp"].should.equal( | 
					
						
							| 
									
										
										
										
											2022-11-17 21:41:08 -01:00
										 |  |  |         "https://git-codecommit.eu-central-1.amazonaws.com/v1/repos/repository_two" | 
					
						
							| 
									
										
										
										
											2019-12-26 16:06:53 +01:00
										 |  |  |     ) | 
					
						
							|  |  |  |     response["repositoryMetadata"]["Arn"].should.equal( | 
					
						
							| 
									
										
										
										
											2022-11-17 21:41:08 -01:00
										 |  |  |         f"arn:aws:codecommit:eu-central-1:{ACCOUNT_ID}:repository_two" | 
					
						
							| 
									
										
										
										
											2019-12-26 16:06:53 +01:00
										 |  |  |     ) | 
					
						
							|  |  |  |     response["repositoryMetadata"]["accountId"].should.equal(ACCOUNT_ID) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_codecommit | 
					
						
							|  |  |  | def test_create_repository_repository_name_exists(): | 
					
						
							|  |  |  |     client = boto3.client("codecommit", region_name="eu-central-1") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     client.create_repository(repositoryName="repository_two") | 
					
						
							| 
									
										
										
										
											2019-12-26 14:23:53 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(ClientError) as e: | 
					
						
							| 
									
										
										
										
											2019-12-26 16:06:53 +01:00
										 |  |  |         client.create_repository( | 
					
						
							|  |  |  |             repositoryName="repository_two", | 
					
						
							|  |  |  |             repositoryDescription="description repo two", | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     ex = e.value | 
					
						
							| 
									
										
										
										
											2019-12-26 14:23:53 +01:00
										 |  |  |     ex.operation_name.should.equal("CreateRepository") | 
					
						
							|  |  |  |     ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) | 
					
						
							|  |  |  |     ex.response["Error"]["Code"].should.contain("RepositoryNameExistsException") | 
					
						
							| 
									
										
										
										
											2019-12-26 15:02:24 +01:00
										 |  |  |     ex.response["Error"]["Message"].should.equal( | 
					
						
							| 
									
										
										
										
											2022-11-17 21:41:08 -01:00
										 |  |  |         "Repository named repository_two already exists" | 
					
						
							| 
									
										
										
										
											2019-12-26 15:02:24 +01:00
										 |  |  |     ) | 
					
						
							| 
									
										
										
										
											2019-12-26 14:23:53 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-26 16:06:53 +01:00
										 |  |  | @mock_codecommit | 
					
						
							|  |  |  | def test_create_repository_invalid_repository_name(): | 
					
						
							|  |  |  |     client = boto3.client("codecommit", region_name="eu-central-1") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(ClientError) as e: | 
					
						
							| 
									
										
										
										
											2019-12-26 16:06:53 +01:00
										 |  |  |         client.create_repository(repositoryName="in_123_valid_@#$_characters") | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     ex = e.value | 
					
						
							| 
									
										
										
										
											2019-12-26 16:06:53 +01:00
										 |  |  |     ex.operation_name.should.equal("CreateRepository") | 
					
						
							|  |  |  |     ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) | 
					
						
							|  |  |  |     ex.response["Error"]["Code"].should.contain("InvalidRepositoryNameException") | 
					
						
							|  |  |  |     ex.response["Error"]["Message"].should.equal( | 
					
						
							|  |  |  |         "The repository name is not valid. Repository names can be any valid " | 
					
						
							|  |  |  |         "combination of letters, numbers, " | 
					
						
							|  |  |  |         "periods, underscores, and dashes between 1 and 100 characters in " | 
					
						
							|  |  |  |         "length. Names are case sensitive. " | 
					
						
							|  |  |  |         "For more information, see Limits in the AWS CodeCommit User Guide. " | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-26 14:23:53 +01:00
										 |  |  | @mock_codecommit | 
					
						
							|  |  |  | def test_get_repository(): | 
					
						
							|  |  |  |     client = boto3.client("codecommit", region_name="eu-central-1") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-26 15:02:24 +01:00
										 |  |  |     repository_name = "repository_one" | 
					
						
							| 
									
										
										
										
											2019-12-26 14:23:53 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     client.create_repository( | 
					
						
							| 
									
										
										
										
											2019-12-26 15:02:24 +01:00
										 |  |  |         repositoryName=repository_name, repositoryDescription="description repo one" | 
					
						
							| 
									
										
										
										
											2019-12-26 14:23:53 +01:00
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-26 15:02:24 +01:00
										 |  |  |     response = client.get_repository(repositoryName=repository_name) | 
					
						
							| 
									
										
										
										
											2019-12-26 14:23:53 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     response.should_not.be.none | 
					
						
							|  |  |  |     response.get("repositoryMetadata").should_not.be.none | 
					
						
							|  |  |  |     response.get("repositoryMetadata").get("creationDate").should_not.be.none | 
					
						
							|  |  |  |     response.get("repositoryMetadata").get("lastModifiedDate").should_not.be.none | 
					
						
							|  |  |  |     response.get("repositoryMetadata").get("repositoryId").should_not.be.empty | 
					
						
							| 
									
										
										
										
											2019-12-26 15:02:24 +01:00
										 |  |  |     response.get("repositoryMetadata").get("repositoryName").should.equal( | 
					
						
							|  |  |  |         repository_name | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     response.get("repositoryMetadata").get("repositoryDescription").should.equal( | 
					
						
							|  |  |  |         "description repo one" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     response.get("repositoryMetadata").get("cloneUrlSsh").should.equal( | 
					
						
							| 
									
										
										
										
											2022-11-17 21:41:08 -01:00
										 |  |  |         "ssh://git-codecommit.eu-central-1.amazonaws.com/v1/repos/repository_one" | 
					
						
							| 
									
										
										
										
											2019-12-26 15:02:24 +01:00
										 |  |  |     ) | 
					
						
							|  |  |  |     response.get("repositoryMetadata").get("cloneUrlHttp").should.equal( | 
					
						
							| 
									
										
										
										
											2022-11-17 21:41:08 -01:00
										 |  |  |         "https://git-codecommit.eu-central-1.amazonaws.com/v1/repos/repository_one" | 
					
						
							| 
									
										
										
										
											2019-12-26 15:02:24 +01:00
										 |  |  |     ) | 
					
						
							|  |  |  |     response.get("repositoryMetadata").get("Arn").should.equal( | 
					
						
							| 
									
										
										
										
											2022-11-17 21:41:08 -01:00
										 |  |  |         f"arn:aws:codecommit:eu-central-1:{ACCOUNT_ID}:repository_one" | 
					
						
							| 
									
										
										
										
											2019-12-26 15:02:24 +01:00
										 |  |  |     ) | 
					
						
							| 
									
										
										
										
											2019-12-26 14:23:53 +01:00
										 |  |  |     response.get("repositoryMetadata").get("accountId").should.equal(ACCOUNT_ID) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     client = boto3.client("codecommit", region_name="us-east-1") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(ClientError) as e: | 
					
						
							| 
									
										
										
										
											2019-12-26 15:02:24 +01:00
										 |  |  |         client.get_repository(repositoryName=repository_name) | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     ex = e.value | 
					
						
							| 
									
										
										
										
											2019-12-26 14:23:53 +01:00
										 |  |  |     ex.operation_name.should.equal("GetRepository") | 
					
						
							|  |  |  |     ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) | 
					
						
							|  |  |  |     ex.response["Error"]["Code"].should.contain("RepositoryDoesNotExistException") | 
					
						
							| 
									
										
										
										
											2022-11-17 21:41:08 -01:00
										 |  |  |     ex.response["Error"]["Message"].should.equal(f"{repository_name} does not exist") | 
					
						
							| 
									
										
										
										
											2019-12-26 14:23:53 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_codecommit | 
					
						
							| 
									
										
										
										
											2019-12-26 16:06:53 +01:00
										 |  |  | def test_get_repository_invalid_repository_name(): | 
					
						
							| 
									
										
										
										
											2019-12-26 14:23:53 +01:00
										 |  |  |     client = boto3.client("codecommit", region_name="eu-central-1") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(ClientError) as e: | 
					
						
							| 
									
										
										
										
											2019-12-26 16:06:53 +01:00
										 |  |  |         client.get_repository(repositoryName="repository_one-@#@") | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     ex = e.value | 
					
						
							| 
									
										
										
										
											2019-12-26 14:23:53 +01:00
										 |  |  |     ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) | 
					
						
							|  |  |  |     ex.response["Error"]["Code"].should.contain("InvalidRepositoryNameException") | 
					
						
							| 
									
										
										
										
											2019-12-26 15:02:24 +01:00
										 |  |  |     ex.response["Error"]["Message"].should.equal( | 
					
						
							|  |  |  |         "The repository name is not valid. Repository names can be any valid " | 
					
						
							|  |  |  |         "combination of letters, numbers, " | 
					
						
							|  |  |  |         "periods, underscores, and dashes between 1 and 100 characters in " | 
					
						
							|  |  |  |         "length. Names are case sensitive. " | 
					
						
							|  |  |  |         "For more information, see Limits in the AWS CodeCommit User Guide. " | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2019-12-26 14:23:53 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_codecommit | 
					
						
							|  |  |  | def test_delete_repository(): | 
					
						
							|  |  |  |     client = boto3.client("codecommit", region_name="us-east-1") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-26 15:02:24 +01:00
										 |  |  |     response = client.create_repository(repositoryName="repository_one") | 
					
						
							| 
									
										
										
										
											2019-12-26 14:23:53 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     repository_id_create = response.get("repositoryMetadata").get("repositoryId") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-26 15:02:24 +01:00
										 |  |  |     response = client.delete_repository(repositoryName="repository_one") | 
					
						
							| 
									
										
										
										
											2019-12-26 14:23:53 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-26 15:02:24 +01:00
										 |  |  |     response.get("repositoryId").should_not.be.none | 
					
						
							| 
									
										
										
										
											2019-12-26 14:23:53 +01:00
										 |  |  |     repository_id_create.should.equal(response.get("repositoryId")) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-26 15:02:24 +01:00
										 |  |  |     response = client.delete_repository(repositoryName="unknown_repository") | 
					
						
							| 
									
										
										
										
											2019-12-26 14:23:53 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-26 15:02:24 +01:00
										 |  |  |     response.get("repositoryId").should.be.none | 
					
						
							| 
									
										
										
										
											2019-12-26 14:23:53 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_codecommit | 
					
						
							|  |  |  | def test_delete_repository_invalid_repository_name(): | 
					
						
							|  |  |  |     client = boto3.client("codecommit", region_name="us-east-1") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(ClientError) as e: | 
					
						
							| 
									
										
										
										
											2019-12-26 15:02:24 +01:00
										 |  |  |         client.delete_repository(repositoryName="_rep@ository_one") | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     ex = e.value | 
					
						
							| 
									
										
										
										
											2019-12-26 14:23:53 +01:00
										 |  |  |     ex.operation_name.should.equal("DeleteRepository") | 
					
						
							|  |  |  |     ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) | 
					
						
							|  |  |  |     ex.response["Error"]["Code"].should.contain("InvalidRepositoryNameException") | 
					
						
							| 
									
										
										
										
											2019-12-26 15:02:24 +01:00
										 |  |  |     ex.response["Error"]["Message"].should.equal( | 
					
						
							|  |  |  |         "The repository name is not valid. Repository names can be any valid " | 
					
						
							|  |  |  |         "combination of letters, numbers, " | 
					
						
							|  |  |  |         "periods, underscores, and dashes between 1 and 100 characters in " | 
					
						
							|  |  |  |         "length. Names are case sensitive. " | 
					
						
							|  |  |  |         "For more information, see Limits in the AWS CodeCommit User Guide. " | 
					
						
							|  |  |  |     ) |