From bd1c522b203099e70981e33517c775c089801a48 Mon Sep 17 00:00:00 2001 From: scrat Date: Mon, 21 Apr 2008 15:42:58 +0000 Subject: [PATCH] added a doctest in tests.py for testing access to the Outlook API. Minor changes in outlook.py in order to avoid Outlook COM Exception upon call on certain MailItem Attributes (Bug in Outlook API?). outlook.py: loadMailsFromFolder now returns self.result instead of yield None. Otherwise nothing would be returned. Added doctest outlook_real.txt which uses the Outlook API. git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@2534 fd906abe-77d9-0310-91a1-e0d9ade77398 --- agent/crawl/outlook.py | 14 +++++------ agent/crawl/outlook_real.txt | 45 ++++++++++++++++++++++++++++++++++++ agent/tests.py | 1 + 3 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 agent/crawl/outlook_real.txt diff --git a/agent/crawl/outlook.py b/agent/crawl/outlook.py index 2e0b65a..8fa3536 100644 --- a/agent/crawl/outlook.py +++ b/agent/crawl/outlook.py @@ -27,9 +27,6 @@ from email import MIMEMultipart from zope.interface import implements from twisted.internet import defer -#import win32com.client -#import ctypes -#import win32api, win32process, win32con #The watsup import is needed as soon as we start handling the Outlook Pop-Up #again #This should also be integrated within the wrapper-api for doctests @@ -113,8 +110,11 @@ class OutlookCrawler(MailCrawler): if self.keys is None: self.keys = [] for key in mail._prop_map_get_: - if isinstance(getattr(mail, key), (int, str, unicode)): - self.keys.append(key) + try: + if isinstance(getattr(mail, key), (int, str, unicode)): + self.keys.append(key) + except: + pass record = {} for key in self.keys: record[key] = getattr(mail, key) @@ -122,8 +122,8 @@ class OutlookCrawler(MailCrawler): msg = self.createEmailMime(record) # Create a resource and append it to the result list self.createResource(msg, folder, "Microsoft Office Outlook") - #return self.result - yield None + return self.result + #yield None --> nothing would be returned def login(self): pass diff --git a/agent/crawl/outlook_real.txt b/agent/crawl/outlook_real.txt new file mode 100644 index 0000000..e485c61 --- /dev/null +++ b/agent/crawl/outlook_real.txt @@ -0,0 +1,45 @@ +================================================ +Agents for Job Execution and Communication Tasks +================================================ + + ($Id: outlook.txt 2522 2008-04-12 16:29:12Z scrat $) + + >>> config = ''' + ... controller(names=['core.sample']) + ... scheduler(name='core') + ... logger(name='default', standard=30) + ... system.winapi = 'use_outlook' + ... ''' + >>> from cybertools.agent.main import setup + >>> master = setup(config) + Starting agent application... + Using controllers core.sample. + + +OutlookCrawler +============== + +The agent uses Twisted's cooperative multitasking model. + +OutlookCrawler is derived from MailCrawler. The OutlookCrawler returns a deferred +which itself holds a list of MailResource Objects. + +Returns a deferred that must be supplied with a callback method (and in +most cases also an errback method). + +The TestCase here is using subsidiary methods which replace calls to the "real Outlook +dlls". + + >>> controller = master.controllers[0] + >>> controller.createAgent('crawl.outlook', 'sample02') + +In the next step we request the start of a job, again via the controller. + + >>> controller.enterJob('sample', 'sample02', params=dict(inbox=True)) + +The job is not executed immediately - we have to hand over control to +the twisted reactor first. + + >>> from cybertools.agent.tests import tester + >>> tester.iterate() + Job 00001 completed; result: []; diff --git a/agent/tests.py b/agent/tests.py index f7323f0..12487b1 100755 --- a/agent/tests.py +++ b/agent/tests.py @@ -44,6 +44,7 @@ def test_suite(): DocFileSuite('README.txt', optionflags=flags), DocFileSuite('crawl/README.txt', optionflags=flags), DocFileSuite('crawl/outlook.txt', optionflags=flags), + DocFileSuite('crawl/outlook_real.txt', optionflags=flags), )) return testSuite