rdbms_indexer_tests.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Licensed to Cloudera, Inc. under one
  4. # or more contributor license agreements. See the NOTICE file
  5. # distributed with this work for additional information
  6. # regarding copyright ownership. Cloudera, Inc. licenses this file
  7. # to you under the Apache License, Version 2.0 (the
  8. # "License"); you may not use this file except in compliance
  9. # with the License. You may obtain a copy of the License at
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0
  12. #
  13. # Unless required by applicable law or agreed to in writing, software
  14. # distributed under the License is distributed on an "AS IS" BASIS,
  15. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. # See the License for the specific language governing permissions and
  17. # limitations under the License.
  18. from builtins import object
  19. import logging
  20. from nose.plugins.skip import SkipTest
  21. from nose.tools import assert_equal, assert_false, assert_not_equal, assert_true
  22. from desktop.auth.backend import rewrite_user
  23. from desktop.conf import ENABLE_ORGANIZATIONS
  24. from desktop.lib.django_test_util import make_logged_in_client
  25. from indexer.conf import ENABLE_SQOOP
  26. from indexer.indexers.rdbms import _get_api
  27. from librdbms.server import dbms as rdbms
  28. if ENABLE_ORGANIZATIONS.get():
  29. from useradmin.models import User
  30. else:
  31. from django.contrib.auth.models import User
  32. LOG = logging.getLogger(__name__)
  33. class TestRdbmsIndexer(object):
  34. @classmethod
  35. def setup_class(cls):
  36. if not ENABLE_SQOOP.get():
  37. raise SkipTest
  38. if not rdbms.get_query_server_config(server='mysql'):
  39. raise SkipTest
  40. cls.client = make_logged_in_client()
  41. cls.user = User.objects.get(username='test')
  42. cls.user = rewrite_user(cls.user)
  43. request = Bag()
  44. request.user = cls.user
  45. request.POST = {'source': '{"rdbmsMode":"configRdbms", "rdbmsType": "mysql", "inputFormat": "rdbms"}'}
  46. cls.indexer = _get_api(request)
  47. @classmethod
  48. def teardown_class(cls):
  49. cls.user.is_superuser = False
  50. cls.user.save()
  51. def test_get_sample_data(cls):
  52. data = cls.indexer.get_sample_data({}, database='hue', table='desktop_document2', column='id')
  53. assert_equal(0, data['status'], data)
  54. assert_not_equal('', data['rows'], data)
  55. class Bag(dict):
  56. pass