diff --git a/src/apps/storetool/Bongo.rules b/src/apps/storetool/Bongo.rules index 4bb0610..76f8d49 100644 --- a/src/apps/storetool/Bongo.rules +++ b/src/apps/storetool/Bongo.rules @@ -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 diff --git a/src/apps/storetool/bongo-storetool.py b/src/apps/storetool/bongo-storetool.py index d5c77d0..35880c9 100755 --- a/src/apps/storetool/bongo-storetool.py +++ b/src/apps/storetool/bongo-storetool.py @@ -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() diff --git a/src/apps/storetool/bongo/storetool/TestCommands.py b/src/apps/storetool/bongo/storetool/TestCommands.py new file mode 100644 index 0000000..d0fadb6 --- /dev/null +++ b/src/apps/storetool/bongo/storetool/TestCommands.py @@ -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." diff --git a/src/libs/python/bongo/store/StoreClient.py b/src/libs/python/bongo/store/StoreClient.py index f41c1a6..4574ff7 100644 --- a/src/libs/python/bongo/store/StoreClient.py +++ b/src/libs/python/bongo/store/StoreClient.py @@ -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)))