# Path: scar/providers/aws/ecr.py
# class ECR(GenericClient):
#     """Manages the AWS ElasticContainerRegistry functionality"""
# 
#     def __init__(self, resources_info: Dict):
#         super().__init__()
#         self.resources_info = resources_info
# 
#     def get_authorization_token(self) -> str:
#         """Retrieves an authorization token."""
#         return self.client.get_authorization_token()
# 
#     def get_registry_url(self) -> str:
#         """Retrieves the registry URL."""
#         registry_id = self.client.get_registry_id()
#         return "%s.dkr.ecr.us-east-1.amazonaws.com" % registry_id
# 
#     def get_repository_uri(self, repository_name: str) -> str:
#         """Check if a repository exists."""
#         response = self.client.describe_repositories(repositoryNames=[repository_name])
#         if response:
#             return response["repositories"][0]["repositoryUri"]
#         else:
#             return None
# 
#     def create_repository(self, repository_name: str) -> str:
#         """Creates a repository."""
#         response = self.client.create_repository(repository_name)
#         return response["repository"]["repositoryUri"]
# 
#     def delete_repository(self, repository_name: str):
#         self.client.delete_repository(repository_name)


import unittest
import sys
import os
from mock import MagicMock
from mock import patch, call
from scar.providers.aws.ecr import ECR


class TestECR(unittest.TestCase):

    def __init__(self, *args):
        os.environ["AWS_DEFAULT_REGION"] = "us-east-1"
        unittest.TestCase.__init__(self, *args)

    def test_init(self):
        ecr = ECR({})
        self.assertEqual(type(ecr.client.client).__name__, "ECR")

    @staticmethod
    def _init_mocks(call_list):
        session = MagicMock(['client'])
        client = MagicMock(call_list)
        session.client.return_value = client
        return session

    @patch('boto3.Session')
    def test_get_authorization_token(self, boto_session):
        boto_session.return_value = self._init_mocks(['get_authorization_token'])
        ecr = ECR({})
        token = "QVdTOnRva2Vu"
        ecr.client.client.get_authorization_token.return_value = {'authorizationData': [{'authorizationToken': token}]}
        self.assertEqual(ecr.get_authorization_token(), ["AWS", "token"])

    @patch('boto3.Session')
    def test_get_registry_url(self, boto_session):
        boto_session.return_value = self._init_mocks(['describe_registry'])

# Path: scar/providers/aws/ecr.py
# class ECR(GenericClient):
#     """Manages the AWS ElasticContainerRegistry functionality"""
# 
#     def __init__(self, resources_info: Dict):
#         super().__init__()
#         self.resources_info = resources_info
# 
#     def get_authorization_token(self) -> str:
#         """Retrieves an authorization token."""
#         return self.client.get_authorization_token()
# 
#     def get_registry_url(self) -> str:
#         """Retrieves the registry URL."""
#         registry_id = self.client.get_registry_id()
#         return "%s.dkr.ecr.us-east-1.amazonaws.com" % registry_id
# 
#     def get_repository_uri(self, repository_name: str) -> str:
#         """Check if a repository exists."""
#         response = self.client.describe_repositories(repositoryNames=[repository_name])
#         if response:
#             return response["repositories"][0]["repositoryUri"]
#         else:
#             return None
# 
#     def create_repository(self, repository_name: str) -> str:
#         """Creates a repository."""
#         response = self.client.create_repository(repository_name)
#         return response["repository"]["repositoryUri"]
# 
#     def delete_repository(self, repository_name: str):
#         self.client.delete_repository(repository_name)


# Path: test/unit/aws/test_ecr.py
import unittest
import sys
import os
from mock import MagicMock
from mock import patch, call
from scar.providers.aws.ecr import ECR



class TestECR(unittest.TestCase):

    def __init__(self, *args):
        os.environ["AWS_DEFAULT_REGION"] = "us-east-1"
        unittest.TestCase.__init__(self, *args)

    def test_init(self):
        ecr = ECR({})
        self.assertEqual(type(ecr.client.client).__name__, "ECR")

    @staticmethod
    def _init_mocks(call_list):
        session = MagicMock(['client'])
        client = MagicMock(call_list)
        session.client.return_value = client
        return session

    @patch('boto3.Session')
    def test_get_authorization_token(self, boto_session):
        boto_session.return_value = self._init_mocks(['get_authorization_token'])
        ecr = ECR({})
        token = "QVdTOnRva2Vu"
        ecr.client.client.get_authorization_token.return_value = {'authorizationData': [{'authorizationToken': token}]}
        self.assertEqual(ecr.get_authorization_token(), ["AWS", "token"])

    @patch('boto3.Session')
    def test_get_registry_url(self, boto_session):
        boto_session.return_value = self._init_mocks(['describe_registry'])

        ecr = ECR({})