conduit r1228 - in trunk: . conduit/modules/BackpackModule test/python-tests
- From: jstowers svn gnome org
- To: svn-commits-list gnome org
- Subject: conduit r1228 - in trunk: . conduit/modules/BackpackModule test/python-tests
- Date: Wed, 16 Jan 2008 09:07:40 +0000 (GMT)
Author: jstowers
Date: Wed Jan 16 09:07:40 2008
New Revision: 1228
URL: http://svn.gnome.org/viewvc/conduit?rev=1228&view=rev
Log:
2008-01-16 John Stowers <john stowers gmail com>
* conduit/modules/BackpackModule/BackpackModule.py: Fix refresh() behaviour
so that we dont recreate the backpack API everytime, but we do check for
new notes
* test/python-tests/TestDataProviderBackpack.py: Fix test and add test
for deleting notes
Modified:
trunk/ChangeLog
trunk/conduit/modules/BackpackModule/BackpackModule.py
trunk/test/python-tests/TestDataProviderBackpack.py
Modified: trunk/conduit/modules/BackpackModule/BackpackModule.py
==============================================================================
--- trunk/conduit/modules/BackpackModule/BackpackModule.py (original)
+++ trunk/conduit/modules/BackpackModule/BackpackModule.py Wed Jan 16 09:07:40 2008
@@ -20,29 +20,28 @@
}
class BackpackBase(DataProvider.DataProviderBase):
- """
- Simple wrapper to share gmail login stuff
- """
def __init__(self, *args):
+ DataProvider.DataProviderBase.__init__(self)
self.username = ""
self.apikey = ""
-
self.ba = None
+ self.loggedIn = False
def initialize(self):
return True
def refresh(self):
- username = "http://" + self.username + ".backpackit.com/"
- try:
- self.ba = backpack.Backpack(username,self.apikey)
- self.loggedIn = True
- except backpack.BackpackError:
- log.warn("Error logging into backpack (username %s)" % self.username)
- raise Exceptions.RefreshError
+ if self.loggedIn == False:
+ username = "http://" + self.username + ".backpackit.com/"
+ try:
+ self.ba = backpack.Backpack(username,self.apikey)
+ self.loggedIn = True
+ except backpack.BackpackError:
+ log.warn("Error logging into backpack (username %s)" % self.username)
+ raise Exceptions.RefreshError
-class BackpackNoteSink(BackpackBase, DataProvider.DataSink):
+class BackpackNoteSink(DataProvider.DataSink, BackpackBase):
_name_ = _("Backpack Notes")
_description_ = _("Store things in Backpack Notes")
@@ -53,20 +52,19 @@
_icon_ = "backpack"
def __init__(self, *args):
- BackpackBase.__init__(self, *args)
DataProvider.DataSink.__init__(self)
+ BackpackBase.__init__(self, *args)
self.need_configuration(True)
self.storeInPage = "Conduit"
self.pageID = None
-
#there is no way to pragmatically see if a note exists so we list them
#and cache the results. key = note uid
self._notes = {}
def refresh(self):
- BackpackBase.refresh(self)
DataProvider.DataSink.refresh(self)
+ BackpackBase.refresh(self)
#First search for the pageID of the named page to put notes in
if self.pageID is None:
pages = self.ba.page.list()
@@ -78,17 +76,16 @@
#Didnt find the page so create one
if self.pageID is None:
try:
- self.pageID, title = self.ba.page.create("Conduit")
+ self.pageID, title = self.ba.page.create(self.storeInPage)
log.info("Created page %s (id: %s)" % (title, self.pageID))
except backpack.BackpackError, err:
log.info("Could not create page to store notes in (%s)" % err)
raise Exceptions.RefreshError
- #First put needs to cache the existing note titles and uris
- if len(self._notes) == 0:
- for uid, title, timestamp, text in self.ba.notes.list(self.pageID):
- self._notes[title] = uid
- log.debug("Found existing notes: %s" % self._notes)
+ #Need to cache the existing note titles
+ for uid, title, timestamp, text in self.ba.notes.list(self.pageID):
+ self._notes[title] = uid
+ log.debug("Found existing note: %s (%s)" % (title, uid))
def configure(self, window):
tree = Utils.dataprovider_glade_get_widget(
@@ -119,13 +116,14 @@
if len(self.username) > 0 and len(self.apikey) > 0:
self.set_configured(True)
- dlg.destroy()
+ dlg.destroy()
+ def get_all(self):
+ return self._notes.values()
def put(self, note, overwrite, LUID=None):
DataProvider.DataSink.put(self, note, overwrite, LUID)
- #FIXME: implement overwrite and LUID behaviour
#If all that went well then actually store some notes.
uid = None
try:
@@ -151,7 +149,7 @@
log.info("Could delete note (%s)" % err)
raise Exceptions.SyncronizeError
else:
- log.debug("Could not find note")
+ log.info("Could not find note")
def get_UID(self):
return "%s:%s" % (self.username,self.storeInPage)
Modified: trunk/test/python-tests/TestDataProviderBackpack.py
==============================================================================
--- trunk/test/python-tests/TestDataProviderBackpack.py (original)
+++ trunk/test/python-tests/TestDataProviderBackpack.py Wed Jan 16 09:07:40 2008
@@ -14,16 +14,16 @@
#setup the test
test = SimpleTest(sinkName="BackpackNoteSink")
-backpack = test.get_sink().module
-
-#configure the backpack
config = {
- "username" : os.environ['TEST_USERNAME'],
+ "username" : os.environ.get("TEST_USERNAME","conduitproject"),
"apikey" : "13f3e8657d25d399f4b6b4f7eda7986ae6e0fbde",
- "storeInPage" : "%s-%s" % (conduit.APPNAME, conduit.APPVERSION)
+ "storeInPage" : "Test"
}
test.configure(sink=config)
+#get the module directly so we can call some special functions on it
+backpack = test.get_sink().module
+
#Log in
try:
backpack.refresh()
@@ -37,37 +37,45 @@
n = Note.Note(
title=title,
modified=mtime,
- contents="This is a test note \n* list\n*list"
+ contents="Test Note 1\n* list"
)
try:
- uid = backpack.put(n, True)
- ok("Add a note (UID:%s)" % uid, True)
+ rid = backpack.put(n, True)
+ ok("Add a note (%s)" % rid, True)
except Exception, err:
traceback.print_exc()
ok("Add a note (%s)" % err, False)
#Add another note
-title = Utils.random_string()
-mtime = datetime.datetime.today()
n = Note.Note(
- title=title,
- modified=mtime,
- contents="Test Note\n* list\n* list"
+ title=Utils.random_string(),
+ modified=datetime.datetime.today(),
+ contents="Test Note 2"
)
try:
- uid = backpack.put(n, True)
- ok("Add a note (UID:%s)" % uid, True)
+ rid = backpack.put(n, True)
+ uid = rid.get_UID()
+ ok("Add another note (%s)" % rid, True)
except Exception, err:
traceback.print_exc()
- ok("Add a note (%s)" % err, False)
+ ok("Add another note (%s)" % err, False)
#now update that note
n.contents = "Updated Note"
try:
- uid = backpack.put(n, True)
- ok("Update a note (UID:%s)" % uid, True)
+ rid = backpack.put(n, True, uid)
+ ok("Update a note (%s)" % rid, True)
except Exception, err:
traceback.print_exc()
ok("Update a note (%s)" % err, False)
-
+
+try:
+ backpack.refresh()
+ backpack.delete(uid)
+ backpack.refresh()
+ ok("Delete a note (%s)" % rid, uid not in backpack.get_all())
+except Exception, err:
+ traceback.print_exc()
+ ok("Delete a note (%s)" % err, False)
+
finished()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]