コード例 #1
0
class TestECSbuilder(unittest.TestCase):
    """
    Test the ECSBuilder
    """
    def setUp(self):
        self.commit = Commit(
            commit_hash='master',
            repository="adsws"
        )
        self.build = Build(commit=self.commit)
        self.containers = [
            ECSBuilder.DockerContainer(
                self.build,
                environment="staging",
                memory=m,
                portmappings=[{
                    "hostPort": 8080,
                    "containerPort": 80}] if m == 10 else None
            ) for m in range(10, 50, 10)
        ]
        self.builder = ECSBuilder(self.containers, family="unittest")

    def test_init(self):
        """
        Initialized ECSBuilder should have a template and containers attribute
        of the appropriate types
        """
        self.assertIsInstance(
            self.builder.containers[0],
            ECSBuilder.DockerContainer
        )
        self.assertEqual(self.builder.containers, self.containers)
        self.assertIsInstance(
            self.builder.templates,
            jinja2.environment.Environment
        )

    def test_render_template(self):
        """
        instance method render_template should return a json template based
        on base.aws.template
        """
        t = self.builder.render_template()
        self.assertIsInstance(t, basestring)
        try:
            j = json.loads(t)
        except ValueError:
            print("Could not load json: {}".format(t))
            raise
        self.assertIn(self.commit.repository, t)
        for container in self.containers:
            self.assertIn("{}".format(container.memory), t)
            if container.portmappings is not None:
                self.assertEqual(
                    j['containerDefinitions'][self.containers.index(container)]['portMappings'],
                    container.portmappings,
                )
コード例 #2
0
class TestECSbuilder(unittest.TestCase):
    """
    Test the ECSBuilder
    """
    def setUp(self):
        self.commit = Commit(commit_hash='master', repository="adsws")
        self.build = Build(commit=self.commit)
        self.containers = [
            ECSBuilder.DockerContainer(self.build,
                                       environment="staging",
                                       memory=m,
                                       portmappings=[{
                                           "hostPort": 8080,
                                           "containerPort": 80
                                       }] if m == 10 else None)
            for m in range(10, 50, 10)
        ]
        self.builder = ECSBuilder(self.containers, family="unittest")

    def test_init(self):
        """
        Initialized ECSBuilder should have a template and containers attribute
        of the appropriate types
        """
        self.assertIsInstance(self.builder.containers[0],
                              ECSBuilder.DockerContainer)
        self.assertEqual(self.builder.containers, self.containers)
        self.assertIsInstance(self.builder.templates,
                              jinja2.environment.Environment)

    def test_render_template(self):
        """
        instance method render_template should return a json template based
        on base.aws.template
        """
        t = self.builder.render_template()
        self.assertIsInstance(t, basestring)
        try:
            j = json.loads(t)
        except ValueError:
            print("Could not load json: {}".format(t))
            raise
        self.assertIn(self.commit.repository, t)
        for container in self.containers:
            self.assertIn("{}".format(container.memory), t)
            if container.portmappings is not None:
                self.assertEqual(
                    j['containerDefinitions'][self.containers.index(container)]
                    ['portMappings'],
                    container.portmappings,
                )