From: erickson Date: Wed, 1 Jul 2009 15:33:19 +0000 (+0000) Subject: added really dumb (for now) user search script. made generic random phrase generator... X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=24b541dda42b7d9c95f2138fb281f72dded57ec9;p=working%2Frandom.git added really dumb (for now) user search script. made generic random phrase generator in utils git-svn-id: svn://svn.open-ils.org/ILS-Contrib/constrictor/trunk@555 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- diff --git a/contrib/evergreen/eg_bib_search.py b/contrib/evergreen/eg_bib_search.py index 6db0490a9..774a25d66 100644 --- a/contrib/evergreen/eg_bib_search.py +++ b/contrib/evergreen/eg_bib_search.py @@ -22,13 +22,7 @@ class BibSearchScript(Script): # randomly add many more optional flags } - word_count = int( (random.random() * 3) % 3) + 1 # search phrase has 1-4 words - search_term = '' - - for i in range(0, word_count): - word = words[ int(random.random() * len(words)) ] - search_term += '%s ' % word[0:len(word)-1] - + search_term = eg_utils.random_phrase(None, 3) # search phrase has 1-3 words logInfo('Search term="%s" args="%s"' % (search_term, str(search_args))) res = eg_tasks.TASKS['BibSearchTask'].run( diff --git a/contrib/evergreen/eg_tasks.py b/contrib/evergreen/eg_tasks.py index f27fa4292..9c3c93f12 100644 --- a/contrib/evergreen/eg_tasks.py +++ b/contrib/evergreen/eg_tasks.py @@ -176,3 +176,15 @@ class UserTransactionsByType(AbstractMethodTask): registerTask(UserTransactionsByType()) +class UserSearchTask(AbstractMethodTask): + + def __init__(self): + AbstractMethodTask.__init__(self) + self.service = 'open-ils.actor' + self.method = 'open-ils.actor.patron.search.advanced' + + def run(self, **kw): + return self.runMethod(eg_utils.authtoken(), kw['search_args'], 100) + +registerTask(UserSearchTask()) + diff --git a/contrib/evergreen/eg_user_search.py b/contrib/evergreen/eg_user_search.py new file mode 100644 index 000000000..5c3f1ae07 --- /dev/null +++ b/contrib/evergreen/eg_user_search.py @@ -0,0 +1,35 @@ +from constrictor.task import Task +from constrictor.script import Script, ScriptManager, ScriptThread +from constrictor.log import * +import eg_utils, eg_data, eg_tasks +import random + +eg_utils.init() + +class UserSearchScript(Script): + + def run(self): + + dm = eg_data.DataManager() + + # TODO pull names from the cencus data files we have for generating test users + search_args = { + 'family_name' : {'value' : eg_utils.random_phrase(1), 'group' : 0}, + 'first_given_name' : {'value' : eg_utils.random_phrase(1), 'group' : 0} + } + + logInfo('Search for patron %s' % str(search_args)) + + try: + res = eg_tasks.TASKS['UserSearchTask'].run(search_args = search_args) + + logInfo('Search returned %d hits' % len(res)) + except Exception, e: + logErrror(e) + + return True + +ScriptManager.go(UserSearchScript()) + + + diff --git a/contrib/evergreen/eg_utils.py b/contrib/evergreen/eg_utils.py index 5c15c828a..25096d251 100644 --- a/contrib/evergreen/eg_utils.py +++ b/contrib/evergreen/eg_utils.py @@ -7,11 +7,13 @@ from oils.utils.idl import IDLParser from oils.utils.utils import md5sum from oils.event import Event from oils.const import * -import os, errno +import os, errno, random props = Properties.getProperties() +words = None def init(): + global words loadIDL() initOsrf() @@ -38,6 +40,9 @@ def init(): props.setProperty('evergreen.orgIDs', str(user.home_ou())) + words_file = open('/usr/share/dict/words') # add config property + words = words_file.readlines() + words_file.close() def initOsrf(): @@ -169,3 +174,17 @@ class AuthException(Exception): class ILSEventException(Exception): pass + +def random_phrase(num_words, max_num_words=3): + + if num_words is None: + num_words = int( (random.random() * max_num_words) % max_num_words) + 1 + + phrase = '' + + for i in range(0, num_words): + word = words[ int(random.random() * len(words)) ] + phrase += '%s ' % word[0:len(word)-1] + + return phrase +