conduit r1235 - in trunk: . conduit/datatypes conduit/modules/BackpackModule conduit/modules/BoxDotNetModule conduit/modules/GmailModule conduit/modules/ShutterflyModule test/python-tests
- From: jstowers svn gnome org
- To: svn-commits-list gnome org
- Subject: conduit r1235 - in trunk: . conduit/datatypes conduit/modules/BackpackModule conduit/modules/BoxDotNetModule conduit/modules/GmailModule conduit/modules/ShutterflyModule test/python-tests
- Date: Wed, 16 Jan 2008 21:57:16 +0000 (GMT)
Author: jstowers
Date: Wed Jan 16 21:57:15 2008
New Revision: 1235
URL: http://svn.gnome.org/viewvc/conduit?rev=1235&view=rev
Log:
2008-01-17 John Stowers <john stowers gmail com>
* conduit/datatypes/Email.py:
* conduit/modules/GmailModule/GmailModule.py: Fix to retain subject in put()
* conduit/modules/BackpackModule/BackpackModule.py: Implement get() and
get_all(). Not two-way yet, but needed to implement these for tests.
* conduit/modules/ShutterflyModule/ShutterflyModule.py: fix get()
* conduit/modules/BoxDotNetModule/BoxDotNetModule.py:
* test/python-tests/TestDataProviderBackpack.py:
* test/python-tests/TestDataProviderBoxDotNet.py:
* test/python-tests/TestDataProviderGmail.py: Fix tests
* test/python-tests/common.py: Generalise do_dataprovider_test to support
and DataType
Modified:
trunk/ChangeLog
trunk/conduit/datatypes/Email.py
trunk/conduit/modules/BackpackModule/BackpackModule.py
trunk/conduit/modules/BoxDotNetModule/BoxDotNetModule.py
trunk/conduit/modules/GmailModule/GmailModule.py
trunk/conduit/modules/ShutterflyModule/ShutterflyModule.py
trunk/test/python-tests/TestDataProviderBackpack.py
trunk/test/python-tests/TestDataProviderBoxDotNet.py
trunk/test/python-tests/TestDataProviderGmail.py
trunk/test/python-tests/TestDataProviderShutterfly.py
trunk/test/python-tests/common.py
Modified: trunk/conduit/datatypes/Email.py
==============================================================================
--- trunk/conduit/datatypes/Email.py (original)
+++ trunk/conduit/datatypes/Email.py Wed Jan 16 21:57:15 2008
@@ -79,6 +79,9 @@
def get_email_string(self):
return self.email.as_string()
+
+ def get_subject(self):
+ return self.email['Subject']
def __getstate__(self):
data = DataType.DataType.__getstate__(self)
Modified: trunk/conduit/modules/BackpackModule/BackpackModule.py
==============================================================================
--- trunk/conduit/modules/BackpackModule/BackpackModule.py (original)
+++ trunk/conduit/modules/BackpackModule/BackpackModule.py Wed Jan 16 21:57:15 2008
@@ -1,6 +1,7 @@
import os
import sys
import traceback
+import datetime
from gettext import gettext as _
import logging
log = logging.getLogger("modules.Backpack")
@@ -59,7 +60,8 @@
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
+ #and cache the results.
+ #title:(uid,timestamp,text)
self._notes = {}
def refresh(self):
@@ -83,9 +85,10 @@
raise Exceptions.RefreshError
#Need to cache the existing note titles
+ self._notes = {}
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))
+ self._notes[title] = (uid,timestamp,text)
+ log.debug("Found existing note: %s (uid:%s timestamp:%s)" % (title, uid, timestamp))
def configure(self, window):
tree = Utils.dataprovider_glade_get_widget(
@@ -117,9 +120,23 @@
self.set_configured(True)
dlg.destroy()
+
+ def get(self, LUID):
+ for title in self._notes:
+ uid,timestamp,content = self._notes[title]
+ if uid == LUID:
+ n = Note.Note(
+ title=title,
+ #FIXME: Backpack doesnt have mtime, only creation time
+ modified=datetime.datetime.fromtimestamp(timestamp),
+ contents=content
+ )
+ n.set_UID(LUID)
+ return n
+ raise Exceptions.SyncronizeError("Could not find note %s" % LUID)
def get_all(self):
- return self._notes.values()
+ return [n[0] for n in self._notes.values()]
def put(self, note, overwrite, LUID=None):
DataProvider.DataSink.put(self, note, overwrite, LUID)
@@ -129,15 +146,14 @@
try:
if note.title in self._notes:
log.debug("Updating Existing")
- uid = self._notes[note.title]
+ uid,oldtimestamp,oldcontent = self._notes[note.title]
self.ba.notes.update(self.pageID,uid,note.title,note.contents)
else:
log.debug("Creating New (title: %s)" % note.title)
- uid,title,mtime,content = self.ba.notes.create(self.pageID,note.title,note.contents)
- self._notes[note.title] = uid
+ uid,title,timestamp,content = self.ba.notes.create(self.pageID,note.title,note.contents)
+ self._notes[title] = (uid,timestamp,content)
except backpack.BackpackError, err:
- log.info("Could not sync note (%s)" % err)
- raise Exceptions.SyncronizeError
+ raise Exceptions.SyncronizeError("Could not sync note (%s)" % err)
return Rid(uid=str(uid), mtime=None, hash=hash(None))
Modified: trunk/conduit/modules/BoxDotNetModule/BoxDotNetModule.py
==============================================================================
--- trunk/conduit/modules/BoxDotNetModule/BoxDotNetModule.py (original)
+++ trunk/conduit/modules/BoxDotNetModule/BoxDotNetModule.py Wed Jan 16 21:57:15 2008
@@ -318,8 +318,15 @@
URI= url,
group= self.foldername
)
- #FIXME: gnomevfs doesnt like unicode
- f.force_new_filename(str(self.files[LUID]))
+ try:
+ #gnomevfs doesnt like unicode
+ f.force_new_filename(str(self.files[LUID]))
+ except KeyError:
+ #occurs on put() returning get() because we have
+ #not refreshed since. Not a problem because the point
+ #of put returning get() is to make the rids() in the same
+ #scheme, and not actually do something with the returned file.
+ pass
f.set_open_URI(url)
f.set_UID(LUID)
Modified: trunk/conduit/modules/GmailModule/GmailModule.py
==============================================================================
--- trunk/conduit/modules/GmailModule/GmailModule.py (original)
+++ trunk/conduit/modules/GmailModule/GmailModule.py Wed Jan 16 21:57:15 2008
@@ -277,12 +277,12 @@
msg = libgmail.GmailComposedMessage(
to="",
- subject=email.subject,
- body=email.content,
+ subject=email.get_subject(),
+ body="",
filenames=attach)
try:
- draftMsg = self.ga.sendMessage(msg, asDraft = True)
+ draftMsg = self.ga.sendMessage(msg, asDraft=True)
draftMsg.addLabel(self._label)
except libgmail.GmailSendError:
raise Exceptions.SyncronizeError("Error saving message")
Modified: trunk/conduit/modules/ShutterflyModule/ShutterflyModule.py
==============================================================================
--- trunk/conduit/modules/ShutterflyModule/ShutterflyModule.py (original)
+++ trunk/conduit/modules/ShutterflyModule/ShutterflyModule.py Wed Jan 16 21:57:15 2008
@@ -68,10 +68,10 @@
return self.sphotos.keys()
def get(self, LUID):
- Image.ImageSink.get(self, LUID)
+ #Image.ImageSink.get(self, LUID)
sphoto = self.sphotos[LUID]
- f = ShutterflyPhoto(URI=sphoto.url)
+ f = Photo.Photo(URI=sphoto.url)
f.set_open_URI(sphoto.url)
f.set_UID(LUID)
Modified: trunk/test/python-tests/TestDataProviderBackpack.py
==============================================================================
--- trunk/test/python-tests/TestDataProviderBackpack.py (original)
+++ trunk/test/python-tests/TestDataProviderBackpack.py Wed Jan 16 21:57:15 2008
@@ -4,8 +4,6 @@
import traceback
import datetime
-from conduit.Module import ModuleManager
-from conduit.TypeConverter import TypeConverter
import conduit.datatypes.Note as Note
import conduit.Utils as Utils
@@ -24,6 +22,11 @@
#get the module directly so we can call some special functions on it
backpack = test.get_sink().module
+#The ID of the Test page
+SAFE_PAGEID=1352096
+#A Reliable note that will note be deleted
+SAFE_FILEID=2575890
+
#Log in
try:
backpack.refresh()
@@ -31,51 +34,21 @@
except Exception, err:
ok("Logged in (%s)" % err, False)
-#Add a note
-title = Utils.random_string()
-mtime = datetime.datetime.today()
-n = Note.Note(
- title=title,
- modified=mtime,
- contents="Test Note 1\n* list"
- )
-try:
- 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)
+#get the safe folder
+ok("Got page %s" % SAFE_PAGEID, SAFE_PAGEID == backpack.pageID)
-#Add another note
+#Perform basic tests
n = Note.Note(
title=Utils.random_string(),
modified=datetime.datetime.today(),
- contents="Test Note 2"
+ contents="Random Note\n* list"
)
-try:
- rid = backpack.put(n, True)
- uid = rid.get_UID()
- ok("Add another note (%s)" % rid, True)
-except Exception, err:
- traceback.print_exc()
- ok("Add another note (%s)" % err, False)
+test.do_dataprovider_tests(
+ supportsGet=True,
+ supportsDelete=True,
+ safeLUID=SAFE_FILEID,
+ data=n,
+ name="note"
+ )
-#now update that note
-n.contents = "Updated Note"
-try:
- 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()
Modified: trunk/test/python-tests/TestDataProviderBoxDotNet.py
==============================================================================
--- trunk/test/python-tests/TestDataProviderBoxDotNet.py (original)
+++ trunk/test/python-tests/TestDataProviderBoxDotNet.py Wed Jan 16 21:57:15 2008
@@ -36,10 +36,13 @@
ok("Got expected folder %s" % SAFE_FOLDER, SAFE_FOLDER in folders)
#Perform basic tests
+f = new_file(None)
test.do_dataprovider_tests(
supportsGet=True,
supportsDelete=True,
- safeLUID=SAFE_FILEID
+ safeLUID=SAFE_FILEID,
+ data=f,
+ name="file"
)
finished()
Modified: trunk/test/python-tests/TestDataProviderGmail.py
==============================================================================
--- trunk/test/python-tests/TestDataProviderGmail.py (original)
+++ trunk/test/python-tests/TestDataProviderGmail.py Wed Jan 16 21:57:15 2008
@@ -9,13 +9,17 @@
if not is_online():
skip()
+
+#setup the test
+test = SimpleTest(sinkName="GmailEmailTwoWay")
+config = {
+ "username": os.environ.get("TEST_USERNAME","conduitproject gmail com"),
+ "password": os.environ["TEST_PASSWORD"],
+}
+test.configure(sink=config)
-#Dynamically load all datasources, datasinks and converters
-type_converter = SimpleTest().type_converter
-
-gmail = model.get_new_module_instance("GmailEmailTwoWay").module
-gmail.username = "%s gmail com" % os.environ['TEST_USERNAME']
-gmail.password = "%s" % os.environ['TEST_PASSWORD']
+#get the module directly so we can call some special functions on it
+gmail = test.get_sink().module
#Log in
try:
@@ -24,29 +28,14 @@
except Exception, err:
ok("Logged in (%s)" % err, False)
-#Send a remote file
-f = File.File("ssh://root www greenbirdsystems com/root/sync/tests/new/newest")
-try:
- email = type_converter.convert("file","email",f)
- ok("Convert file to email (%s)" % email.get_open_URI(), True)
- uid = gmail.put(email, True)
- ok("Save a file to Gmail (UID:%s) "% uid, True)
-except Exception, err:
- ok("Save a file to Gmail (%s)" % err, False)
-
-#Send an email to myself
-subject = Utils.random_string()
-email = Email.Email(
- None,
- to="",
- subject=subject,
- content="TestGmail.py"
- )
-try:
- uid = gmail.put(email, True)
- ok("Sent Email (UID:%s) "% uid, True)
-except Exception, err:
- ok("Sent Email (%s)" % err, False)
+e = new_email(None)
+test.do_dataprovider_tests(
+ supportsGet=False,
+ supportsDelete=False,
+ safeLUID=None,
+ data=e,
+ name="email"
+ )
finished()
Modified: trunk/test/python-tests/TestDataProviderShutterfly.py
==============================================================================
--- trunk/test/python-tests/TestDataProviderShutterfly.py (original)
+++ trunk/test/python-tests/TestDataProviderShutterfly.py Wed Jan 16 21:57:15 2008
@@ -51,15 +51,9 @@
else:
ok("Album id %s does not equal the one we're expecting %s" % (album_id, SAFE_ALBUM_ID), False)
-info = shutter._get_photo_info (SAFE_PHOTO_ID)
-ok("Got photo info", info != None)
-
-url = shutter._get_raw_photo_url(info)
-ok("Got photo url (%s)" % url, url != None)
-
#Perform image tests
test.do_image_dataprovider_tests(
- supportsGet=False,
+ supportsGet=True,
supportsDelete=True,
safePhotoLUID=SAFE_PHOTO_ID,
ext="jpg"
Modified: trunk/test/python-tests/common.py
==============================================================================
--- trunk/test/python-tests/common.py (original)
+++ trunk/test/python-tests/common.py Wed Jan 16 21:57:15 2008
@@ -330,32 +330,42 @@
def print_mapping_db(self):
print conduit.GLOBALS.mappingDB.debug()
- def do_dataprovider_tests(self, supportsGet, supportsDelete, safeLUID, ext="png", name="file"):
+ def do_dataprovider_tests(self, supportsGet, supportsDelete, safeLUID, data, name):
"""
- Tests get(), put(), delete()
+ Tests get(), put(), delete(). Because some dps have a delay between
+ data being put, and it being get()'able use safeLUID for the UID of
+ the data to get
"""
- #Test get()
- if supportsGet:
- try:
- f = self.sink.module.get(safeLUID)
- ok("Got %s %s" % (name,safeLUID), f.exists())
- except Exception, err:
- traceback.print_exc()
- ok("Got %s (%s)" % (name,err), False)
-
#Test put()
- f = File.File("http://files.conduit-project.org/screenshot.%s" % ext)
try:
- rid = self.sink.module.put(f, True)
+ rid = self.sink.module.put(data, True)
uid = rid.get_UID()
ok("Upload a %s (%s) " % (name,rid), True)
except Exception, err:
traceback.print_exc()
ok("Upload a %s (%s)" % (name,err), False)
+
+ #Test get()
+ if supportsGet:
+ #default to getting the safe file
+ if safeLUID != None:
+ LUID = safeLUID
+ desc = "safe %s" % name
+ else:
+ LUID = uid
+ desc = name
+
+ try:
+ self.sink.module.refresh()
+ f = self.sink.module.get(LUID)
+ ok("Got %s %s" % (desc,LUID), f != None)
+ except Exception, err:
+ traceback.print_exc()
+ ok("Got %s (%s)" % (desc,err), False)
#Test put() to replace
try:
- rid = self.sink.module.put(f, True, uid)
+ rid = self.sink.module.put(data, True, uid)
ok("Update a %s (%s)" % (name,rid), True)
except Exception, err:
traceback.print_exc()
@@ -387,12 +397,13 @@
except Exception, err:
traceback.print_exc()
ok("Got photo info/url (%s)" % err, False)
-
+
+ data = Photo.Photo(URI="http://files.conduit-project.org/screenshot.%s" % ext)
self.do_dataprovider_tests(
supportsGet,
supportsDelete,
safePhotoLUID,
- ext,
+ data,
"photo"
)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]