Beispiel #1
0
 def setUp(self):
     self.freight_forwarder = FreightForwarder(
         config_path_override=os.path.join(os.getcwd(),
                                           'tests',
                                           'fixtures',
                                           'test_freight_forwarder.yaml'),
         verbose=False
     )
class CommercialInvoiceCreateContainershipsTest(unittest.TestCase):
    def setUp(self):
        self.freight_forwarder = FreightForwarder(
            config_path_override=os.path.join(os.getcwd(), 'tests', 'fixtures',
                                              'test_freight_forwarder.yaml'),
            verbose=False)

    def tearDown(self):
        del self.freight_forwarder

    @mock.patch.object(CommercialInvoice, '_create_registries', autospec=True)
    @mock.patch(
        'freight_forwarder.commercial_invoice.commercial_invoice.ContainerShip',
        create=True)
    def test_create_containerships_with_deploy(self, mock_container_ship,
                                               mocked_create_registries):
        """
        Validate the deployment host or hosts is available inside the commercial invoice
        :param mock_container_ship:
        :param mocked_create_registries:
        :return:
        """
        commercial_invoice = self.freight_forwarder.commercial_invoice(
            'deploy', 'local', 'development', 'tomcat-test')
        self.assertEqual(len(commercial_invoice.container_ships), 3)
        self.assertIn('tomcat-test', commercial_invoice.container_ships.keys())
        self.assertEqual(
            len(commercial_invoice.container_ships['tomcat-test']), 1)

    @mock.patch.object(CommercialInvoice, '_create_registries', autospec=True)
    @mock.patch(
        'freight_forwarder.commercial_invoice.commercial_invoice.ContainerShip',
        create=True)
    @mock.patch('freight_forwarder.commercial_invoice.commercial_invoice.os')
    def test_create_containerships_with_no_default(self, mock_os,
                                                   mock_container_ship,
                                                   mocked_create_registries):
        """
        Validate the the container_ship creation with no default defined in the configuration
        :param mock_container_ship:
        :param mocked_create_registries:
        :return:
        """
        # Remove default hosts to ensure it is created
        hosts = self.freight_forwarder._config.get('hosts', 'environments',
                                                   'development', 'local')
        del hosts['default']

        commercial_invoice = self.freight_forwarder.commercial_invoice(
            'deploy', 'local', 'development', 'tomcat-test')
        self.assertEqual(mock_os.getenv.call_count, 3)
        calls = [
            call('DOCKER_TLS_VERIFY'),
            call('DOCKER_CERT_PATH'),
            call('DOCKER_HOST')
        ]
        mock_os.getenv.assert_has_call(calls, any_order=True)
class CommercialInvoiceCreateContainershipsTest(unittest.TestCase):
    def setUp(self):
        self.freight_forwarder = FreightForwarder(
            config_path_override=os.path.join(os.getcwd(),
                                              'tests',
                                              'fixtures',
                                              'test_freight_forwarder.yaml'),
            verbose=False
        )

    def tearDown(self):
        del self.freight_forwarder

    @mock.patch.object(CommercialInvoice, '_create_registries', autospec=True)
    @mock.patch('freight_forwarder.commercial_invoice.commercial_invoice.ContainerShip', create=True)
    def test_create_containerships_with_deploy(self, mock_container_ship, mocked_create_registries):
        """
        Validate the deployment host or hosts is available inside the commercial invoice
        :param mock_container_ship:
        :param mocked_create_registries:
        :return:
        """
        commercial_invoice = self.freight_forwarder.commercial_invoice(
            'deploy',
            'local',
            'development',
            'tomcat-test'
        )
        self.assertEqual(len(commercial_invoice.container_ships), 3)
        self.assertIn('tomcat-test', commercial_invoice.container_ships.keys())
        self.assertEqual(len(commercial_invoice.container_ships['tomcat-test']), 1)

    @mock.patch.object(CommercialInvoice, '_create_registries', autospec=True)
    @mock.patch('freight_forwarder.commercial_invoice.commercial_invoice.ContainerShip', create=True)
    @mock.patch('freight_forwarder.commercial_invoice.commercial_invoice.os')
    def test_create_containerships_with_no_default(self, mock_os, mock_container_ship, mocked_create_registries):
        """
        Validate the the container_ship creation with no default defined in the configuration
        :param mock_container_ship:
        :param mocked_create_registries:
        :return:
        """
        # Remove default hosts to ensure it is created
        hosts = self.freight_forwarder._config.get('hosts', 'environments', 'development', 'local')
        del hosts['default']

        commercial_invoice = self.freight_forwarder.commercial_invoice(
            'deploy',
            'local',
            'development',
            'tomcat-test'
        )
        self.assertEqual(mock_os.getenv.call_count, 3)
        calls =  [call('DOCKER_TLS_VERIFY'), call('DOCKER_CERT_PATH'), call('DOCKER_HOST')]
        mock_os.getenv.assert_has_call(calls, any_order=True)
 def setUp(self):
     self.freight_forwarder = FreightForwarder(
         config_path_override=os.path.join(os.getcwd(),
                                           'tests',
                                           'fixtures',
                                           'test_freight_forwarder.yaml'),
         verbose=False
     )
