示例#1
0
    def test_services_create_spatial_command_IndexError(self, mock_service, mock_pretty_output):
        """
        Test for services_create_spatial_command
        Handles an IndexError exception
        :param mock_service:  mock for SpatialDatasetService
        :param mock_pretty_output:  mock for pretty_output text
        :return:
        """
        mock_args = mock.MagicMock()
        mock_args.connection = 'IndexError:9876@IndexError'  # No 'http' or '://'

        services_create_spatial_command(mock_args)

        mock_service.assert_not_called()

        po_call_args = mock_pretty_output().__enter__().write.call_args_list
        self.assertEqual(1, len(po_call_args))
        self.assertIn('The connection argument (-c) must be of the form', po_call_args[0][0][0])
        self.assertIn('"<username>:<password>@<protocol>//<host>:<port>".', po_call_args[0][0][0])
示例#2
0
    def test_services_create_spatial_command(self, mock_service, mock_pretty_output):
        """
        Test for services_create_spatial_command
        For going through the function and saving
        :param mock_service:  mock for SpatialDatasetService
        :param mock_pretty_output:  mock for pretty_output text
        :return:
        """
        mock_args = mock.MagicMock()
        mock_args.connection = 'foo:pass@http:://foo:1234'
        mock_args.public_endpoint = 'http://foo:1234'
        mock_service.return_value = mock.MagicMock()

        services_create_spatial_command(mock_args)

        mock_service.assert_called()

        po_call_args = mock_pretty_output().__enter__().write.call_args_list
        self.assertEqual(1, len(po_call_args))
        self.assertEqual('Successfully created new Spatial Dataset Service!', po_call_args[0][0][0])
示例#3
0
    def test_services_create_spatial_command_FormatError(self, mock_service, mock_pretty_output):
        """
        Test for services_create_spatial_command
        Handles an FormatError exception
        :param mock_service:  mock for SpatialDatasetService
        :param mock_pretty_output:  mock for pretty_output text
        :return:
        """
        mock_args = mock.MagicMock()
        mock_args.connection = 'foo:pass@http:://foo:1234'
        mock_args.public_endpoint = 'foo@foo:foo'  # No 'http' or '://'

        services_create_spatial_command(mock_args)

        mock_service.assert_not_called()

        po_call_args = mock_pretty_output().__enter__().write.call_args_list
        self.assertEqual(1, len(po_call_args))
        self.assertIn('The public_endpoint argument (-p) must be of the form ', po_call_args[0][0][0])
        self.assertIn('"<protocol>//<host>:<port>".', po_call_args[0][0][0])
示例#4
0
    def test_services_create_spatial_command_IntegrityError(self, mock_service, mock_pretty_output):
        """
        Test for services_create_spatial_command
        Handles an IntegrityError exception
        :param mock_service:  mock for SpatialDatasetService
        :param mock_pretty_output:  mock for pretty_output text
        :return:
        """
        mock_args = mock.MagicMock()
        mock_args.connection = 'foo:pass@http:://foo:1234'
        mock_args.public_endpoint = 'http://foo:1234'
        mock_service.side_effect = IntegrityError

        services_create_spatial_command(mock_args)

        mock_service.assert_called()

        po_call_args = mock_pretty_output().__enter__().write.call_args_list
        self.assertEqual(1, len(po_call_args))
        self.assertIn('Spatial Dataset Service with name ', po_call_args[0][0][0])
        self.assertIn('already exists. Command aborted.', po_call_args[0][0][0])