first passed component tests
Make the first component tests pass by correcting XMLDummyServer and xmldiff (in tests/utils.py) darcs-hash:20051127155735-684f5-82dc72186ef66c59ac9671f83d1ec90ea66ee5b1.gz
This commit is contained in:
@@ -24,6 +24,7 @@ import sys
|
||||
import time
|
||||
import traceback
|
||||
import re
|
||||
import os
|
||||
import socket
|
||||
import types
|
||||
import select
|
||||
@@ -114,7 +115,7 @@ class XMLDummyServer(DummyServer):
|
||||
# received size is based on the expected size in self.queries
|
||||
data = conn.recv(1024 + len(self.queries[idx]))
|
||||
if data:
|
||||
print "-----------RECEIVE " + data
|
||||
# print "-----------RECEIVE " + data
|
||||
r = self._reader.feed(data)
|
||||
except:
|
||||
type, value, stack = sys.exc_info()
|
||||
@@ -131,7 +132,7 @@ class XMLDummyServer(DummyServer):
|
||||
else:
|
||||
response = self.responses[idx]
|
||||
if response is not None:
|
||||
print >>sys.stderr, '---------SENDING : ', response
|
||||
# print >>sys.stderr, '---------SENDING : ', response
|
||||
conn.send(response)
|
||||
conn.close()
|
||||
except:
|
||||
@@ -143,15 +144,21 @@ class XMLDummyServer(DummyServer):
|
||||
def verify_queries(self):
|
||||
result = True
|
||||
queries_len = len(self.queries)
|
||||
if queries_len == len(self.real_queries):
|
||||
if queries_len == len(self.real_queries):
|
||||
full_real_queries = ""
|
||||
full_recv_queries = ""
|
||||
for idx in range(queries_len):
|
||||
real_query = xml.dom.minidom.parseString(self.real_queries[idx])
|
||||
recv_query = xml.dom.minidom.parseString(self.queries[idx])
|
||||
if not utils.xmldiff(real_query, recv_query):
|
||||
result = False
|
||||
print >>sys.stderr, "Unexpected query :\n" + \
|
||||
"Expected query : _" + self.queries[idx] + "_\n" + \
|
||||
"Receive query : _" + self.real_queries[idx] + "_\n"
|
||||
full_real_queries += self.real_queries[idx].rstrip(os.linesep)
|
||||
full_recv_queries += self.queries[idx].rstrip(os.linesep)
|
||||
# Do not receive it but add it so that xml parsing can succeed
|
||||
full_real_queries += "</stream:stream>"
|
||||
real_query = xml.dom.minidom.parseString(full_real_queries)
|
||||
recv_query = xml.dom.minidom.parseString(full_recv_queries)
|
||||
try:
|
||||
utils.xmldiff(real_query, recv_query)
|
||||
except Exception, msg:
|
||||
result = False
|
||||
print >>sys.stderr, msg
|
||||
else:
|
||||
result = False
|
||||
print >>sys.stderr, "Expected " + str(queries_len) + \
|
||||
|
||||
@@ -70,11 +70,8 @@ class MailComponent_TestCase_Basic(unittest.TestCase):
|
||||
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>"]
|
||||
# TODO : concatenate all queries to parse xml
|
||||
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></handshake>"]
|
||||
# self.server.queries = ["<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>\s<stream:stream xmlns:stream=\"http://etherx.jabber.org/streams\" xmlns=\"jabber:component:accept\" to=\"jmc.localhost\" version=\"1.0\">", \
|
||||
# "<handshake>\s*</handshake>"]
|
||||
"<handshake>[0-9abcdef]*</handshake></stream:stream>"]
|
||||
self.mail_component.run(1)
|
||||
self.failUnless(self.server.verify_queries())
|
||||
# TODO : more assertion
|
||||
@@ -82,9 +79,9 @@ class MailComponent_TestCase_Basic(unittest.TestCase):
|
||||
class MailComponent_TestCase_NoReg(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.handler = TestStreamHandler()
|
||||
logger = logging.getLogger()
|
||||
logger.addHandler(logging.StreamHandler())
|
||||
logger.setLevel(logging.DEBUG)
|
||||
# logger = logging.getLogger()
|
||||
# logger.addHandler(logging.StreamHandler())
|
||||
# logger.setLevel(logging.DEBUG)
|
||||
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, ())
|
||||
@@ -97,10 +94,10 @@ class MailComponent_TestCase_NoReg(unittest.TestCase):
|
||||
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\"\?>\s?" + \
|
||||
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>\s*</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>"]
|
||||
"<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())
|
||||
|
||||
@@ -109,102 +106,103 @@ class MailComponent_TestCase_NoReg(unittest.TestCase):
|
||||
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\"\?>\s?" + \
|
||||
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>\s*</handshake>", \
|
||||
"<iq from=\"jmc.localhost\" to=\"test@localhost/test\" type=\"result\" id=\"aad9a\">\s?" + \
|
||||
"<query xmlns=\"jabber:iq:register\">\s?" + \
|
||||
"<x xmlns=\"jabber:x:data\">\s?" + \
|
||||
"<title>Jabber Mail connection registration</title>\s?" + \
|
||||
"<instructions>Enter anything below</instructions>\s?" + \
|
||||
"<field type=\"text-single\" label=\"Connection name\" var=\"name\"/>\s?" + \
|
||||
"<field type=\"text-single\" label=\"Login\" var=\"login\"/>\s?" + \
|
||||
"<field type=\"text-private\" label=\"Password\" var=\"password\"/>\s?" + \
|
||||
"<field type=\"text-single\" label=\"Host\" var=\"host\"/>\s?" + \
|
||||
"<field type=\"text-single\" label=\"Port\" var=\"port\"/>\s?" + \
|
||||
"<field type=\"list-single\" label=\"Mailbox type\" var=\"type\">\s?" + \
|
||||
"<option label=\"POP3\">\s?" + \
|
||||
"<value>pop3</value>\s?" + \
|
||||
"</option>\s?" + \
|
||||
"<option label=\"POP3S\">\s?" + \
|
||||
"<value>pop3s</value>\s?" + \
|
||||
"</option>\s?" + \
|
||||
"<option label=\"IMAP\">\s?" + \
|
||||
"<value>imap</value>\s?" + \
|
||||
"</option>\s?" + \
|
||||
"<option label=\"IMAPS\">\s?" + \
|
||||
"<value>imaps</value>\s?" + \
|
||||
"</option>\s?" + \
|
||||
"</field>\s?" + \
|
||||
"<field type=\"text-single\" label=\"Mailbox (IMAP)\" var=\"mailbox\">\s?" + \
|
||||
"<value>INBOX</value>\s?" + \
|
||||
"</field>\s?" + \
|
||||
"<field type=\"list-single\" label=\"Action when state is 'Free For Chat'\" var=\"ffc_action\">\s?" + \
|
||||
"<value>2</value>\s?" + \
|
||||
"<option label=\"Do nothing\">\s?" + \
|
||||
"<value>0</value>\s?" + \
|
||||
"</option>\s?" + \
|
||||
"<option label=\"Send mail digest\">\s?" + \
|
||||
"<value>1</value>\s?" + \
|
||||
"</option>\s?" + \
|
||||
"<option label=\"Retrieve mail\">\s?" + \
|
||||
"<value>2</value>\s?" + \
|
||||
"</option>\s?" + \
|
||||
"</field>\s?" + \
|
||||
"<field type=\"list-single\" label=\"Action when state is 'Online'\" var=\"online_action\">\s?" + \
|
||||
"<value>2</value>\s?" + \
|
||||
"<option label=\"Do nothing\">\s?" + \
|
||||
"<value>0</value>\s?" + \
|
||||
"</option>\s?" + \
|
||||
"<option label=\"Send mail digest\">\s?" + \
|
||||
"<value>1</value>\s?" + \
|
||||
"</option>\s?" + \
|
||||
"<option label=\"Retrieve mail\">\s?" + \
|
||||
"<value>2</value>\s?" + \
|
||||
"</option>\s?" + \
|
||||
"</field>\s?" + \
|
||||
"<field type=\"list-single\" label=\"Action when state is 'Away'\" var=\"away_action\">\s?" + \
|
||||
"<value>1</value>\s?" + \
|
||||
"<option label=\"Do nothing\">\s?" + \
|
||||
"<value>0</value>\s?" + \
|
||||
"</option>\s?" + \
|
||||
"<option label=\"Send mail digest\">\s?" + \
|
||||
"<value>1</value>\s?" + \
|
||||
"</option>\s?" + \
|
||||
"<option label=\"Retrieve mail\">\s?" + \
|
||||
"<value>2</value>\s?" + \
|
||||
"</option>\s?" + \
|
||||
"</field>\s?" + \
|
||||
"<field type=\"list-single\" label=\"Action when state is 'Extended Away'\" var=\"ea_action\">\s?" + \
|
||||
"<value>1</value>\s?" + \
|
||||
"<option label=\"Do nothing\">\s?" + \
|
||||
"<value>0</value>\s?" + \
|
||||
"</option>\s?" + \
|
||||
"<option label=\"Send mail digest\">\s?" + \
|
||||
"<value>1</value>\s?" + \
|
||||
"</option>\s?" + \
|
||||
"<option label=\"Retrieve mail\">\s?" + \
|
||||
"<value>2</value>\s?" + \
|
||||
"</option>\s?" + \
|
||||
"</field>\s?" + \
|
||||
"<field type=\"list-single\" label=\"Action when state is 'Offline'\" var=\"offline_action\">\s?" + \
|
||||
"<value>0</value>\s?" + \
|
||||
"<option label=\"Do nothing\">\s?" + \
|
||||
"<value>0</value>\s?" + \
|
||||
"</option>\s?" + \
|
||||
"<option label=\"Send mail digest\">\s?" + \
|
||||
"<value>1</value>\s?" + \
|
||||
"</option>\s?" + \
|
||||
"<option label=\"Retrieve mail\">\s?" + \
|
||||
"<value>2</value>\s?" + \
|
||||
"</option>\s?" + \
|
||||
"</field>\s?" + \
|
||||
"<field type=\"text-single\" label=\"Mail check interval (in minutes)\" var=\"interval\">\s?" + \
|
||||
"<value>5</value>\s?" + \
|
||||
"</field>\s?" + \
|
||||
"</x>\s?" + \
|
||||
"</query>\s?" + \
|
||||
"</iq>"]
|
||||
"<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=\"ffc_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 'Extended Away'\" var=\"ea_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())
|
||||
|
||||
|
||||
@@ -213,7 +213,7 @@ class IMAPConnection_TestCase(unittest.TestCase):
|
||||
if core:
|
||||
core(self)
|
||||
self.imap_connection.disconnect()
|
||||
self.failUnless(self.server.verify_queries("Sended queries does not match expected queries."))
|
||||
self.failUnless(self.server.verify_queries())
|
||||
return inner
|
||||
|
||||
test_connection = make_test()
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
import unittest
|
||||
from jabber.mailconnection_factory import *
|
||||
from jabber import mailconnection
|
||||
|
||||
class MailConnectionFactory_TestCase(unittest.TestCase):
|
||||
def test_new_mail_connection_imap(self):
|
||||
@@ -41,56 +42,56 @@ class MailConnectionFactory_TestCase(unittest.TestCase):
|
||||
self.assertEquals(mc, mc)
|
||||
|
||||
def test_str_to_mail_connection_imap(self):
|
||||
mc = str_to_mail_connection("imap#login#passwd#host#193#nothing#nothing#nothing#nothing#retrieve#INBOX")
|
||||
mc = str_to_mail_connection("imap#login#passwd#host#193#0#0#0#1#2#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.ffc_action, "nothing")
|
||||
self.assertEquals(mc.online_action, "nothing")
|
||||
self.assertEquals(mc.away_action, "nothing")
|
||||
self.assertEquals(mc.ea_action, "nothing")
|
||||
self.assertEquals(mc.offline_action, "retrieve")
|
||||
self.assertEquals(mc.ffc_action, mailconnection.DO_NOTHING)
|
||||
self.assertEquals(mc.online_action, mailconnection.DO_NOTHING)
|
||||
self.assertEquals(mc.away_action, mailconnection.DO_NOTHING)
|
||||
self.assertEquals(mc.ea_action, mailconnection.DIGEST)
|
||||
self.assertEquals(mc.offline_action, mailconnection.RETRIEVE)
|
||||
|
||||
def test_str_to_mail_connection_imaps(self):
|
||||
mc = str_to_mail_connection("imaps#login#passwd#host#993#nothing#nothing#nothing#nothing#retrieve#INBOX.SubDir")
|
||||
mc = str_to_mail_connection("imaps#login#passwd#host#993#0#0#0#1#2#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.ffc_action, "nothing")
|
||||
self.assertEquals(mc.online_action, "nothing")
|
||||
self.assertEquals(mc.away_action, "nothing")
|
||||
self.assertEquals(mc.ea_action, "nothing")
|
||||
self.assertEquals(mc.offline_action, "retrieve")
|
||||
self.assertEquals(mc.ffc_action, mailconnection.DO_NOTHING)
|
||||
self.assertEquals(mc.online_action, mailconnection.DO_NOTHING)
|
||||
self.assertEquals(mc.away_action, mailconnection.DO_NOTHING)
|
||||
self.assertEquals(mc.ea_action, mailconnection.DIGEST)
|
||||
self.assertEquals(mc.offline_action, mailconnection.RETRIEVE)
|
||||
|
||||
def test_str_to_mail_connection_pop3(self):
|
||||
mc = str_to_mail_connection("pop3#login#passwd#host#110#nothing#nothing#nothing#nothing#retrieve")
|
||||
mc = str_to_mail_connection("pop3#login#passwd#host#110#0#0#0#1#2")
|
||||
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.ffc_action, "nothing")
|
||||
self.assertEquals(mc.online_action, "nothing")
|
||||
self.assertEquals(mc.away_action, "nothing")
|
||||
self.assertEquals(mc.ea_action, "nothing")
|
||||
self.assertEquals(mc.offline_action, "retrieve")
|
||||
self.assertEquals(mc.ffc_action, mailconnection.DO_NOTHING)
|
||||
self.assertEquals(mc.online_action, mailconnection.DO_NOTHING)
|
||||
self.assertEquals(mc.away_action, mailconnection.DO_NOTHING)
|
||||
self.assertEquals(mc.ea_action, mailconnection.DIGEST)
|
||||
self.assertEquals(mc.offline_action, mailconnection.RETRIEVE)
|
||||
|
||||
def test_str_to_mail_connection_pop3s(self):
|
||||
mc = str_to_mail_connection("pop3s#login#passwd#host#995#nothing#nothing#nothing#nothing#retrieve")
|
||||
mc = str_to_mail_connection("pop3s#login#passwd#host#995#0#0#0#1#2")
|
||||
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.ffc_action, "nothing")
|
||||
self.assertEquals(mc.online_action, "nothing")
|
||||
self.assertEquals(mc.away_action, "nothing")
|
||||
self.assertEquals(mc.ea_action, "nothing")
|
||||
self.assertEquals(mc.offline_action, "retrieve")
|
||||
self.assertEquals(mc.ffc_action, mailconnection.DO_NOTHING)
|
||||
self.assertEquals(mc.online_action, mailconnection.DO_NOTHING)
|
||||
self.assertEquals(mc.away_action, mailconnection.DO_NOTHING)
|
||||
self.assertEquals(mc.ea_action, mailconnection.DIGEST)
|
||||
self.assertEquals(mc.offline_action, mailconnection.RETRIEVE)
|
||||
|
||||
|
||||
119
tests/utils.py
119
tests/utils.py
@@ -21,80 +21,75 @@
|
||||
##
|
||||
|
||||
import xml.dom.minidom
|
||||
|
||||
#document = "<stream:stream xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:component:accept' id='4258238724' from='localhost'>"
|
||||
# document = """\
|
||||
# <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>
|
||||
# """
|
||||
|
||||
# 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 important1</point>
|
||||
# <point>To have more than</point>
|
||||
# <point>one slide</point>
|
||||
# </slide>
|
||||
# </slideshow>
|
||||
# """
|
||||
|
||||
#dom = xml.dom.minidom.parseString(document)
|
||||
#dom1 = xml.dom.minidom.parseString(document)
|
||||
|
||||
# def getText(nodelist):
|
||||
# rc = ""
|
||||
# for node in nodelist:
|
||||
# if node.nodeType == node.TEXT_NODE:
|
||||
# rc = rc + node.data
|
||||
# return rc
|
||||
import re
|
||||
|
||||
def xmldiff(node1, node2):
|
||||
if node1.nodeType == node1.TEXT_NODE:
|
||||
if not node2.nodeType == node2.TEXT_NODE \
|
||||
or node1.data != node2.data:
|
||||
return False
|
||||
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:
|
||||
return False
|
||||
raise Exception("node1 is Document but not node2 (" + node2.nodeType + ")")
|
||||
elif node1.tagName != node2.tagName:
|
||||
return False
|
||||
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):
|
||||
return False
|
||||
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)):
|
||||
if not xmldiff(node1.childNodes[i], node2.childNodes[i]):
|
||||
return False
|
||||
return True
|
||||
xmldiff(node1.childNodes[i], node2.childNodes[i])
|
||||
|
||||
#print xmldiff(dom, dom1)
|
||||
# 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
|
||||
|
||||
# def nodediff(node1, node2):
|
||||
# if not node1.name == node2.name:
|
||||
# return False
|
||||
# for properties in node1.properties:
|
||||
# if node2.hasAttribute(attr):
|
||||
|
||||
# def xmldiff(xpath, node1, node2):
|
||||
# if not nodediff(node1, node2):
|
||||
# return False
|
||||
# for child in node1.children:
|
||||
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