2019-12-26 13:23:53 +00:00
|
|
|
import boto3
|
|
|
|
|
2021-10-18 19:44:29 +00:00
|
|
|
import sure # noqa # pylint: disable=unused-import
|
2019-12-26 13:23:53 +00:00
|
|
|
from moto import mock_codecommit
|
2020-09-13 15:08:23 +00:00
|
|
|
from moto.core import ACCOUNT_ID
|
2019-12-26 13:23:53 +00:00
|
|
|
from botocore.exceptions import ClientError
|
2020-10-06 05:54:49 +00:00
|
|
|
import pytest
|
2019-12-26 13:23:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
@mock_codecommit
|
|
|
|
def test_create_repository():
|
|
|
|
client = boto3.client("codecommit", region_name="eu-central-1")
|
|
|
|
response = client.create_repository(
|
2019-12-26 14:02:24 +00:00
|
|
|
repositoryName="repository_one", repositoryDescription="description repo one"
|
2019-12-26 13:23:53 +00: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 14:02:24 +00:00
|
|
|
response["repositoryMetadata"]["repositoryDescription"].should.equal(
|
|
|
|
"description repo one"
|
|
|
|
)
|
|
|
|
response["repositoryMetadata"]["cloneUrlSsh"].should.equal(
|
|
|
|
"ssh://git-codecommit.{0}.amazonaws.com/v1/repos/{1}".format(
|
|
|
|
"eu-central-1", "repository_one"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
response["repositoryMetadata"]["cloneUrlHttp"].should.equal(
|
|
|
|
"https://git-codecommit.{0}.amazonaws.com/v1/repos/{1}".format(
|
|
|
|
"eu-central-1", "repository_one"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
response["repositoryMetadata"]["Arn"].should.equal(
|
|
|
|
"arn:aws:codecommit:{0}:{1}:{2}".format(
|
|
|
|
"eu-central-1", ACCOUNT_ID, "repository_one"
|
|
|
|
)
|
|
|
|
)
|
2019-12-26 13:23:53 +00:00
|
|
|
response["repositoryMetadata"]["accountId"].should.equal(ACCOUNT_ID)
|
|
|
|
|
2019-12-26 15:06:53 +00:00
|
|
|
|
|
|
|
@mock_codecommit
|
|
|
|
def test_create_repository_without_description():
|
|
|
|
client = boto3.client("codecommit", region_name="eu-central-1")
|
|
|
|
|
2019-12-26 14:02:24 +00:00
|
|
|
response = client.create_repository(repositoryName="repository_two")
|
2019-12-26 13:23:53 +00:00
|
|
|
|
|
|
|
response.should_not.be.none
|
|
|
|
response.get("repositoryMetadata").should_not.be.none
|
2019-12-26 14:02:24 +00:00
|
|
|
response.get("repositoryMetadata").get("repositoryName").should.equal(
|
|
|
|
"repository_two"
|
|
|
|
)
|
2019-12-26 13:23:53 +00:00
|
|
|
response.get("repositoryMetadata").get("repositoryDescription").should.be.none
|
2019-12-26 15:06:53 +00: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(
|
|
|
|
"ssh://git-codecommit.{0}.amazonaws.com/v1/repos/{1}".format(
|
|
|
|
"eu-central-1", "repository_two"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
response["repositoryMetadata"]["cloneUrlHttp"].should.equal(
|
|
|
|
"https://git-codecommit.{0}.amazonaws.com/v1/repos/{1}".format(
|
|
|
|
"eu-central-1", "repository_two"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
response["repositoryMetadata"]["Arn"].should.equal(
|
|
|
|
"arn:aws:codecommit:{0}:{1}:{2}".format(
|
|
|
|
"eu-central-1", ACCOUNT_ID, "repository_two"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
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 13:23:53 +00:00
|
|
|
|
2020-10-06 05:54:49 +00:00
|
|
|
with pytest.raises(ClientError) as e:
|
2019-12-26 15:06:53 +00:00
|
|
|
client.create_repository(
|
|
|
|
repositoryName="repository_two",
|
|
|
|
repositoryDescription="description repo two",
|
|
|
|
)
|
2020-10-06 06:04:09 +00:00
|
|
|
ex = e.value
|
2019-12-26 13:23:53 +00:00
|
|
|
ex.operation_name.should.equal("CreateRepository")
|
|
|
|
ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
|
|
|
|
ex.response["Error"]["Code"].should.contain("RepositoryNameExistsException")
|
2019-12-26 14:02:24 +00:00
|
|
|
ex.response["Error"]["Message"].should.equal(
|
|
|
|
"Repository named {0} already exists".format("repository_two")
|
|
|
|
)
|
2019-12-26 13:23:53 +00:00
|
|
|
|
|
|
|
|
2019-12-26 15:06:53 +00:00
|
|
|
@mock_codecommit
|
|
|
|
def test_create_repository_invalid_repository_name():
|
|
|
|
client = boto3.client("codecommit", region_name="eu-central-1")
|
|
|
|
|
2020-10-06 05:54:49 +00:00
|
|
|
with pytest.raises(ClientError) as e:
|
2019-12-26 15:06:53 +00:00
|
|
|
client.create_repository(repositoryName="in_123_valid_@#$_characters")
|
2020-10-06 06:04:09 +00:00
|
|
|
ex = e.value
|
2019-12-26 15:06:53 +00: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 13:23:53 +00:00
|
|
|
@mock_codecommit
|
|
|
|
def test_get_repository():
|
|
|
|
client = boto3.client("codecommit", region_name="eu-central-1")
|
|
|
|
|
2019-12-26 14:02:24 +00:00
|
|
|
repository_name = "repository_one"
|
2019-12-26 13:23:53 +00:00
|
|
|
|
|
|
|
client.create_repository(
|
2019-12-26 14:02:24 +00:00
|
|
|
repositoryName=repository_name, repositoryDescription="description repo one"
|
2019-12-26 13:23:53 +00:00
|
|
|
)
|
|
|
|
|
2019-12-26 14:02:24 +00:00
|
|
|
response = client.get_repository(repositoryName=repository_name)
|
2019-12-26 13:23:53 +00: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 14:02:24 +00: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(
|
|
|
|
"ssh://git-codecommit.{0}.amazonaws.com/v1/repos/{1}".format(
|
|
|
|
"eu-central-1", "repository_one"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
response.get("repositoryMetadata").get("cloneUrlHttp").should.equal(
|
|
|
|
"https://git-codecommit.{0}.amazonaws.com/v1/repos/{1}".format(
|
|
|
|
"eu-central-1", "repository_one"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
response.get("repositoryMetadata").get("Arn").should.equal(
|
|
|
|
"arn:aws:codecommit:{0}:{1}:{2}".format(
|
|
|
|
"eu-central-1", ACCOUNT_ID, "repository_one"
|
|
|
|
)
|
|
|
|
)
|
2019-12-26 13:23:53 +00:00
|
|
|
response.get("repositoryMetadata").get("accountId").should.equal(ACCOUNT_ID)
|
|
|
|
|
|
|
|
client = boto3.client("codecommit", region_name="us-east-1")
|
|
|
|
|
2020-10-06 05:54:49 +00:00
|
|
|
with pytest.raises(ClientError) as e:
|
2019-12-26 14:02:24 +00:00
|
|
|
client.get_repository(repositoryName=repository_name)
|
2020-10-06 06:04:09 +00:00
|
|
|
ex = e.value
|
2019-12-26 13:23:53 +00:00
|
|
|
ex.operation_name.should.equal("GetRepository")
|
|
|
|
ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
|
|
|
|
ex.response["Error"]["Code"].should.contain("RepositoryDoesNotExistException")
|
2019-12-26 14:02:24 +00:00
|
|
|
ex.response["Error"]["Message"].should.equal(
|
|
|
|
"{0} does not exist".format(repository_name)
|
|
|
|
)
|
2019-12-26 13:23:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
@mock_codecommit
|
2019-12-26 15:06:53 +00:00
|
|
|
def test_get_repository_invalid_repository_name():
|
2019-12-26 13:23:53 +00:00
|
|
|
client = boto3.client("codecommit", region_name="eu-central-1")
|
|
|
|
|
2020-10-06 05:54:49 +00:00
|
|
|
with pytest.raises(ClientError) as e:
|
2019-12-26 15:06:53 +00:00
|
|
|
client.get_repository(repositoryName="repository_one-@#@")
|
2020-10-06 06:04:09 +00:00
|
|
|
ex = e.value
|
2019-12-26 13:23:53 +00:00
|
|
|
ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
|
|
|
|
ex.response["Error"]["Code"].should.contain("InvalidRepositoryNameException")
|
2019-12-26 14:02:24 +00: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 13:23:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
@mock_codecommit
|
|
|
|
def test_delete_repository():
|
|
|
|
client = boto3.client("codecommit", region_name="us-east-1")
|
|
|
|
|
2019-12-26 14:02:24 +00:00
|
|
|
response = client.create_repository(repositoryName="repository_one")
|
2019-12-26 13:23:53 +00:00
|
|
|
|
|
|
|
repository_id_create = response.get("repositoryMetadata").get("repositoryId")
|
|
|
|
|
2019-12-26 14:02:24 +00:00
|
|
|
response = client.delete_repository(repositoryName="repository_one")
|
2019-12-26 13:23:53 +00:00
|
|
|
|
2019-12-26 14:02:24 +00:00
|
|
|
response.get("repositoryId").should_not.be.none
|
2019-12-26 13:23:53 +00:00
|
|
|
repository_id_create.should.equal(response.get("repositoryId"))
|
|
|
|
|
2019-12-26 14:02:24 +00:00
|
|
|
response = client.delete_repository(repositoryName="unknown_repository")
|
2019-12-26 13:23:53 +00:00
|
|
|
|
2019-12-26 14:02:24 +00:00
|
|
|
response.get("repositoryId").should.be.none
|
2019-12-26 13:23:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
@mock_codecommit
|
|
|
|
def test_delete_repository_invalid_repository_name():
|
|
|
|
client = boto3.client("codecommit", region_name="us-east-1")
|
|
|
|
|
2020-10-06 05:54:49 +00:00
|
|
|
with pytest.raises(ClientError) as e:
|
2019-12-26 14:02:24 +00:00
|
|
|
client.delete_repository(repositoryName="_rep@ository_one")
|
2020-10-06 06:04:09 +00:00
|
|
|
ex = e.value
|
2019-12-26 13:23:53 +00:00
|
|
|
ex.operation_name.should.equal("DeleteRepository")
|
|
|
|
ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
|
|
|
|
ex.response["Error"]["Code"].should.contain("InvalidRepositoryNameException")
|
2019-12-26 14:02:24 +00: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. "
|
|
|
|
)
|