Exemplo n.º 1
0
 def test_init_ecr(self, mocker):
     # type: ("MockerFixture") -> None
     """Test init ecr."""
     context = MagicMock()
     registry = ElasticContainerRegistry(account_id="123456012",
                                         aws_region="us-east-1")
     mock_determine_registry = mocker.patch.object(
         LoginArgs,
         "determine_registry",
         return_value=registry.fqn,
     )
     args = {
         "ecr": {
             "account_id": "123456012",
             "aws_region": "us-east-1"
         },
         "password": "******",
     }
     obj = LoginArgs.parse_obj(deepcopy(args), context=context)
     mock_determine_registry.assert_called_once_with(context=context,
                                                     ecr=args["ecr"],
                                                     registry=None)
     assert not obj.dockercfg_path
     assert not obj.email
     assert obj.password == args["password"]
     assert obj.registry == registry.fqn
     assert obj.username == "AWS"
Exemplo n.º 2
0
 def test_init_public(self) -> None:
     """Test init public."""
     obj = ElasticContainerRegistry(alias="test")
     assert obj.account_id is None
     assert obj.alias == "test"
     assert obj.region is None
     assert obj.public
Exemplo n.º 3
0
 def test_init_private(self) -> None:
     """Test init private."""
     account_id = "123456789012"
     region = "us-east-1"
     obj = ElasticContainerRegistry(account_id=account_id, aws_region=region)
     assert obj.account_id == account_id
     assert obj.alias is None
     assert obj.region == region
     assert not obj.public
Exemplo n.º 4
0
 def test_determine_registry_ecr(self, mocker):
     # type: ("MockerFixture") -> None
     """Test determine_registry ecr."""
     registry = ElasticContainerRegistry(account_id="123456012",
                                         aws_region="us-east-1")
     mocker.patch(
         MODULE + ".ElasticContainerRegistry",
         parse_obj=MagicMock(return_value=registry),
     )
     assert (LoginArgs.determine_registry(context=None,
                                          ecr=True,
                                          registry=None) == registry.fqn)
Exemplo n.º 5
0
    def test_init_default(self, cfngin_context: MockCFNginContext) -> None:
        """Test init default values."""
        account_id = "123456789012"
        sts_stubber = cfngin_context.add_stubber("sts")
        sts_stubber.add_response(
            "get_caller_identity",
            {
                "UserId": "str",
                "Account": account_id,
                "Arn": "arn:aws:iam:::user/test-user",
            },
        )

        with sts_stubber:
            obj = ElasticContainerRegistry(context=cfngin_context)
        sts_stubber.assert_no_pending_responses()
        assert obj.account_id == account_id
        assert obj.alias is None
        assert obj.region == cfngin_context.env.aws_region
        assert not obj.public
Exemplo n.º 6
0
 def test_init_no_context(self) -> None:
     """Test init with no context."""
     with pytest.raises(ValueError) as excinfo:
         ElasticContainerRegistry()
     assert str(excinfo.value) == "context is required to resolve values"
Exemplo n.º 7
0
 def test_fqn_public(self) -> None:
     """Test fqn public."""
     obj = ElasticContainerRegistry(alias="test")
     assert obj.fqn == "public.ecr.aws/test/"
Exemplo n.º 8
0
 def test_fqn_private(self) -> None:
     """Test fqn private."""
     obj = ElasticContainerRegistry(
         account_id="123456789012", aws_region="us-east-1"
     )
     assert obj.fqn == "123456789012.dkr.ecr.us-east-1.amazonaws.com/"