Beispiel #5
0
class CommercialInvoiceCreateContainershipsTest(unittest.TestCase):
    def setUp(self):
        self.freight_forwarder = FreightForwarder(
            config_path_override=os.path.join(os.getcwd(),
                                              'tests',
                                              'fixtures',
                                              'test_freight_forwarder.yaml'),
            verbose=False
        )

    def tearDown(self):
        del self.freight_forwarder

    @mock.patch.object(CommercialInvoice, '_create_registries', autospec=True)
    @mock.patch('freight_forwarder.commercial_invoice.commercial_invoice.ContainerShip', create=True)
    def test_create_containerships_with_deploy(self, mock_container_ship, mocked_create_registries):
        """
        Validate the deployment host or hosts is available inside the commercial invoice
        :param mock_container_ship:
        :param mocked_create_registries:
        :return:
        """
        commercial_invoice = self.freight_forwarder.commercial_invoice(
            action='deploy',
            data_center='local',
            environment='development',
            transport_service='tomcat-test'
        )
        self.assertEqual(len(commercial_invoice.container_ships), 3)
        self.assertIn('tomcat_test', commercial_invoice.container_ships.keys())
        self.assertEqual(len(commercial_invoice.container_ships['tomcat_test']), 1)

    @mock.patch.object(CommercialInvoice, '_create_registries', autospec=True)
    @mock.patch('freight_forwarder.commercial_invoice.commercial_invoice.ContainerShip', create=True)
    @mock.patch('freight_forwarder.commercial_invoice.commercial_invoice.os')
    def test_create_containerships_with_no_default(self, mock_os, mock_container_ship, mocked_create_registries):
        """
        Validate the the container_ship creation with no default defined in the configuration
        :param mock_container_ship:
        :param mocked_create_registries:
        :return:
        """
        # Remove default hosts to ensure it is created
        hosts = self.freight_forwarder._config.get('hosts', 'environments', 'development', 'local')
        del hosts['default']

        self.freight_forwarder.commercial_invoice(
            action='deploy',
            data_center='local',
            environment='development',
            transport_service='tomcat-test'
        )
        self.assertEqual(mock_os.getenv.call_count, 3)
        calls = [call('DOCKER_TLS_VERIFY'), call('DOCKER_CERT_PATH'), call('DOCKER_HOST')]
        mock_os.getenv.assert_has_call(calls, any_order=True)

    @mock.patch.object(CommercialInvoice, '_create_registries', autospec=True)
    @mock.patch('freight_forwarder.commercial_invoice.commercial_invoice.ContainerShip', create=True)
    def test_create_containerships_using_yaml_variables(self, mock_container_ship, mocked_create_registries):
        """
        While utilizing variables for various hosts, ensure that all the necessary keys are present
        :param mock_container_ship:
        :param mocked_create_registries:
        :return:
        """
        self.freight_forwarder.config

        commercial_invoice = self.freight_forwarder.commercial_invoice(
            action='deploy',
            data_center='local',
            environment='staging',
            transport_service='tomcat-test'
        )
        container_ships = commercial_invoice.container_ships.keys()
        self.assertEqual(len(commercial_invoice.container_ships), 4)
        self.assertIn('tomcat_test', container_ships)
        self.assertIn('redis_srv', container_ships)
        self.assertIn('https://192.168.99.100:2376', commercial_invoice.container_ships.get('tomcat_test').keys())
        self.assertIn('https://192.168.99.100:2376', commercial_invoice.container_ships.get('default').keys())
        self.assertIn('https://192.168.99.100:2376', commercial_invoice.container_ships.get('export').keys())
        self.assertIn('https://redis_srv.example.com:2376', commercial_invoice.container_ships.get('redis_srv').keys())