Migration to JCL
JMC migration to JCL: - Use SQLObject for persistence - Use PyXMPP DataForm implementation - test packages reorganisation Need to update component.py and config.py to finish the migration darcs-hash:20070221173604-86b55-17fb4a530f378b51b6b62a117a6f93c73c5be796.gz
This commit is contained in:
@@ -1,20 +0,0 @@
|
||||
<config>
|
||||
<jabber>
|
||||
<server>127.0.0.1</server>
|
||||
<port>5347</port>
|
||||
<secret>secret</secret>
|
||||
<service>jmc.localhost</service>
|
||||
<connectsleep>5</connectsleep>
|
||||
<language>en</language>
|
||||
<vCard>
|
||||
<FN>Jabber Mail Component</FN>
|
||||
<DESC>A Jabber mail server component</DESC>
|
||||
<URL>http://people.happycoders.org/dax/jabber/jmc/</URL>
|
||||
</vCard>
|
||||
</jabber>
|
||||
<storage>SQLite</storage>
|
||||
<pidfile>jmc.pid</pidfile>
|
||||
<spooldir>.</spooldir>
|
||||
<check_interval>5</check_interval> <!-- in minutes -->
|
||||
<mail_default_encoding>iso-8859-15</mail_default_encoding>
|
||||
</config>
|
||||
2
tests/jmc/__init__.py
Normal file
2
tests/jmc/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
"""JMC test module"""
|
||||
__revision__ = ""
|
||||
@@ -29,9 +29,28 @@ import socket
|
||||
import types
|
||||
import select
|
||||
import xml.dom.minidom
|
||||
import utils
|
||||
from pyxmpp import xmlextra
|
||||
|
||||
def xmldiff(node1, node2):
|
||||
if node1.nodeType == node1.TEXT_NODE:
|
||||
if not node2.nodeType == node2.TEXT_NODE \
|
||||
or re.compile(node2.data + "$").match(node1.data) is None:
|
||||
raise Exception("data in text node " + node1.data + " does not match " + node2.data)
|
||||
elif node1.nodeType == node1.DOCUMENT_NODE:
|
||||
if not node2.nodeType == node2.DOCUMENT_NODE:
|
||||
raise Exception("node1 is Document but not node2 (" + node2.nodeType + ")")
|
||||
elif node1.tagName != node2.tagName:
|
||||
raise Exception("Different tag name : " + node1.tagName + " != " + node2.tagName)
|
||||
else:
|
||||
for attr in node1._get_attributes().keys():
|
||||
if not node2.hasAttribute(attr) \
|
||||
or node1.getAttribute(attr) != node2.getAttribute(attr):
|
||||
raise Exception("(" + node1.tagName + ") Different attributes : " + node1.getAttribute(attr) + " != " + node2.getAttribute(attr))
|
||||
if len(node1.childNodes) != len(node2.childNodes):
|
||||
raise Exception("(" + node1.tagName + ") Different children number : " + str(len(node1.childNodes)) + " != " + str(len(node2.childNodes)))
|
||||
for i in range(len(node1.childNodes)):
|
||||
xmldiff(node1.childNodes[i], node2.childNodes[i])
|
||||
|
||||
class DummyServer:
|
||||
def __init__(self, host, port, responses = None):
|
||||
for res in socket.getaddrinfo(host, port, socket.AF_UNSPEC, socket.SOCK_STREAM, 0, socket.AI_PASSIVE):
|
||||
@@ -40,7 +59,7 @@ class DummyServer:
|
||||
s = socket.socket(af, socktype, proto)
|
||||
except socket.error, msg:
|
||||
s = None
|
||||
continue
|
||||
raise socket.error
|
||||
try:
|
||||
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
s.bind(sa)
|
||||
@@ -48,7 +67,7 @@ class DummyServer:
|
||||
except socket.error, msg:
|
||||
s.close()
|
||||
s = None
|
||||
continue
|
||||
raise socket.error
|
||||
break
|
||||
self.socket = s
|
||||
self.responses = None
|
||||
@@ -56,6 +75,7 @@ class DummyServer:
|
||||
self.real_queries = []
|
||||
|
||||
def serve(self):
|
||||
conn = None
|
||||
try:
|
||||
conn, addr = self.socket.accept()
|
||||
rfile = conn.makefile('rb', -1)
|
||||
@@ -77,9 +97,11 @@ class DummyServer:
|
||||
else:
|
||||
self.real_queries.append(data)
|
||||
#print >>sys.stderr, 'Receive : ', data
|
||||
conn.close()
|
||||
self.socket.close()
|
||||
self.socket = None
|
||||
if conn is not None:
|
||||
conn.close()
|
||||
if self.socket is not None:
|
||||
self.socket.close()
|
||||
self.socket = None
|
||||
except:
|
||||
type, value, stack = sys.exc_info()
|
||||
print >>sys.stderr, "".join(traceback.format_exception
|
||||
2
tests/jmc/jabber/__init__.py
Normal file
2
tests/jmc/jabber/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
"""JMC jabber test module"""
|
||||
__revision__ = ""
|
||||
26
tests/jmc/jabber/test_component.py
Normal file
26
tests/jmc/jabber/test_component.py
Normal file
@@ -0,0 +1,26 @@
|
||||
##
|
||||
## test_component.py
|
||||
## Login : <dax@happycoders.org>
|
||||
## Started on Wed Feb 14 18:04:49 2007 David Rousselie
|
||||
## $Id$
|
||||
##
|
||||
## Copyright (C) 2007 David Rousselie
|
||||
## This program is free software; you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published by
|
||||
## the Free Software Foundation; either version 2 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## This program is distributed in the hope that it will be useful,
|
||||
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
## GNU General Public License for more details.
|
||||
##
|
||||
## You should have received a copy of the GNU General Public License
|
||||
## along with this program; if not, write to the Free Software
|
||||
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
##
|
||||
|
||||
import unittest
|
||||
|
||||
class MailComponent_TestCase(unittest.TestCase):
|
||||
pass
|
||||
0
tests/jmc/model/__init__.py
Normal file
0
tests/jmc/model/__init__.py
Normal file
@@ -1,11 +1,11 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##
|
||||
## mailconnection_test.py
|
||||
## Login : David Rousselie <david.rousselie@happycoders.org>
|
||||
## Started on Fri May 13 11:32:51 2005 David Rousselie
|
||||
## $Id: test_mailconnection.py,v 1.2 2005/09/18 20:24:07 David Rousselie Exp $
|
||||
## test_account.py
|
||||
## Login : <dax@happycoders.org>
|
||||
## Started on Wed Feb 14 08:23:17 2007 David Rousselie
|
||||
## $Id$
|
||||
##
|
||||
## Copyright (C) 2005 David Rousselie
|
||||
## Copyright (C) 2007 David Rousselie
|
||||
## This program is free software; you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published by
|
||||
## the Free Software Foundation; either version 2 of the License, or
|
||||
@@ -22,20 +22,45 @@
|
||||
##
|
||||
|
||||
import unittest
|
||||
from jmc.email.mailconnection import IMAPConnection, \
|
||||
POP3Connection, \
|
||||
MailConnection
|
||||
import dummy_server
|
||||
import email_generator
|
||||
import os
|
||||
import thread
|
||||
import re
|
||||
import sys
|
||||
import string
|
||||
|
||||
class MailConnection_TestCase(unittest.TestCase):
|
||||
from sqlobject import *
|
||||
from sqlobject.dbconnection import TheURIOpener
|
||||
|
||||
from jcl.model import account
|
||||
from jcl.model.account import Account, PresenceAccount
|
||||
from jmc.model.account import MailAccount, POP3Account, IMAPAccount
|
||||
|
||||
from tests.jmc import email_generator, dummy_server
|
||||
|
||||
DB_PATH = "/tmp/jmc_test.db"
|
||||
DB_URL = DB_PATH # + "?debug=1&debugThreading=1"
|
||||
|
||||
class MailAccount_TestCase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.connection = MailConnection()
|
||||
|
||||
if os.path.exists(DB_PATH):
|
||||
os.unlink(DB_PATH)
|
||||
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||
Account.createTable(ifNotExists = True)
|
||||
PresenceAccount.createTable(ifNotExists = True)
|
||||
MailAccount.createTable(ifNotExists = True)
|
||||
self.account = MailAccount(user_jid = "user1@test.com", \
|
||||
name = "account1", \
|
||||
jid = "account1@jmc.test.com")
|
||||
del account.hub.threadConnection
|
||||
|
||||
def tearDown(self):
|
||||
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||
MailAccount.dropTable(ifExists = True)
|
||||
PresenceAccount.dropTable(ifExists = True)
|
||||
Account.dropTable(ifExists = True)
|
||||
del TheURIOpener.cachedURIs['sqlite://' + DB_URL]
|
||||
account.hub.threadConnection.close()
|
||||
del account.hub.threadConnection
|
||||
if os.path.exists(DB_PATH):
|
||||
os.unlink(DB_PATH)
|
||||
|
||||
def make_test(email_type, tested_func, expected_res):
|
||||
def inner(self):
|
||||
encoded, multipart, header = email_type
|
||||
@@ -48,23 +73,23 @@ class MailConnection_TestCase(unittest.TestCase):
|
||||
|
||||
test_get_decoded_part_not_encoded = \
|
||||
make_test((False, False, False), \
|
||||
lambda self, email: self.connection.get_decoded_part(email, None), \
|
||||
lambda self, email: self.account.get_decoded_part(email, None), \
|
||||
u"Not encoded single part")
|
||||
|
||||
test_get_decoded_part_encoded = \
|
||||
make_test((True, False, False), \
|
||||
lambda self, email: self.connection.get_decoded_part(email, None), \
|
||||
lambda self, email: self.account.get_decoded_part(email, None), \
|
||||
u"Encoded single part with 'iso-8859-15' charset (éàê)")
|
||||
|
||||
test_format_message_summary_not_encoded = \
|
||||
make_test((False, False, True), \
|
||||
lambda self, email: self.connection.format_message_summary(email), \
|
||||
lambda self, email: self.account.format_message_summary(email), \
|
||||
(u"From : not encoded from\nSubject : not encoded subject\n\n", \
|
||||
u"not encoded from"))
|
||||
|
||||
test_format_message_summary_encoded = \
|
||||
make_test((True, False, True), \
|
||||
lambda self, email: self.connection.format_message_summary(email), \
|
||||
lambda self, email: self.account.format_message_summary(email), \
|
||||
(u"From : encoded from (éàê)\nSubject : encoded subject " + \
|
||||
u"(éàê)\n\n", \
|
||||
u"encoded from (éàê)"))
|
||||
@@ -78,21 +103,21 @@ class MailConnection_TestCase(unittest.TestCase):
|
||||
email.replace_header("From", \
|
||||
"\"" + str(email["From"]) \
|
||||
+ "\" not encoded part") or \
|
||||
self.connection.format_message_summary(email), \
|
||||
self.account.format_message_summary(email), \
|
||||
(u"From : \"encoded from (éàê)\" not encoded part\nSubject " + \
|
||||
u": \"encoded subject (éàê)\" not encoded part\n\n", \
|
||||
u"\"encoded from (éàê)\" not encoded part"))
|
||||
|
||||
test_format_message_single_not_encoded = \
|
||||
make_test((False, False, True), \
|
||||
lambda self, email: self.connection.format_message(email), \
|
||||
lambda self, email: self.account.format_message(email), \
|
||||
(u"From : not encoded from\nSubject : not encoded subject" + \
|
||||
u"\n\nNot encoded single part\n", \
|
||||
u"not encoded from"))
|
||||
|
||||
test_format_message_single_encoded = \
|
||||
make_test((True, False, True), \
|
||||
lambda self, email: self.connection.format_message(email), \
|
||||
lambda self, email: self.account.format_message(email), \
|
||||
(u"From : encoded from (éàê)\nSubject : encoded subject " + \
|
||||
u"(éàê)\n\nEncoded single part with 'iso-8859-15' charset" + \
|
||||
u" (éàê)\n", \
|
||||
@@ -100,14 +125,14 @@ class MailConnection_TestCase(unittest.TestCase):
|
||||
|
||||
test_format_message_multi_not_encoded = \
|
||||
make_test((False, True, True), \
|
||||
lambda self, email: self.connection.format_message(email), \
|
||||
lambda self, email: self.account.format_message(email), \
|
||||
(u"From : not encoded from\nSubject : not encoded subject" + \
|
||||
u"\n\nNot encoded multipart1\nNot encoded multipart2\n", \
|
||||
u"not encoded from"))
|
||||
|
||||
test_format_message_multi_encoded = \
|
||||
make_test((True, True, True), \
|
||||
lambda self, email: self.connection.format_message(email), \
|
||||
lambda self, email: self.account.format_message(email), \
|
||||
(u"From : encoded from (éàê)\nSubject : encoded subject (éà" + \
|
||||
u"ê)\n\nutf-8 multipart1 with no charset (éàê)" + \
|
||||
u"\nEncoded multipart2 with 'iso-8859-15' charset (éàê)\n" + \
|
||||
@@ -115,19 +140,40 @@ class MailConnection_TestCase(unittest.TestCase):
|
||||
u"encoded from (éàê)"))
|
||||
|
||||
|
||||
class POP3Connection_TestCase(unittest.TestCase):
|
||||
class POP3Account_TestCase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.server = dummy_server.DummyServer("localhost", 1110)
|
||||
thread.start_new_thread(self.server.serve, ())
|
||||
self.pop3connection = POP3Connection("login", \
|
||||
"pass", \
|
||||
"localhost", \
|
||||
1110, \
|
||||
ssl = False)
|
||||
|
||||
if os.path.exists(DB_PATH):
|
||||
os.unlink(DB_PATH)
|
||||
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||
Account.createTable(ifNotExists = True)
|
||||
PresenceAccount.createTable(ifNotExists = True)
|
||||
MailAccount.createTable(ifNotExists = True)
|
||||
POP3Account.createTable(ifNotExists = True)
|
||||
self.pop3_account = POP3Account(user_jid = "user1@test.com", \
|
||||
name = "account1", \
|
||||
jid = "account1@jmc.test.com", \
|
||||
login = "login")
|
||||
self.pop3_account.password = "pass"
|
||||
self.pop3_account.host = "localhost"
|
||||
self.pop3_account.port = 1110
|
||||
self.pop3_account.ssl = False
|
||||
del account.hub.threadConnection
|
||||
|
||||
def tearDown(self):
|
||||
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||
POP3Account.dropTable(ifExists = True)
|
||||
MailAccount.dropTable(ifExists = True)
|
||||
PresenceAccount.dropTable(ifExists = True)
|
||||
Account.dropTable(ifExists = True)
|
||||
del TheURIOpener.cachedURIs['sqlite://' + DB_URL]
|
||||
account.hub.threadConnection.close()
|
||||
del account.hub.threadConnection
|
||||
if os.path.exists(DB_PATH):
|
||||
os.unlink(DB_PATH)
|
||||
self.server = None
|
||||
self.pop3connection = None
|
||||
self.pop3_account = None
|
||||
|
||||
def make_test(responses = None, queries = None, core = None):
|
||||
def inner(self):
|
||||
@@ -141,12 +187,14 @@ class POP3Connection_TestCase(unittest.TestCase):
|
||||
if queries:
|
||||
self.server.queries += queries
|
||||
self.server.queries += ["QUIT\r\n"]
|
||||
self.pop3connection.connect()
|
||||
self.failUnless(self.pop3connection.connection, \
|
||||
self.pop3_account.connect()
|
||||
self.failUnless(self.pop3_account.connection, \
|
||||
"Cannot establish connection")
|
||||
if core:
|
||||
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||
core(self)
|
||||
self.pop3connection.disconnect()
|
||||
del account.hub.threadConnection
|
||||
self.pop3_account.disconnect()
|
||||
self.failUnless(self.server.verify_queries(), \
|
||||
"Sended queries does not match expected queries.")
|
||||
return inner
|
||||
@@ -157,7 +205,7 @@ class POP3Connection_TestCase(unittest.TestCase):
|
||||
make_test(["+OK 2 20\r\n"], \
|
||||
["STAT\r\n"], \
|
||||
lambda self: \
|
||||
self.assertEquals(self.pop3connection.get_mail_list(), \
|
||||
self.assertEquals(self.pop3_account.get_mail_list(), \
|
||||
["1", "2"]))
|
||||
|
||||
test_get_mail_summary = \
|
||||
@@ -169,7 +217,7 @@ class POP3Connection_TestCase(unittest.TestCase):
|
||||
["RETR 1\r\n",
|
||||
"RSET\r\n"], \
|
||||
lambda self: \
|
||||
self.assertEquals(self.pop3connection.get_mail_summary(1), \
|
||||
self.assertEquals(self.pop3_account.get_mail_summary(1), \
|
||||
(u"From : user@test.com\n" + \
|
||||
u"Subject : subject test\n\n", \
|
||||
u"user@test.com")))
|
||||
@@ -183,7 +231,7 @@ class POP3Connection_TestCase(unittest.TestCase):
|
||||
["RETR 1\r\n",
|
||||
"RSET\r\n"], \
|
||||
lambda self: \
|
||||
self.assertEquals(self.pop3connection.get_mail(1), \
|
||||
self.assertEquals(self.pop3_account.get_mail(1), \
|
||||
(u"From : user@test.com\n" + \
|
||||
u"Subject : subject test\n\n" + \
|
||||
u"mymessage\n", \
|
||||
@@ -198,7 +246,7 @@ class POP3Connection_TestCase(unittest.TestCase):
|
||||
["RETR 1\r\n",
|
||||
"RSET\r\n"], \
|
||||
lambda self: \
|
||||
self.assertEquals(self.pop3connection.get_mail_summary(1), \
|
||||
self.assertEquals(self.pop3_account.get_mail_summary(1), \
|
||||
(u"From : user@test.com\n" + \
|
||||
u"Subject : subject test\n\n", \
|
||||
u"user@test.com")))
|
||||
@@ -212,26 +260,47 @@ class POP3Connection_TestCase(unittest.TestCase):
|
||||
["RETR 1\r\n",
|
||||
"RSET\r\n"], \
|
||||
lambda self: \
|
||||
self.assertEquals(self.pop3connection.get_mail(1), \
|
||||
self.assertEquals(self.pop3_account.get_mail(1), \
|
||||
(u"From : user@test.com\n" + \
|
||||
u"Subject : subject test\n\n" + \
|
||||
u"mymessage\n", \
|
||||
u"user@test.com")))
|
||||
|
||||
|
||||
class IMAPConnection_TestCase(unittest.TestCase):
|
||||
class IMAPAccount_TestCase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.server = dummy_server.DummyServer("localhost", 1143)
|
||||
thread.start_new_thread(self.server.serve, ())
|
||||
self.imap_connection = IMAPConnection("login", \
|
||||
"pass", \
|
||||
"localhost", \
|
||||
1143, \
|
||||
ssl = False)
|
||||
if os.path.exists(DB_PATH):
|
||||
os.unlink(DB_PATH)
|
||||
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||
Account.createTable(ifNotExists = True)
|
||||
PresenceAccount.createTable(ifNotExists = True)
|
||||
MailAccount.createTable(ifNotExists = True)
|
||||
IMAPAccount.createTable(ifNotExists = True)
|
||||
self.imap_account = IMAPAccount(user_jid = "user1@test.com", \
|
||||
name = "account1", \
|
||||
jid = "account1@jmc.test.com", \
|
||||
login = "login")
|
||||
self.imap_account.password = "pass"
|
||||
self.imap_account.host = "localhost"
|
||||
self.imap_account.port = 1143
|
||||
self.imap_account.ssl = False
|
||||
del account.hub.threadConnection
|
||||
|
||||
def tearDown(self):
|
||||
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||
IMAPAccount.dropTable(ifExists = True)
|
||||
MailAccount.dropTable(ifExists = True)
|
||||
PresenceAccount.dropTable(ifExists = True)
|
||||
Account.dropTable(ifExists = True)
|
||||
del TheURIOpener.cachedURIs['sqlite://' + DB_URL]
|
||||
account.hub.threadConnection.close()
|
||||
del account.hub.threadConnection
|
||||
if os.path.exists(DB_PATH):
|
||||
os.unlink(DB_PATH)
|
||||
self.server = None
|
||||
self.imap_connection = None
|
||||
self.imap_account = None
|
||||
|
||||
def make_test(responses = None, queries = None, core = None):
|
||||
def inner(self):
|
||||
@@ -250,12 +319,14 @@ class IMAPConnection_TestCase(unittest.TestCase):
|
||||
if queries:
|
||||
self.server.queries += queries
|
||||
self.server.queries += ["^[^ ]* LOGOUT"]
|
||||
self.imap_connection.connect()
|
||||
self.failUnless(self.imap_connection.connection, \
|
||||
self.imap_account.connect()
|
||||
self.failUnless(self.imap_account.connection, \
|
||||
"Cannot establish connection")
|
||||
if core:
|
||||
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||
core(self)
|
||||
self.imap_connection.disconnect()
|
||||
del account.hub.threadConnection
|
||||
self.imap_account.disconnect()
|
||||
self.failUnless(self.server.verify_queries())
|
||||
return inner
|
||||
|
||||
@@ -271,7 +342,7 @@ class IMAPConnection_TestCase(unittest.TestCase):
|
||||
["^[^ ]* SELECT INBOX", \
|
||||
"^[^ ]* SEARCH RECENT"], \
|
||||
lambda self: \
|
||||
self.assertEquals(self.imap_connection.get_mail_list(), ['9', '10']))
|
||||
self.assertEquals(self.imap_account.get_mail_list(), ['9', '10']))
|
||||
|
||||
test_get_mail_summary = make_test([lambda data: "* 42 EXISTS\r\n* 1 RECENT\r\n* OK" +\
|
||||
" [UNSEEN 9]\r\n* FLAGS (\Deleted \Seen\*)\r\n*" +\
|
||||
@@ -283,7 +354,7 @@ class IMAPConnection_TestCase(unittest.TestCase):
|
||||
data.split()[0] + " OK FETCH completed\r\n"], \
|
||||
["^[^ ]* EXAMINE INBOX", \
|
||||
"^[^ ]* FETCH 1 \(RFC822\)"], \
|
||||
lambda self: self.assertEquals(self.imap_connection.get_mail_summary(1), \
|
||||
lambda self: self.assertEquals(self.imap_account.get_mail_summary(1), \
|
||||
(u"From : None\nSubject : None\n\n", \
|
||||
u"None")))
|
||||
|
||||
@@ -297,7 +368,7 @@ class IMAPConnection_TestCase(unittest.TestCase):
|
||||
data.split()[0] + " OK FETCH completed\r\n"], \
|
||||
["^[^ ]* EXAMINE INBOX", \
|
||||
"^[^ ]* FETCH 1 \(RFC822\)",], \
|
||||
lambda self: self.assertEquals(self.imap_connection.get_mail(1), \
|
||||
lambda self: self.assertEquals(self.imap_account.get_mail(1), \
|
||||
(u"From : None\nSubject : None\n\nbody text\r\n\n", \
|
||||
u"None")))
|
||||
|
||||
@@ -1,355 +0,0 @@
|
||||
##
|
||||
## test_mailconnection_factory.py
|
||||
## Login : David Rousselie <david.rousselie@happycoders.org>
|
||||
## Started on Fri May 20 10:46:58 2005
|
||||
## $Id: test_component.py,v 1.2 2005/09/18 20:24:07 dax Exp $
|
||||
##
|
||||
## Copyright (C) 2005
|
||||
## This program is free software; you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published by
|
||||
## the Free Software Foundation; either version 2 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## This program is distributed in the hope that it will be useful,
|
||||
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
## GNU General Public License for more details.
|
||||
##
|
||||
## You should have received a copy of the GNU General Public License
|
||||
## along with this program; if not, write to the Free Software
|
||||
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
##
|
||||
|
||||
import thread
|
||||
import unittest
|
||||
import dummy_server
|
||||
import time
|
||||
import traceback
|
||||
from pyxmpp import xmlextra
|
||||
from jmc.jabber.component import *
|
||||
from jmc.utils.config import Config
|
||||
|
||||
class TestStreamHandler(xmlextra.StreamHandler):
|
||||
def __init__(self, expected_balises = []):
|
||||
xmlextra.StreamHandler.__init__(self)
|
||||
self.expected_balises = expected_balises
|
||||
|
||||
def stream_start(self, doc):
|
||||
pass
|
||||
|
||||
def stream_end(self, doc):
|
||||
pass
|
||||
|
||||
def stanza(self, notused, node):
|
||||
pass
|
||||
|
||||
class MailComponent_TestCase_NoConnection(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.mail_component = MailComponent(Config("tests/jmc-test.xml"))
|
||||
|
||||
def tearDown(self):
|
||||
self.mail_component = None
|
||||
|
||||
def test_get_reg_form(self):
|
||||
reg_form = self.mail_component.get_reg_form()
|
||||
reg_form2 = self.mail_component.get_reg_form()
|
||||
self.assertTrue(reg_form is reg_form2)
|
||||
|
||||
#TODO
|
||||
class MailComponent_TestCase_Basic(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.handler = TestStreamHandler()
|
||||
self.mail_component = MailComponent(Config("tests/jmc-test.xml"))
|
||||
self.server = dummy_server.XMLDummyServer("localhost", 55555, None, self.handler)
|
||||
thread.start_new_thread(self.server.serve, ())
|
||||
|
||||
def tearDown(self):
|
||||
self.server = None
|
||||
self.mail_component = None
|
||||
os.remove("./registered.db")
|
||||
|
||||
def test_run(self):
|
||||
self.server.responses = ["<?xml version='1.0'?><stream:stream xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:component:accept' id='4258238724' from='localhost'>", \
|
||||
"<handshake/></stream:stream>"]
|
||||
self.server.queries = ["<?xml version='1.0' encoding='UTF-8'?><stream:stream xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:component:accept' to='jmc.localhost' version='1.0'>", \
|
||||
"<handshake>[0-9abcdef]*</handshake>",
|
||||
"</stream:stream>"]
|
||||
self.mail_component.run(1)
|
||||
self.failUnless(self.server.verify_queries())
|
||||
# TODO : more assertion
|
||||
|
||||
class MailComponent_TestCase_NoReg(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.handler = TestStreamHandler()
|
||||
self.mail_component = MailComponent(Config("tests/jmc-test.xml"))
|
||||
self.server = dummy_server.XMLDummyServer("localhost", 55555, None, self.handler)
|
||||
thread.start_new_thread(self.server.serve, ())
|
||||
|
||||
def tearDown(self):
|
||||
self.server = None
|
||||
self.mail_component = None
|
||||
## TODO : be storage independant
|
||||
os.remove("./registered.db")
|
||||
|
||||
def test_disco_get_items(self):
|
||||
self.server.responses = ["<?xml version='1.0'?><stream:stream xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:component:accept' id='4258238724' from='localhost'>",
|
||||
"<handshake/><iq type='get' to='jmc.localhost' id='aabca'><query xmlns='http://jabber.org/protocol/disco#info'/></iq>",
|
||||
"</stream:stream>"]
|
||||
self.server.queries = ["<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + \
|
||||
"<stream:stream xmlns:stream=\"http://etherx.jabber.org/streams\" xmlns=\"jabber:component:accept\" to=\"jmc.localhost\" version=\"1.0\">", \
|
||||
"<handshake>[0-9abcdef]*</handshake>",
|
||||
"<iq from=\"jmc.localhost\" type=\"result\" id=\"aabca\"><query xmlns=\"http://jabber.org/protocol/disco#info\"><feature var=\"jabber:iq:version\"/><feature var=\"jabber:iq:register\"/><identity name=\"Jabber Mail Component\" category=\"headline\" type=\"mail\"/></query></iq>",
|
||||
"</stream:stream>"]
|
||||
self.mail_component.run(1)
|
||||
self.failUnless(self.server.verify_queries())
|
||||
|
||||
def test_get_register(self):
|
||||
self.server.responses = ["<?xml version='1.0'?><stream:stream xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:component:accept' id='4258238724' from='localhost'>",
|
||||
"<handshake/><iq type='get' to='jmc.localhost' from='test@localhost/test' id='aad9a'><query xmlns='jabber:iq:register'/></iq>",
|
||||
"</stream:stream>"]
|
||||
self.server.queries = ["<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + \
|
||||
"<stream:stream xmlns:stream=\"http://etherx.jabber.org/streams\" xmlns=\"jabber:component:accept\" to=\"jmc.localhost\" version=\"1.0\">", \
|
||||
"<handshake>[0-9abcdef]*</handshake>",
|
||||
"<iq from=\"jmc.localhost\" to=\"test@localhost/test\" type=\"result\" id=\"aad9a\">" + \
|
||||
"<query xmlns=\"jabber:iq:register\">" + \
|
||||
"<x xmlns=\"jabber:x:data\">" + \
|
||||
"<title>Jabber Mail connection registration</title>" + \
|
||||
"<instructions>Enter anything below</instructions>" + \
|
||||
"<field type=\"text-single\" label=\"Connection name\" var=\"name\"/>" + \
|
||||
"<field type=\"text-single\" label=\"Login\" var=\"login\"/>" + \
|
||||
"<field type=\"text-private\" label=\"Password\" var=\"password\"/>" + \
|
||||
"<field type=\"text-single\" label=\"Host\" var=\"host\"/>" + \
|
||||
"<field type=\"text-single\" label=\"Port\" var=\"port\"/>" + \
|
||||
"<field type=\"list-single\" label=\"Mailbox type\" var=\"type\">" + \
|
||||
"<option label=\"POP3\">" + \
|
||||
"<value>pop3</value>" + \
|
||||
"</option>" + \
|
||||
"<option label=\"POP3S\">" + \
|
||||
"<value>pop3s</value>" + \
|
||||
"</option>" + \
|
||||
"<option label=\"IMAP\">" + \
|
||||
"<value>imap</value>" + \
|
||||
"</option>" + \
|
||||
"<option label=\"IMAPS\">" + \
|
||||
"<value>imaps</value>" + \
|
||||
"</option>" + \
|
||||
"</field>" + \
|
||||
"<field type=\"text-single\" label=\"Mailbox (IMAP)\" var=\"mailbox\">" + \
|
||||
"<value>INBOX</value>" + \
|
||||
"</field>" + \
|
||||
"<field type=\"list-single\" label=\"Action when state is 'Free For Chat'\" var=\"chat_action\">" + \
|
||||
"<value>2</value>" + \
|
||||
"<option label=\"Do nothing\">" + \
|
||||
"<value>0</value>" + \
|
||||
"</option>" + \
|
||||
"<option label=\"Send mail digest\">" + \
|
||||
"<value>1</value>" + \
|
||||
"</option>" + \
|
||||
"<option label=\"Retrieve mail\">" + \
|
||||
"<value>2</value>" + \
|
||||
"</option>" + \
|
||||
"</field>" + \
|
||||
"<field type=\"list-single\" label=\"Action when state is 'Online'\" var=\"online_action\">" + \
|
||||
"<value>2</value>" + \
|
||||
"<option label=\"Do nothing\">" + \
|
||||
"<value>0</value>" + \
|
||||
"</option>" + \
|
||||
"<option label=\"Send mail digest\">" + \
|
||||
"<value>1</value>" + \
|
||||
"</option>" + \
|
||||
"<option label=\"Retrieve mail\">" + \
|
||||
"<value>2</value>" + \
|
||||
"</option>" + \
|
||||
"</field>" + \
|
||||
"<field type=\"list-single\" label=\"Action when state is 'Away'\" var=\"away_action\">" + \
|
||||
"<value>1</value>" + \
|
||||
"<option label=\"Do nothing\">" + \
|
||||
"<value>0</value>" + \
|
||||
"</option>" + \
|
||||
"<option label=\"Send mail digest\">" + \
|
||||
"<value>1</value>" + \
|
||||
"</option>" + \
|
||||
"<option label=\"Retrieve mail\">" + \
|
||||
"<value>2</value>" + \
|
||||
"</option>" + \
|
||||
"</field>" + \
|
||||
"<field type=\"list-single\" label=\"Action when state is 'Not Available'\" var=\"xa_action\">" + \
|
||||
"<value>1</value>" + \
|
||||
"<option label=\"Do nothing\">" + \
|
||||
"<value>0</value>" + \
|
||||
"</option>" + \
|
||||
"<option label=\"Send mail digest\">" + \
|
||||
"<value>1</value>" + \
|
||||
"</option>" + \
|
||||
"<option label=\"Retrieve mail\">" + \
|
||||
"<value>2</value>" + \
|
||||
"</option>" + \
|
||||
"</field>" + \
|
||||
"<field type=\"list-single\" label=\"Action when state is 'Do not Disturb'\" var=\"dnd_action\">" + \
|
||||
"<value>1</value>" + \
|
||||
"<option label=\"Do nothing\">" + \
|
||||
"<value>0</value>" + \
|
||||
"</option>" + \
|
||||
"<option label=\"Send mail digest\">" + \
|
||||
"<value>1</value>" + \
|
||||
"</option>" + \
|
||||
"<option label=\"Retrieve mail\">" + \
|
||||
"<value>2</value>" + \
|
||||
"</option>" + \
|
||||
"</field>" + \
|
||||
"<field type=\"list-single\" label=\"Action when state is 'Offline'\" var=\"offline_action\">" + \
|
||||
"<value>0</value>" + \
|
||||
"<option label=\"Do nothing\">" + \
|
||||
"<value>0</value>" + \
|
||||
"</option>" + \
|
||||
"<option label=\"Send mail digest\">" + \
|
||||
"<value>1</value>" + \
|
||||
"</option>" + \
|
||||
"<option label=\"Retrieve mail\">" + \
|
||||
"<value>2</value>" + \
|
||||
"</option>" + \
|
||||
"</field>" + \
|
||||
"<field type=\"text-single\" label=\"Mail check interval (in minutes)\" var=\"interval\">" + \
|
||||
"<value>5</value>" + \
|
||||
"</field>" + \
|
||||
"</x>" + \
|
||||
"</query>" + \
|
||||
"</iq>",
|
||||
"</stream:stream>"]
|
||||
self.mail_component.run(1)
|
||||
self.failUnless(self.server.verify_queries())
|
||||
|
||||
|
||||
def test_disco_get_info(self):
|
||||
self.server.responses = ["<?xml version='1.0'?><stream:stream xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:component:accept' id='4258238724' from='localhost'>",
|
||||
"<handshake/><iq type='get' to='jmc.localhost' from='test@localhost/test' id='aad9a'><query xmlns='http://jabber.org/protocol/disco#info'/></iq>",
|
||||
"</stream:stream>"]
|
||||
self.server.queries = ["<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + \
|
||||
"<stream:stream xmlns:stream=\"http://etherx.jabber.org/streams\" xmlns=\"jabber:component:accept\" to=\"jmc.localhost\" version=\"1.0\">",
|
||||
"<handshake>[0-9abcdef]*</handshake>",
|
||||
"<iq from=\"jmc.localhost\" to=\"test@localhost/test\" type=\"result\" id=\"aad9a\">" + \
|
||||
"<query xmlns=\"http://jabber.org/protocol/disco#info\">" + \
|
||||
"<feature var=\"jabber:iq:version\"/>" + \
|
||||
"<feature var=\"jabber:iq:register\"/>" + \
|
||||
"<identity name=\"Jabber Mail Component\" category=\"headline\" type=\"mail\"/>" + \
|
||||
"</query></iq>",
|
||||
"</stream:stream>"]
|
||||
self.mail_component.run(1)
|
||||
self.failUnless(self.server.verify_queries())
|
||||
|
||||
def test_set_register(self):
|
||||
self.server.responses = ["<?xml version='1.0'?><stream:stream xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:component:accept' id='4258238724' from='localhost'>", \
|
||||
"<handshake/>" + \
|
||||
"<iq from='test@localhost/test' to='jmc.localhost' type='set' id='aacaa'>" + \
|
||||
"<query xmlns='jabber:iq:register'>" + \
|
||||
"<x xmlns='jabber:x:data' type='submit'>" + \
|
||||
"<field type='text-single' var='name'>" + \
|
||||
"<value>test</value>" + \
|
||||
"</field>" + \
|
||||
"<field type='text-single' var='login'>" + \
|
||||
"<value>logintest</value>" + \
|
||||
"</field>" + \
|
||||
"<field type='text-private' var='password'>" + \
|
||||
"<value>passtest</value>" + \
|
||||
"</field>" + \
|
||||
"<field type='text-single' var='host'>" + \
|
||||
"<value>hosttest</value>" + \
|
||||
"</field>" + \
|
||||
"<field type='text-single' var='port'>" + \
|
||||
"<value>993</value>" + \
|
||||
"</field>" + \
|
||||
"<field type='list-single' var='type'>" + \
|
||||
"<value>imaps</value>" + \
|
||||
"</field>" + \
|
||||
"<field type='text-single' var='mailbox'>" + \
|
||||
"<value>INBOX</value>" + \
|
||||
"</field>" + \
|
||||
"<field type='list-single' var='chat_action'>" + \
|
||||
"<value>2</value>" + \
|
||||
"</field>" + \
|
||||
"<field type='list-single' var='online_action'>" + \
|
||||
"<value>2</value>" + \
|
||||
"</field>" + \
|
||||
"<field type='list-single' var='away_action'>" + \
|
||||
"<value>1</value>" + \
|
||||
"</field>" + \
|
||||
"<field type='list-single' var='xa_action'>" + \
|
||||
"<value>1</value>" + \
|
||||
"</field>" + \
|
||||
"<field type='list-single' var='dnd_action'>" + \
|
||||
"<value>1</value>" + \
|
||||
"</field>" + \
|
||||
"<field type='list-single' var='offline_action'>" + \
|
||||
"<value>0</value>" + \
|
||||
"</field>" + \
|
||||
"<field type='text-single' var='interval'>" + \
|
||||
"<value>5</value>" + \
|
||||
"</field>" + \
|
||||
"</x>" + \
|
||||
"</query></iq>",
|
||||
lambda x: None,
|
||||
"</stream:stream>"]
|
||||
self.server.queries = ["<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + \
|
||||
"<stream:stream xmlns:stream=\"http://etherx.jabber.org/streams\" xmlns=\"jabber:component:accept\" to=\"jmc.localhost\" version=\"1.0\">", \
|
||||
"<handshake>[0-9abcdef]*</handshake>", \
|
||||
"<iq from=\"jmc.localhost\" to=\"test@localhost/test\" type=\"result\" id=\"aacaa\"/>",
|
||||
"<presence from=\"jmc.localhost\" to=\"test@localhost\" type=\"subscribe\"/>",
|
||||
"<message from=\"jmc.localhost\" to=\"test@localhost/test\" type=\"message\"><body>New imaps connection \\'test\\': Registered with username \\'logintest\\' and password \\'passtest\\' on \\'hosttest:993\\'</body></message>",
|
||||
"<presence from=\"test@jmc.localhost\" to=\"test@localhost\" type=\"subscribe\"/>",
|
||||
"</stream:stream>"]
|
||||
self.mail_component.run(1)
|
||||
self.failUnless(self.server.verify_queries())
|
||||
|
||||
class MailComponent_TestCase_Reg(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.mail_component = MailComponent(Config("tests/jmc-test.xml"))
|
||||
self.mail_component.set_register(iq = None)
|
||||
|
||||
def test_get_reg_form_init(self):
|
||||
pass
|
||||
|
||||
def test_get_reg_form_init_2pass(self):
|
||||
pass
|
||||
|
||||
def test_disco_get_items(self):
|
||||
pass
|
||||
|
||||
def test_get_register(self):
|
||||
pass
|
||||
|
||||
def test_set_register_update(self):
|
||||
pass
|
||||
|
||||
def test_set_register_remove(self):
|
||||
pass
|
||||
|
||||
def test_presence_available_transport(self):
|
||||
pass
|
||||
|
||||
def test_presence_available_mailbox(self):
|
||||
pass
|
||||
|
||||
def test_presence_unavailable_transport(self):
|
||||
pass
|
||||
|
||||
def test_presence_unavailable_mailbox(self):
|
||||
pass
|
||||
|
||||
def test_presence_subscribe(self):
|
||||
pass
|
||||
|
||||
def test_presence_subscribed_transport(self):
|
||||
pass
|
||||
|
||||
def test_presence_subscribed_mailbox(self):
|
||||
pass
|
||||
|
||||
def test_presence_unsubscribe(self):
|
||||
pass
|
||||
|
||||
def test_presence_unsubscribed(self):
|
||||
pass
|
||||
|
||||
def test_check_mail(self):
|
||||
pass
|
||||
|
||||
@@ -1,204 +0,0 @@
|
||||
##
|
||||
## test_mailconnection_factory.py
|
||||
## Login : David Rousselie <david.rousselie@happycoders.org>
|
||||
## Started on Fri May 20 10:46:58 2005
|
||||
## $Id: test_mailconnection_factory.py,v 1.1 2005/07/11 20:39:31 dax Exp $
|
||||
##
|
||||
## Copyright (C) 2005
|
||||
## This program is free software; you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published by
|
||||
## the Free Software Foundation; either version 2 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## This program is distributed in the hope that it will be useful,
|
||||
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
## GNU General Public License for more details.
|
||||
##
|
||||
## You should have received a copy of the GNU General Public License
|
||||
## along with this program; if not, write to the Free Software
|
||||
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
##
|
||||
|
||||
import unittest
|
||||
from jmc.email.mailconnection_factory import *
|
||||
from jmc.email.mailconnection import *
|
||||
import jmc.email.mailconnection as mailconnection
|
||||
|
||||
class MailConnectionFactory_TestCase(unittest.TestCase):
|
||||
def test_new_mail_connection_imap(self):
|
||||
mc = get_new_mail_connection("imap")
|
||||
self.assertEquals(mc, IMAPConnection())
|
||||
|
||||
def test_new_mail_connection_imaps(self):
|
||||
mc = get_new_mail_connection("imaps")
|
||||
self.assertEquals(mc, IMAPConnection(ssl = True))
|
||||
|
||||
def test_new_mail_connection_pop3(self):
|
||||
mc = get_new_mail_connection("pop3")
|
||||
self.assertEquals(mc, POP3Connection())
|
||||
|
||||
def test_new_mail_connection_pop3s(self):
|
||||
mc = get_new_mail_connection("pop3s")
|
||||
self.assertEquals(mc, POP3Connection(ssl = True))
|
||||
|
||||
def test_new_mail_connection_unknown(self):
|
||||
self.assertRaises(Exception, get_new_mail_connection, "unknown")
|
||||
|
||||
def test_str_to_mail_connection_imap_v01_v02(self):
|
||||
mc = str_to_mail_connection("imap#login#passwd#host#193#False#INBOX")
|
||||
self.assertEquals(mc.get_type(), "imap")
|
||||
self.assertEquals(mc.login, "login")
|
||||
self.assertEquals(mc.password, "passwd")
|
||||
self.assertEquals(mc.store_password, True)
|
||||
self.assertEquals(mc.host, "host")
|
||||
self.assertEquals(mc.port, 193)
|
||||
self.assertEquals(mc.mailbox, "INBOX")
|
||||
self.assertEquals(mc.chat_action, mailconnection.DIGEST)
|
||||
self.assertEquals(mc.online_action, mailconnection.DIGEST)
|
||||
self.assertEquals(mc.away_action, mailconnection.DIGEST)
|
||||
self.assertEquals(mc.xa_action, mailconnection.DIGEST)
|
||||
self.assertEquals(mc.dnd_action, mailconnection.DIGEST)
|
||||
self.assertEquals(mc.offline_action, mailconnection.DO_NOTHING)
|
||||
self.assertEquals(mc.interval, 5)
|
||||
self.assertEquals(mc.live_email_only, False)
|
||||
|
||||
def test_str_to_mail_connection_imap_v01_v02_retrieve(self):
|
||||
mc = str_to_mail_connection("imap#login#passwd#host#193#True#INBOX")
|
||||
self.assertEquals(mc.get_type(), "imap")
|
||||
self.assertEquals(mc.login, "login")
|
||||
self.assertEquals(mc.password, "passwd")
|
||||
self.assertEquals(mc.store_password, True)
|
||||
self.assertEquals(mc.host, "host")
|
||||
self.assertEquals(mc.port, 193)
|
||||
self.assertEquals(mc.mailbox, "INBOX")
|
||||
self.assertEquals(mc.chat_action, mailconnection.RETRIEVE)
|
||||
self.assertEquals(mc.online_action, mailconnection.RETRIEVE)
|
||||
self.assertEquals(mc.away_action, mailconnection.RETRIEVE)
|
||||
self.assertEquals(mc.xa_action, mailconnection.RETRIEVE)
|
||||
self.assertEquals(mc.dnd_action, mailconnection.RETRIEVE)
|
||||
self.assertEquals(mc.offline_action, mailconnection.DO_NOTHING)
|
||||
self.assertEquals(mc.interval, 5)
|
||||
self.assertEquals(mc.live_email_only, False)
|
||||
|
||||
def test_str_to_mail_connection_pop3_v01_v02(self):
|
||||
mc = str_to_mail_connection("pop3#login#passwd#host#110#False")
|
||||
self.assertEquals(mc.get_type(), "pop3")
|
||||
self.assertEquals(mc.login, "login")
|
||||
self.assertEquals(mc.password, "passwd")
|
||||
self.assertEquals(mc.store_password, True)
|
||||
self.assertEquals(mc.host, "host")
|
||||
self.assertEquals(mc.port, 110)
|
||||
self.assertEquals(mc.chat_action, mailconnection.DIGEST)
|
||||
self.assertEquals(mc.online_action, mailconnection.DIGEST)
|
||||
self.assertEquals(mc.away_action, mailconnection.DIGEST)
|
||||
self.assertEquals(mc.xa_action, mailconnection.DIGEST)
|
||||
self.assertEquals(mc.dnd_action, mailconnection.DIGEST)
|
||||
self.assertEquals(mc.offline_action, mailconnection.DO_NOTHING)
|
||||
self.assertEquals(mc.interval, 5)
|
||||
self.assertEquals(mc.live_email_only, False)
|
||||
|
||||
def test_str_to_mail_connection_pop3_v01_v02_retrieve(self):
|
||||
mc = str_to_mail_connection("pop3#login#passwd#host#110#True")
|
||||
self.assertEquals(mc.get_type(), "pop3")
|
||||
self.assertEquals(mc.login, "login")
|
||||
self.assertEquals(mc.password, "passwd")
|
||||
self.assertEquals(mc.store_password, True)
|
||||
self.assertEquals(mc.host, "host")
|
||||
self.assertEquals(mc.port, 110)
|
||||
self.assertEquals(mc.chat_action, mailconnection.RETRIEVE)
|
||||
self.assertEquals(mc.online_action, mailconnection.RETRIEVE)
|
||||
self.assertEquals(mc.away_action, mailconnection.RETRIEVE)
|
||||
self.assertEquals(mc.xa_action, mailconnection.RETRIEVE)
|
||||
self.assertEquals(mc.dnd_action, mailconnection.RETRIEVE)
|
||||
self.assertEquals(mc.offline_action, mailconnection.DO_NOTHING)
|
||||
self.assertEquals(mc.interval, 5)
|
||||
self.assertEquals(mc.live_email_only, False)
|
||||
|
||||
def test_str_to_mail_connection_imap(self):
|
||||
mc = str_to_mail_connection("imap#login#passwd#host#193#0#0#0#1#1#2#4#True#INBOX")
|
||||
self.assertEquals(mc.get_type(), "imap")
|
||||
self.assertEquals(mc.login, "login")
|
||||
self.assertEquals(mc.password, "passwd")
|
||||
self.assertEquals(mc.host, "host")
|
||||
self.assertEquals(mc.port, 193)
|
||||
self.assertEquals(mc.mailbox, "INBOX")
|
||||
self.assertEquals(mc.chat_action, mailconnection.DO_NOTHING)
|
||||
self.assertEquals(mc.online_action, mailconnection.DO_NOTHING)
|
||||
self.assertEquals(mc.away_action, mailconnection.DO_NOTHING)
|
||||
self.assertEquals(mc.xa_action, mailconnection.DIGEST)
|
||||
self.assertEquals(mc.dnd_action, mailconnection.DIGEST)
|
||||
self.assertEquals(mc.offline_action, mailconnection.RETRIEVE)
|
||||
self.assertEquals(mc.interval, 4)
|
||||
self.assertEquals(mc.live_email_only, True)
|
||||
|
||||
def test_str_to_mail_connection_no_password(self):
|
||||
mc = str_to_mail_connection("imap#login#/\\#host#193#0#0#0#1#1#2#4#False#INBOX")
|
||||
self.assertEquals(mc.get_type(), "imap")
|
||||
self.assertEquals(mc.login, "login")
|
||||
self.assertEquals(mc.password, None)
|
||||
self.assertEquals(mc.store_password, False)
|
||||
self.assertEquals(mc.host, "host")
|
||||
self.assertEquals(mc.port, 193)
|
||||
self.assertEquals(mc.mailbox, "INBOX")
|
||||
self.assertEquals(mc.chat_action, mailconnection.DO_NOTHING)
|
||||
self.assertEquals(mc.online_action, mailconnection.DO_NOTHING)
|
||||
self.assertEquals(mc.away_action, mailconnection.DO_NOTHING)
|
||||
self.assertEquals(mc.xa_action, mailconnection.DIGEST)
|
||||
self.assertEquals(mc.dnd_action, mailconnection.DIGEST)
|
||||
self.assertEquals(mc.offline_action, mailconnection.RETRIEVE)
|
||||
self.assertEquals(mc.interval, 4)
|
||||
self.assertEquals(mc.live_email_only, False)
|
||||
|
||||
def test_str_to_mail_connection_imaps(self):
|
||||
mc = str_to_mail_connection("imaps#login#passwd#host#993#0#0#0#1#1#2#4#True#INBOX.SubDir")
|
||||
self.assertEquals(mc.get_type(), "imaps")
|
||||
self.assertEquals(mc.login, "login")
|
||||
self.assertEquals(mc.password, "passwd")
|
||||
self.assertEquals(mc.host, "host")
|
||||
self.assertEquals(mc.port, 993)
|
||||
self.assertEquals(mc.mailbox, "INBOX.SubDir")
|
||||
self.assertEquals(mc.chat_action, mailconnection.DO_NOTHING)
|
||||
self.assertEquals(mc.online_action, mailconnection.DO_NOTHING)
|
||||
self.assertEquals(mc.away_action, mailconnection.DO_NOTHING)
|
||||
self.assertEquals(mc.xa_action, mailconnection.DIGEST)
|
||||
self.assertEquals(mc.dnd_action, mailconnection.DIGEST)
|
||||
self.assertEquals(mc.offline_action, mailconnection.RETRIEVE)
|
||||
self.assertEquals(mc.interval, 4)
|
||||
self.assertEquals(mc.live_email_only, True)
|
||||
|
||||
def test_str_to_mail_connection_pop3(self):
|
||||
mc = str_to_mail_connection("pop3#login#passwd#host#110#0#0#0#1#1#2#4#False")
|
||||
self.assertEquals(mc.get_type(), "pop3")
|
||||
self.assertEquals(mc.login, "login")
|
||||
self.assertEquals(mc.password, "passwd")
|
||||
self.assertEquals(mc.host, "host")
|
||||
self.assertEquals(mc.port, 110)
|
||||
self.assertEquals(mc.chat_action, mailconnection.DO_NOTHING)
|
||||
self.assertEquals(mc.online_action, mailconnection.DO_NOTHING)
|
||||
self.assertEquals(mc.away_action, mailconnection.DO_NOTHING)
|
||||
self.assertEquals(mc.xa_action, mailconnection.DIGEST)
|
||||
self.assertEquals(mc.dnd_action, mailconnection.DIGEST)
|
||||
self.assertEquals(mc.offline_action, mailconnection.RETRIEVE)
|
||||
self.assertEquals(mc.interval, 4)
|
||||
self.assertEquals(mc.live_email_only, False)
|
||||
|
||||
def test_str_to_mail_connection_pop3s(self):
|
||||
mc = str_to_mail_connection("pop3s#login#passwd#host#995#0#0#0#1#1#2#4#True")
|
||||
self.assertEquals(mc.get_type(), "pop3s")
|
||||
self.assertEquals(mc.login, "login")
|
||||
self.assertEquals(mc.password, "passwd")
|
||||
self.assertEquals(mc.host, "host")
|
||||
self.assertEquals(mc.port, 995)
|
||||
self.assertEquals(mc.chat_action, mailconnection.DO_NOTHING)
|
||||
self.assertEquals(mc.online_action, mailconnection.DO_NOTHING)
|
||||
self.assertEquals(mc.away_action, mailconnection.DO_NOTHING)
|
||||
self.assertEquals(mc.xa_action, mailconnection.DIGEST)
|
||||
self.assertEquals(mc.dnd_action, mailconnection.DIGEST)
|
||||
self.assertEquals(mc.offline_action, mailconnection.RETRIEVE)
|
||||
self.assertEquals(mc.interval, 4)
|
||||
self.assertEquals(mc.live_email_only, True)
|
||||
|
||||
def test_str_to_mail_connection_unknown(self):
|
||||
self.assertRaises(Exception, str_to_mail_connection, ("unknown#login#passwd#host#995#0#0#0#1#1#2#4#True"))
|
||||
|
||||
@@ -1,224 +0,0 @@
|
||||
##
|
||||
## test_storage.py
|
||||
## Login : David Rousselie <dax@happycoders.org>
|
||||
## Started on Fri May 20 10:46:58 2005 dax
|
||||
## $Id: test_component.py,v 1.1 2005/07/11 20:39:31 dax Exp $
|
||||
##
|
||||
## Copyright (C) 2005 adro8400
|
||||
## This program is free software; you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published by
|
||||
## the Free Software Foundation; either version 2 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## This program is distributed in the hope that it will be useful,
|
||||
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
## GNU General Public License for more details.
|
||||
##
|
||||
## You should have received a copy of the GNU General Public License
|
||||
## along with this program; if not, write to the Free Software
|
||||
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
##
|
||||
|
||||
import os
|
||||
import unittest
|
||||
import dummy_server
|
||||
from jmc.utils.storage import *
|
||||
from jmc.email.mailconnection import *
|
||||
import jmc.email.mailconnection as mailconnection
|
||||
|
||||
class Storage_TestCase(unittest.TestCase):
|
||||
def test_init(self):
|
||||
spool_dir = "./spool/test"
|
||||
self._storage = Storage(spool_dir = spool_dir)
|
||||
self.assertTrue(os.access(spool_dir, os.F_OK))
|
||||
self.assertEquals(self._storage.spool_dir, spool_dir)
|
||||
os.removedirs(spool_dir)
|
||||
|
||||
class DBMStorage_TestCase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
spool_dir = "./spool/test"
|
||||
self._storage = DBMStorage(nb_pk_fields = 2, spool_dir = spool_dir)
|
||||
self._account1 = IMAPConnection(login = "login1",
|
||||
password = "password1",
|
||||
host = "host1",
|
||||
port = 993,
|
||||
ssl = True,
|
||||
mailbox = "INBOX.box1")
|
||||
self._account1.chat_action = mailconnection.DO_NOTHING
|
||||
self._account1.online_action = mailconnection.DO_NOTHING
|
||||
self._account1.away_action = mailconnection.DO_NOTHING
|
||||
self._account1.xa_action = mailconnection.DO_NOTHING
|
||||
self._account1.dnd_action = mailconnection.DO_NOTHING
|
||||
self._account1.offline_action = mailconnection.DO_NOTHING
|
||||
self._account1.interval = 4
|
||||
self._account2 = POP3Connection(login = "login2",
|
||||
password = "password2",
|
||||
host = "host2",
|
||||
port = 1110,
|
||||
ssl = False)
|
||||
self._account2.chat_action = mailconnection.DO_NOTHING
|
||||
self._account2.online_action = mailconnection.DO_NOTHING
|
||||
self._account2.away_action = mailconnection.DO_NOTHING
|
||||
self._account2.xa_action = mailconnection.DO_NOTHING
|
||||
self._account2.dnd_action = mailconnection.DO_NOTHING
|
||||
self._account2.offline_action = mailconnection.DO_NOTHING
|
||||
self._account2.interval = 4
|
||||
self._account2.store_password = False
|
||||
self._account2.live_email_only = True
|
||||
|
||||
def tearDown(self):
|
||||
db_file = self._storage.file
|
||||
self._storage = None
|
||||
os.remove(db_file)
|
||||
|
||||
def test_set_get(self):
|
||||
self._storage[("test@localhost", "account1")] = self._account1
|
||||
self._storage[("test@localhost", "account2")] = self._account2
|
||||
self.assertEquals(self._storage[("test@localhost", "account1")],
|
||||
self._account1)
|
||||
self.assertEquals(self._storage[("test@localhost", "account2")],
|
||||
self._account2)
|
||||
|
||||
def test_set_sync_get(self):
|
||||
self._storage[("test@localhost", "account1")] = self._account1
|
||||
self._storage[("test@localhost", "account2")] = self._account2
|
||||
loaded_storage = DBMStorage(nb_pk_fields = 2, spool_dir = "./spool/test")
|
||||
self.assertEquals(loaded_storage[("test@localhost", "account1")],
|
||||
self._account1)
|
||||
self.assertEquals(loaded_storage[("test@localhost", "account2")],
|
||||
self._account2)
|
||||
|
||||
def test_set_del_get(self):
|
||||
self._storage[("test@localhost", "account2")] = self._account2
|
||||
del self._storage[("test@localhost", "account2")]
|
||||
try:
|
||||
self._storage[("test@localhost", "account2")]
|
||||
except KeyError:
|
||||
return
|
||||
self.fail("KeyError was expected")
|
||||
|
||||
def test_haskey(self):
|
||||
self._storage[("test@localhost", "account2")] = self._account2
|
||||
self.assertTrue(self._storage.has_key((u"test@localhost", u"account2")))
|
||||
|
||||
def test_partial_haskey(self):
|
||||
self._storage[("test@localhost", "account2")] = self._account2
|
||||
self.assertTrue(self._storage.has_key((u"test@localhost",)))
|
||||
|
||||
def test_get_filtered(self):
|
||||
self._storage[("test@localhost", "account1")] = self._account1
|
||||
self._storage[("test@localhost", "account2")] = self._account2
|
||||
result = self._storage[("test@localhost",)]
|
||||
self.assertEquals(type(result), list)
|
||||
self.assertEquals(len(result), 2)
|
||||
self.assertEquals(result[1], self._account1)
|
||||
self.assertEquals(result[0], self._account2)
|
||||
|
||||
def test_get_filtered2(self):
|
||||
self._storage[("test@localhost", "account1")] = self._account1
|
||||
self._storage[("test@localhost", "account2")] = self._account2
|
||||
result = self._storage[("account1",)]
|
||||
self.assertEquals(type(result), list)
|
||||
self.assertEquals(len(result), 1)
|
||||
self.assertEquals(result[0], self._account1)
|
||||
|
||||
def test_keys(self):
|
||||
self._storage[("test@localhost", "account1")] = self._account1
|
||||
self._storage[("test@localhost", "account2")] = self._account2
|
||||
result = self._storage.keys()
|
||||
self.assertEquals(type(result), list)
|
||||
self.assertEquals(len(result), 2)
|
||||
self.assertEquals(type(result[1]), tuple)
|
||||
self.assertEquals(len(result[1]), 2)
|
||||
self.assertEquals(result[1][0], "test@localhost")
|
||||
self.assertEquals(result[1][1], "account1")
|
||||
self.assertEquals(type(result[0]), tuple)
|
||||
self.assertEquals(len(result[0]), 2)
|
||||
self.assertEquals(result[0][0], "test@localhost")
|
||||
self.assertEquals(result[0][1], "account2")
|
||||
|
||||
def test_keys_filtered(self):
|
||||
self._storage[("test@localhost", "account1")] = self._account1
|
||||
self._storage[("test@localhost", "account2")] = self._account2
|
||||
result = self._storage.keys(())
|
||||
self.assertEquals(type(result), list)
|
||||
self.assertEquals(len(result), 1)
|
||||
self.assertEquals(result[0], "test@localhost")
|
||||
|
||||
def test_keys_filtered2(self):
|
||||
self._storage[("test@localhost", "account1")] = self._account1
|
||||
self._storage[("test@localhost", "account2")] = self._account2
|
||||
result = self._storage.keys(("test@localhost",))
|
||||
self.assertEquals(type(result), list)
|
||||
self.assertEquals(len(result), 2)
|
||||
self.assertEquals(result[0], "account2")
|
||||
self.assertEquals(result[1], "account1")
|
||||
|
||||
def test_del_sync_get(self):
|
||||
self._storage[("test@localhost", "account1")] = self._account1
|
||||
self._storage[("test@localhost", "account2")] = self._account2
|
||||
del self._storage[("test@localhost", "account2")]
|
||||
loaded_storage = DBMStorage(nb_pk_fields = 2, spool_dir = "./spool/test")
|
||||
self.assertEquals(len(loaded_storage.keys()),
|
||||
1)
|
||||
self.assertEquals(loaded_storage[("test@localhost", "account1")],
|
||||
self._account1)
|
||||
|
||||
class SQLiteStorage_TestCase(DBMStorage_TestCase):
|
||||
def setUp(self):
|
||||
spool_dir = "./spool/test"
|
||||
self._storage = SQLiteStorage(nb_pk_fields = 2, spool_dir = spool_dir)
|
||||
self._account1 = IMAPConnection(login = "login1",
|
||||
password = "password1",
|
||||
host = "host1",
|
||||
port = 993,
|
||||
ssl = True,
|
||||
mailbox = "INBOX.box1")
|
||||
self._account1.chat_action = mailconnection.DIGEST
|
||||
self._account1.online_action = mailconnection.DIGEST
|
||||
self._account1.away_action = mailconnection.DO_NOTHING
|
||||
self._account1.xa_action = mailconnection.DO_NOTHING
|
||||
self._account1.dnd_action = mailconnection.DO_NOTHING
|
||||
self._account1.offline_action = mailconnection.DO_NOTHING
|
||||
self._account1.interval = 4
|
||||
self._account2 = POP3Connection(login = "login2",
|
||||
password = "password2",
|
||||
host = "host2",
|
||||
port = 1993,
|
||||
ssl = False)
|
||||
self._account2.chat_action = mailconnection.DO_NOTHING
|
||||
self._account2.online_action = mailconnection.DO_NOTHING
|
||||
self._account2.away_action = mailconnection.DO_NOTHING
|
||||
self._account2.xa_action = mailconnection.DO_NOTHING
|
||||
self._account2.dnd_action = mailconnection.DO_NOTHING
|
||||
self._account2.offline_action = mailconnection.DO_NOTHING
|
||||
self._account2.interval = 4
|
||||
self._account2.store_password = False
|
||||
self._account2.live_email_only = True
|
||||
|
||||
# def tearDown(self):
|
||||
# os.remove(self._storage.file)
|
||||
# self._storage = None
|
||||
|
||||
|
||||
def test_set_sync_get(self):
|
||||
self._storage[("test@localhost", "account1")] = self._account1
|
||||
self._storage[("test@localhost", "account2")] = self._account2
|
||||
self._account2.password = None
|
||||
loaded_storage = SQLiteStorage(nb_pk_fields = 2, spool_dir = "./spool/test")
|
||||
self.assertEquals(loaded_storage[("test@localhost", "account1")],
|
||||
self._account1)
|
||||
self.assertEquals(loaded_storage[("test@localhost", "account2")],
|
||||
self._account2)
|
||||
|
||||
def test_del_sync_get(self):
|
||||
self._storage[("test@localhost", "account1")] = self._account1
|
||||
self._storage[("test@localhost", "account2")] = self._account2
|
||||
del self._storage[("test@localhost", "account2")]
|
||||
loaded_storage = SQLiteStorage(nb_pk_fields = 2, spool_dir = "./spool/test")
|
||||
self.assertEquals(len(loaded_storage.keys()),
|
||||
1)
|
||||
self.assertEquals(loaded_storage[("test@localhost", "account1")],
|
||||
self._account1)
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
##
|
||||
## test_x.py
|
||||
## Login : David Rousselie <david.rousselie@happycoders.org>
|
||||
## Started on Fri May 20 10:46:58 2005
|
||||
## $Id: test_x.py,v 1.1 2005/07/11 20:39:31 dax Exp $
|
||||
##
|
||||
## Copyright (C) 2005
|
||||
## This program is free software; you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published by
|
||||
## the Free Software Foundation; either version 2 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## This program is distributed in the hope that it will be useful,
|
||||
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
## GNU General Public License for more details.
|
||||
##
|
||||
## You should have received a copy of the GNU General Public License
|
||||
## along with this program; if not, write to the Free Software
|
||||
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
##
|
||||
|
||||
import unittest
|
||||
from jmc.jabber.x import *
|
||||
|
||||
class X_TestCase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.mail_component = MailComponent()
|
||||
|
||||
def test_get_form(self):
|
||||
self.reg_form.add_field(type = "text-single", \
|
||||
label = "Connection name", \
|
||||
var = "name")
|
||||
|
||||
self.reg_form.add_field(type = "text-single", \
|
||||
label = "Login", \
|
||||
var = "login")
|
||||
|
||||
self.reg_form.add_field(type = "text-private", \
|
||||
label = "password", \
|
||||
var = "password")
|
||||
|
||||
self.reg_form.add_field(type = "text-single", \
|
||||
label = "Host", \
|
||||
var = "host")
|
||||
|
||||
self.reg_form.add_field(type = "text-single", \
|
||||
label = "Port", \
|
||||
var = "port")
|
||||
|
||||
field = self.reg_form.add_field(type = "list-single", \
|
||||
label = "Mailbox type", \
|
||||
var = "type")
|
||||
field.add_option(label = "POP3", \
|
||||
value = "pop3")
|
||||
field.add_option(label = "POP3S", \
|
||||
value = "pop3s")
|
||||
field.add_option(label = "IMAP", \
|
||||
value = "imap")
|
||||
field.add_option(label = "IMAPS", \
|
||||
value = "imaps")
|
||||
|
||||
self.reg_form.add_field(type = "text-single", \
|
||||
label = "Mailbox (IMAP)", \
|
||||
var = "mailbox", \
|
||||
value = "INBOX")
|
||||
|
||||
self.reg_form.add_field(type = "boolean", \
|
||||
label = "Retrieve mail", \
|
||||
var = "retrieve")
|
||||
pass
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
##
|
||||
## utils.py
|
||||
## Login : David Rousselie <dax@happycoders.org>
|
||||
## Started on Mon Oct 24 21:44:43 2005 dax
|
||||
## $Id$
|
||||
##
|
||||
## Copyright (C) 2005 dax
|
||||
## This program is free software; you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published by
|
||||
## the Free Software Foundation; either version 2 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## This program is distributed in the hope that it will be useful,
|
||||
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
## GNU General Public License for more details.
|
||||
##
|
||||
## You should have received a copy of the GNU General Public License
|
||||
## along with this program; if not, write to the Free Software
|
||||
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
##
|
||||
|
||||
import xml.dom.minidom
|
||||
import re
|
||||
|
||||
def xmldiff(node1, node2):
|
||||
if node1.nodeType == node1.TEXT_NODE:
|
||||
if not node2.nodeType == node2.TEXT_NODE \
|
||||
or re.compile(node2.data + "$").match(node1.data) is None:
|
||||
raise Exception("data in text node " + node1.data + " does not match " + node2.data)
|
||||
elif node1.nodeType == node1.DOCUMENT_NODE:
|
||||
if not node2.nodeType == node2.DOCUMENT_NODE:
|
||||
raise Exception("node1 is Document but not node2 (" + node2.nodeType + ")")
|
||||
elif node1.tagName != node2.tagName:
|
||||
raise Exception("Different tag name : " + node1.tagName + " != " + node2.tagName)
|
||||
else:
|
||||
for attr in node1._get_attributes().keys():
|
||||
if not node2.hasAttribute(attr) \
|
||||
or node1.getAttribute(attr) != node2.getAttribute(attr):
|
||||
raise Exception("(" + node1.tagName + ") Different attributes : " + node1.getAttribute(attr) + " != " + node2.getAttribute(attr))
|
||||
if len(node1.childNodes) != len(node2.childNodes):
|
||||
raise Exception("(" + node1.tagName + ") Different children number : " + str(len(node1.childNodes)) + " != " + str(len(node2.childNodes)))
|
||||
for i in range(len(node1.childNodes)):
|
||||
xmldiff(node1.childNodes[i], node2.childNodes[i])
|
||||
|
||||
# def xmldiff(events1, events2):
|
||||
# for (event1, node1) in events1:
|
||||
# (event2, node2) = events2.next()
|
||||
# print event1 + " " + str(node1)
|
||||
# if not (event1 == event2) or not xml_diff_nodes(node1, node2):
|
||||
# return False
|
||||
# return True
|
||||
|
||||
if __name__ == "__main__":
|
||||
document1 = """\
|
||||
<slideshow attr='value'>
|
||||
<title>Demo slideshow</title>
|
||||
<slide><title>Slide title</title>
|
||||
<point>This is a demo</point>
|
||||
<point>Of a program for processing slides</point>
|
||||
</slide>
|
||||
|
||||
<slide><title>Another demo slide</title>
|
||||
<point>It is important</point>
|
||||
<point>To have more than</point>
|
||||
<point>one slide</point>
|
||||
</slide>
|
||||
</slideshow>
|
||||
"""
|
||||
|
||||
document2 = """\
|
||||
<slideshow attr='value'>
|
||||
<title>Demo slideshow</title>
|
||||
<slide><title>Slide title</title>
|
||||
<point>This is a demo</point>
|
||||
<point>Of a program for processing slides</point>
|
||||
</slide>
|
||||
|
||||
<slide><title>Another demo slide</title>
|
||||
<point>It is important</point>
|
||||
<point>To have more than</point>
|
||||
<point>one slide</point>
|
||||
</slide>
|
||||
</slideshow>
|
||||
"""
|
||||
|
||||
dom1 = xml.dom.minidom.parseString(document1)
|
||||
dom2 = xml.dom.minidom.parseString(document2)
|
||||
|
||||
try:
|
||||
xmldiff(dom1, dom2)
|
||||
except Exception, msg:
|
||||
print msg
|
||||
|
||||
|
||||
Reference in New Issue
Block a user