def test_search(self, pysolr): servers = ['server1', 'server2'] solr = Solr(servers, commit=False, commitWithin='10000') solr.search('foo') solr.query_server.search.assert_called_once_with('foo') pysolr.reset_mock() solr.search('bar', kw='kw') solr.query_server.search.assert_called_once_with('bar', kw='kw')
def test_commit(self, pysolr): servers = ['server1', 'server2'] solr = Solr(servers, commit=False, commitWithin='10000') solr.commit('arg') pysolr.Solr().commit.assert_has_calls([mock.call('arg')] * 2) pysolr.reset_mock() solr.commit('arg', kw='kw') calls = [mock.call('arg', kw='kw')] * 2 pysolr.Solr().commit.assert_has_calls(calls)
def test_delete(self, pysolr): servers = ['server1', 'server2'] solr = Solr(servers, commit=False, commitWithin='10000') solr.delete('foo', commit=True) calls = [mock.call('foo', commit=True)] * 2 pysolr.Solr().delete.assert_has_calls(calls) pysolr.reset_mock() solr.delete('bar', somekw='value') calls = [mock.call('bar', commit=False, somekw='value')] * 2 pysolr.Solr().delete.assert_has_calls(calls)
def test_init(self, pysolr): servers = ['server1', 'server2'] solr = Solr(servers, commit=False, commitWithin='10000') calls = [mock.call('server1'), mock.call('server2')] pysolr.Solr.assert_has_calls(calls) assert_equal(len(solr.push_pool), 2) pysolr.reset_mock() solr = Solr(servers, 'server3', commit=False, commitWithin='10000') calls = [mock.call('server1'), mock.call('server2'), mock.call('server3')] pysolr.Solr.assert_has_calls(calls) assert_equal(len(solr.push_pool), 2)
def __init__(self): self.__dict__ = self.__shared_state if self.__shared_state: return self.allura_templates = pkg_resources.resource_filename( 'allura', 'templates') # Setup SOLR self.solr_server = aslist(config.get('solr.server'), ',') # skip empty strings in case of extra commas self.solr_server = [s for s in self.solr_server if s] self.solr_query_server = config.get('solr.query_server') if asbool(config.get('solr.mock')): self.solr = self.solr_short_timeout = MockSOLR() elif self.solr_server: self.solr = Solr(self.solr_server, self.solr_query_server, commit=asbool(config.get('solr.commit', True)), commitWithin=config.get('solr.commitWithin'), timeout=int(config.get('solr.long_timeout', 60))) self.solr_short_timeout = Solr( self.solr_server, self.solr_query_server, commit=asbool(config.get('solr.commit', True)), commitWithin=config.get('solr.commitWithin'), timeout=int(config.get('solr.short_timeout', 10))) else: # pragma no cover self.solr = None self.solr_short_timeout = None self.use_queue = asbool(config.get('use_queue', False)) # Load login/logout urls; only used for SFX logins self.login_url = config.get('auth.login_url', '/auth/') self.logout_url = config.get('auth.logout_url', '/auth/logout') # Setup Gravatar self.gravatar = gravatar.url self.oid_store = M.OpenIdStore() # Setup pygments self.pygments_formatter = utils.LineAnchorCodeHtmlFormatter( cssclass='codehilite', linenos='table') # Setup Pypeline self.pypeline_markup = pypeline_markup # Setup analytics accounts = config.get('ga.account', 'UA-XXXXX-X') accounts = accounts.split(' ') self.analytics = analytics.GoogleAnalytics(accounts=accounts) self.icons = dict( admin=Icon('x', 'ico-admin'), pencil=Icon('p', 'ico-pencil'), help=Icon('h', 'ico-help'), search=Icon('s', 'ico-search'), history=Icon('N', 'ico-history'), feed=Icon('f', 'ico-feed'), mail=Icon('M', 'ico-mail'), reply=Icon('w', 'ico-reply'), tag=Icon('z', 'ico-tag'), flag=Icon('^', 'ico-flag'), undelete=Icon('+', 'ico-undelete'), delete=Icon('#', 'ico-delete'), close=Icon('D', 'ico-close'), table=Icon('n', 'ico-table'), stats=Icon('Y', 'ico-stats'), pin=Icon('@', 'ico-pin'), folder=Icon('o', 'ico-folder'), fork=Icon('R', 'ico-fork'), merge=Icon('J', 'ico-merge'), plus=Icon('+', 'ico-plus'), conversation=Icon('q', 'ico-conversation'), group=Icon('g', 'ico-group'), user=Icon('U', 'ico-user'), secure=Icon('(', 'ico-lock'), unsecure=Icon(')', 'ico-unlock'), star=Icon('S', 'ico-star'), watch=Icon('E', 'ico-watch'), # Permissions perm_read=Icon('E', 'ico-focus'), perm_update=Icon('0', 'ico-sync'), perm_create=Icon('e', 'ico-config'), perm_register=Icon('e', 'ico-config'), perm_delete=Icon('-', 'ico-minuscirc'), perm_tool=Icon('x', 'ico-config'), perm_admin=Icon('(', 'ico-lock'), perm_has_yes=Icon('3', 'ico-check'), perm_has_no=Icon('d', 'ico-noentry'), perm_has_inherit=Icon('2', 'ico-checkcircle'), ) # Cache some loaded entry points def _cache_eps(section_name, dict_cls=dict): d = dict_cls() for ep in pkg_resources.iter_entry_points(section_name): value = ep.load() d[ep.name] = value return d class entry_point_loading_dict(dict): def __missing__(self, key): self[key] = _cache_eps(key) return self[key] self.entry_points = entry_point_loading_dict( tool=_cache_eps('allura', dict_cls=utils.CaseInsensitiveDict), auth=_cache_eps('allura.auth'), registration=_cache_eps('allura.project_registration'), theme=_cache_eps('allura.theme'), user_prefs=_cache_eps('allura.user_prefs'), spam=_cache_eps('allura.spam'), stats=_cache_eps('allura.stats'), site_stats=_cache_eps('allura.site_stats'), ) # Zarkov logger self._zarkov = None # Set listeners to update stats statslisteners = [] for name, ep in self.entry_points['stats'].iteritems(): statslisteners.append(ep()) self.statsUpdater = PostEvent(statslisteners) self.tmpdir = os.getenv('TMPDIR', '/tmp')