Add a basic store test routine to storetool

This commit is contained in:
alexhudson
2007-12-20 20:48:20 +00:00
parent 5b5f469276
commit b6e10085b5
4 changed files with 92 additions and 0 deletions
+1
View File
@@ -8,6 +8,7 @@ pkgpythonstoretool_PYTHON = \
src/apps/storetool/bongo/storetool/ContactCommands.py \
src/apps/storetool/bongo/storetool/InteractiveCommands.py \
src/apps/storetool/bongo/storetool/MailCommands.py \
src/apps/storetool/bongo/storetool/TestCommands.py \
src/apps/storetool/bongo/storetool/ExportMailbox.py
src/apps/storetool/bongo-storetool: $(top_builddir)/src/libs/python/bongo-python-wrapper
+2
View File
@@ -9,6 +9,7 @@ from bongo.storetool import CalendarCommands
from bongo.storetool import ContactCommands
from bongo.storetool import InteractiveCommands
from bongo.storetool import MailCommands
from bongo.storetool import TestCommands
parser = CommandParser()
parser.add_option("", "--host", type="string", default="localhost",
@@ -29,6 +30,7 @@ parser.add_commands(CalendarCommands, "Calendar")
parser.add_commands(ContactCommands, "Contact")
parser.add_commands(InteractiveCommands)
parser.add_commands(MailCommands, "Mail")
parser.add_commands(TestCommands, "Testing")
if __name__ == '__main__':
(command, options, args) = parser.parse_args()
@@ -0,0 +1,82 @@
import logging
from bongo import Xpl
from bongo.cmdparse import Command
from bongo.BongoError import BongoError
from bongo.store.StoreClient import DocTypes, StoreClient
class TestRun(Command):
log = logging.getLogger("Bongo.StoreTool")
def __init__(self):
Command.__init__(self, "testrun", aliases=["tr"],
summary="Run a test suite against the store",
usage="%prog %cmd")
def Err(self, message):
print "[ERR] %s" % message
def Run(self, options, args):
try:
store = StoreClient("admin", "admin")
except:
self.Err("Couldn't connect to a store for testing.")
return
# collection testing first
print "Looking for collections..."
try:
colls = store.Collections()
for coll in colls:
pass
except:
self.Err("Can't list collections (COLLECTIONS)")
print "Adding collection"
try:
coll = store.Create("/testcoll", existingOk = True)
except:
self.Err("Can't add collection (CREATE)")
print "Listing collection contents"
try:
contents = store.List("/testcoll")
for doc in contents:
pass
except:
self.Err("Can't list collection contents (LIST)")
print "Renaming collection"
try:
store.Rename("/testcoll", "/renamed-testcoll")
except:
self.Err("Can't rename test collection (RENAME)")
mailpath = Xpl.DEFAULT_DATA_DIR + "/demo/mail"
mail1 = "%s/%s" % (mailpath, "bongo-general-000")
mail2 = "%s/%s" % (mailpath, "bongo-general-002")
print "Writing mail to collection..."
guid = None
try:
f = file(mail1)
guid = store.Write("/renamed-testcoll", DocTypes.Mail, f.read())
f.close()
except:
self.Err("Can't write new doc to renamed-testcoll")
if guid != None:
print "Removing mail from collection..."
try:
store.Delete(guid)
except:
self.Err("Can't remove document from renamed-testcoll")
print "Removing collection"
try:
store.Remove("/renamed-testcoll")
except:
self.Err("Couldn't remove collection (REMOVE)")
print "Test suite ran successfully."
@@ -746,6 +746,13 @@ class StoreClient:
r = self.stream.GetResponse()
if r.code != 1000:
raise CommandError(r)
def Rename(self, oldname, newname):
self.stream.Write("RENAME %s %s" % (oldname, newname))
r = self.stream.GetResponse()
if r.code != 1000:
raise CommandError(r)
def Replace(self, doc, data):
self.stream.Write("REPLACE %s %d" % (doc, len(data)))