Exemplo n.º 1
0
    def test_config_validator(self, has_connectors):

        with patch(
                'desktop.lib.connectors.models.CONNECTORS.get') as CONNECTORS:
            CONNECTORS.return_value = {
                'hive-1':
                Mock(
                    NICE_NAME=Mock(get=Mock(return_value='Hive')),
                    DIALECT=Mock(get=Mock(return_value='hive')),
                    INTERFACE=Mock(get=Mock(return_value='hiveserver2')),
                    SETTINGS=Mock(get=Mock(return_value=[{
                        "name": "server_host",
                        "value": "gethue"
                    }, {
                        "name": "server_port",
                        "value": "10000"
                    }])),
                )
            }

            update_app_permissions()

            connectors = _get_installed_connectors(user=self.user)
            assert_true(connectors, connectors)

            warnings = config_validator(user=self.user)

            assert_true(warnings, warnings)
            assert_equal('hive-1', warnings[0][0])
            assert_true(
                'Testing the connector connection failed' in warnings[0][1],
                warnings)
Exemplo n.º 2
0
    def test_config_validator(self, has_connectors):

        with patch('desktop.lib.connectors.api._get_installed_connectors'
                   ) as _get_installed_connectors:
            with patch(
                    'notebook.conf._excute_test_query') as _excute_test_query:
                _get_installed_connectors.return_value = [{
                    'nice_name': 'Hive',
                    'name': 'hive-1',
                    'dialect': 'hive',
                    'category': 'editor',
                    'interface': 'hiveserver2',
                    'settings': {},
                    'dialect_properties': {
                        'sql_identifier_quote': '`',
                        'is_sql': True
                    },
                }]
                _excute_test_query.return_value = Mock(
                    content=json.dumps({'status': 0}))

                connectors = _get_installed_connectors(user=self.user)
                assert_true(connectors, connectors)

                warnings = config_validator(user=self.user)

                assert_false(warnings, warnings)

                _excute_test_query.side_effect = Exception('')

                connectors = _get_installed_connectors(user=self.user)
                assert_true(connectors, connectors)

                warnings = config_validator(user=self.user)

                assert_true(warnings, warnings)
                assert_equal('Hive - hive (hive-1)', warnings[0][0])
                assert_true(
                    'Testing the connector connection failed'
                    in warnings[0][1], warnings)
Exemplo n.º 3
0
def test_connector(request):
  connector = json.loads(request.POST.get('connector', '{}'))

  # Currently only Editor connectors are supported.
  interpreter = _connector_to_iterpreter(
      _augment_connector_properties(connector)
  )
  interpreter['type'] = 'hello'  # This is the id of the common health check query

  warnings = ''.join([
    ''.join(warning)
    for warning in config_validator(user=request.user, interpreters=[interpreter])
  ])

  return JsonResponse({'warnings': warnings, 'hasWarnings': bool(warnings)})