def test_cm_ip_postgis(self): cm = cli_docker_commands.PostGisContainerMetadata() expected_msg = "\nPostGIS/Database:" \ "\n Host: 127.0.0.1" \ "\n Port: 5435" \ "\n Endpoint: postgresql://<username>:<password>@127.0.0.1:5435/<database>" self.assertEqual(expected_msg, cm.ip)
def test_container_metadata_is_installed(self, mock_container): mock_container.return_value = None cm = cli_docker_commands.PostGisContainerMetadata() self.assertFalse(cm.is_installed) mock_container.return_value = mock.Mock() self.assertTrue(cm.is_installed)
def test_cm_get_container_options_postgis(self, mock_default_options, mock_getpass, mock_pretty_output): mock_default_options.return_value = dict(environment={}) mock_getpass.side_effect = [ 'pass', # tethys_default password 'passmgr', # tethys_db_manager password 'passmgr', # tethys_super password ] expected_environment = dict( TETHYS_DEFAULT_PASS='******', TETHYS_DB_MANAGER_PASS='******', TETHYS_SUPER_PASS='******', ) container = cli_docker_commands.PostGisContainerMetadata() self.assertDictEqual( expected_environment, container.get_container_options(defaults=False)['environment']) po_call_args = mock_pretty_output.call_args_list self.assertEqual(1, len(po_call_args)) self.assertIn( 'Provide passwords for the three Tethys database users or press enter', po_call_args[0][0][0]) mock_default_options.assert_called()
def test_cm_remove(self, mock_pretty_output): container = cli_docker_commands.PostGisContainerMetadata() container.remove() po_call_args = mock_pretty_output.call_args_list self.assertEqual(1, len(po_call_args)) self.assertIn('Removing PostGIS/Database container...', po_call_args[0][0][0]) self.mock_dc.containers.get().remove.assert_called()
def test_cm_stop(self, mock_pretty_output): container = cli_docker_commands.PostGisContainerMetadata() msg = container.stop() self.assertIsNone(msg) po_call_args = mock_pretty_output.call_args_list self.assertEqual(1, len(po_call_args)) self.assertIn('Stopping PostGIS/Database container...', po_call_args[0][0][0]) self.mock_dc.containers.get().stop.assert_called()
def test_cm_stop_excpetion(self, mock_pretty_output): self.mock_dc.containers.get().stop.side_effect = Exception container = cli_docker_commands.PostGisContainerMetadata() msg = container.stop() self.assertIn('There was an error while attempting to stop container', msg) po_call_args = mock_pretty_output.call_args_list self.assertEqual(1, len(po_call_args)) self.assertIn('Stopping PostGIS/Database container...', po_call_args[0][0][0]) self.mock_dc.containers.get().stop.assert_called()
def test_cm_create(self, mock_get_options, mock_pretty_output): mock_get_options.return_value = dict(host_config={}) container = cli_docker_commands.PostGisContainerMetadata() container.create() po_call_args = mock_pretty_output.call_args_list self.assertEqual(1, len(po_call_args)) self.assertIn('\nInstalling the PostGIS/Database Docker container...', po_call_args[0][0][0]) mock_get_options.assert_called_with(False) self.mock_dc.api.create_host_config.assert_called_with() self.mock_dc.api.create_container.assert_called()
def test_cm_default_container_options_postgis(self, mock_port_bindings_prop): mock_port_bindings = mock.Mock() mock_port_bindings_prop.return_value = mock_port_bindings expected_options = dict( name='tethys_postgis', image='ciwater/postgis:2.1.2', environment=dict( TETHYS_DEFAULT_PASS='******', TETHYS_DB_MANAGER_PASS='******', TETHYS_SUPER_PASS='******', ), host_config=dict(port_bindings=mock_port_bindings), ) container = cli_docker_commands.PostGisContainerMetadata() self.assertDictEqual(expected_options, container.default_container_options())
def test_container_metadata_container_exception(self): self.mock_dc.containers.get.side_effect = cli_docker_commands.DockerNotFound( 'test') cm = cli_docker_commands.PostGisContainerMetadata() self.assertIsNone(cm.container)
def test_container_metadata_container(self): mock_container = mock.MagicMock() self.mock_dc.containers.get.return_value = mock_container cm = cli_docker_commands.PostGisContainerMetadata() self.assertEqual(mock_container, cm.container)
def test_cm_pull(self, mock_image, mock_pull_stream): container = cli_docker_commands.PostGisContainerMetadata() container.pull() self.mock_dc.api.pull.assert_called_with(mock_image.return_value, stream=True) mock_pull_stream.assert_called()
def test_port_bindings_postgis(self): cm = cli_docker_commands.PostGisContainerMetadata() self.assertDictEqual({5432: 5435}, cm.port_bindings)
def test_container_metadata_init_with_docker_client_arg(self): mock_dc = mock.MagicMock() c = cli_docker_commands.PostGisContainerMetadata(mock_dc) self.assertIs(c._docker_client, mock_dc)
def test_container_metadata_init(self): cli_docker_commands.PostGisContainerMetadata()
def test_container_metadata_container_cached(self): mock_container = mock.MagicMock() cm = cli_docker_commands.PostGisContainerMetadata() cm._container = mock_container self.assertEqual(mock_container, cm.container)