Browse Source

[libsolr] Add some integration tests

Romain Rigaux 10 years ago
parent
commit
267244724f

+ 1 - 1
apps/beeswax/src/beeswax/test_base.py

@@ -332,7 +332,7 @@ class BeeswaxSampleProvider(object):
   def setup_class(cls):
     cls.db_name = get_db_prefix(name='hive')
     cls.cluster, shutdown = get_shared_beeswax_server(cls.db_name)
-    cls.client = make_logged_in_client()
+    cls.client = make_logged_in_client(username='test', is_superuser=False)
     # Weird redirection to avoid binding nonsense.
     cls.shutdown = [ shutdown ]
     cls.init_beeswax_db()

+ 0 - 1
desktop/libs/indexer/src/indexer/api.py

@@ -20,7 +20,6 @@ import json
 import logging
 import re
 
-from django.utils.decorators import available_attrs
 from django.utils.translation import ugettext as _
 
 from desktop.lib.django_util import JsonResponse

+ 3 - 3
desktop/libs/indexer/src/indexer/tests.py

@@ -17,9 +17,9 @@
 
 import json
 
+from nose.plugins.skip import SkipTest
 from nose.tools import assert_equal, assert_true, assert_false
 
-from django.utils.unittest.case import SkipTest
 from django.contrib.auth.models import User
 from django.core.urlresolvers import reverse
 
@@ -54,9 +54,9 @@ class TestIndexerWithSolr:
   def setup_class(cls):
 
     if not is_live_cluster():
-      raise SkipTest
+      raise SkipTest()
 
-    cls.client = make_logged_in_client()
+    cls.client = make_logged_in_client(username='test', is_superuser=False)
     cls.user = User.objects.get(username='test')
     add_to_group('test')
     grant_access("test", "test", "indexer")

+ 66 - 0
desktop/libs/libsolr/src/libsolr/tests.py

@@ -14,3 +14,69 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
+
+import logging
+import json
+
+from nose.plugins.skip import SkipTest
+from nose.tools import assert_equal, assert_true
+
+from django.contrib.auth.models import User
+from django.core.urlresolvers import reverse
+
+from hadoop.pseudo_hdfs4 import is_live_cluster
+from desktop.lib.django_test_util import make_logged_in_client
+from desktop.lib.test_utils import add_to_group, grant_access
+
+from libsolr.api import SolrApi
+
+
+LOG = logging.getLogger(__name__)
+
+
+try:
+  # App can be blacklisted
+  from search.conf import SOLR_URL
+  from search.models import Collection2
+except:
+  LOG.exception('Testing libsolr requires the search app to not be blacklisted')
+
+
+class TestLibSolrWithSolr:
+
+  @classmethod
+  def setup_class(cls):
+
+    if not is_live_cluster():
+      raise SkipTest
+
+    cls.client = make_logged_in_client(username='test', is_superuser=False)
+    cls.user = User.objects.get(username='test')
+    add_to_group('test')
+    grant_access("test", "test", "libsolr")
+    grant_access("test", "test", "search")
+
+    cls.user.is_superuser = True
+    cls.user.save()
+
+    resp = cls.client.post(reverse('search:install_examples'))
+    content = json.loads(resp.content)
+
+    cls.user.is_superuser = False
+    cls.user.save()
+
+    assert_equal(content.get('status'), 0)
+
+  @classmethod
+  def teardown_class(cls):
+    cls.user.is_superuser = False
+    cls.user.save()
+
+  def test_is_solr_cloud_mode(self):
+    SolrApi(SOLR_URL.get(), self.user).collections()
+
+  def test_query(self):
+    collection = Collection2(user=self.user, name='log_analytics_demo')
+    query = {'qs': [{'q': ''}], 'fqs': [], 'start': 0}
+
+    SolrApi(SOLR_URL.get(), self.user).query(collection, query)