<s> import logging <EOL> import json <EOL> from nose . plugins . skip import SkipTest <EOL> from nose . tools import assert_equal , assert_true <EOL> from django . contrib . auth . models import User <EOL> from django . core . urlresolvers import reverse <EOL> from hadoop . pseudo_hdfs4 import is_live_cluster <EOL> from desktop . lib . django_test_util import make_logged_in_client <EOL> from desktop . lib . test_utils import add_to_group , grant_access <EOL> from libsolr . api import SolrApi <EOL> LOG = logging . getLogger ( __name__ ) <EOL> try : <EOL> from search . conf import SOLR_URL <EOL> from search . models import Collection2 <EOL> except : <EOL> LOG . exception ( '<STR_LIT>' ) <EOL> class TestLibSolrWithSolr : <EOL> @ classmethod <EOL> def setup_class ( cls ) : <EOL> if not is_live_cluster ( ) : <EOL> raise SkipTest <EOL> cls . client = make_logged_in_client ( username = '<STR_LIT:test>' , is_superuser = False ) <EOL> cls . user = User . objects . get ( username = '<STR_LIT:test>' ) <EOL> add_to_group ( '<STR_LIT:test>' ) <EOL> grant_access ( "<STR_LIT:test>" , "<STR_LIT:test>" , "<STR_LIT>" ) <EOL> grant_access ( "<STR_LIT:test>" , "<STR_LIT:test>" , "<STR_LIT>" ) <EOL> cls . user . is_superuser = True <EOL> cls . user . save ( ) <EOL> resp = cls . client . post ( reverse ( '<STR_LIT>' ) ) <EOL> content = json . loads ( resp . content ) <EOL> cls . user . is_superuser = False <EOL> cls . user . save ( ) <EOL> assert_equal ( content . get ( '<STR_LIT:status>' ) , <NUM_LIT:0> ) <EOL> @ classmethod <EOL> def teardown_class ( cls ) : <EOL> cls . user . is_superuser = False <EOL> cls . user . save ( ) <EOL> def test_is_solr_cloud_mode ( self ) : <EOL> SolrApi ( SOLR_URL . get ( ) , self . user ) . collections ( ) <EOL> def test_query ( self ) : <EOL> collection = Collection2 ( user = self . user , name = '<STR_LIT>' ) <EOL> collection = json . loads ( collection . get_json ( self . user ) ) <EOL> query = { '<STR_LIT>' : [ { '<STR_LIT:q>' : '<STR_LIT>' } ] , '<STR_LIT>' : [ ] , '<STR_LIT:start>' : <NUM_LIT:0> } <EOL> SolrApi ( SOLR_URL . get ( ) , self . user ) . query ( collection [ '<STR_LIT>' ] , query ) </s>
