From cbed8029bad691f8353854dc264f83303a196a09 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Thu, 29 Jul 2010 23:58:25 -0400 Subject: Updated, cleaned, and documented Iq stanza class. Also added unit tests. --- tests/test_iqstanzas.py | 93 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 tests/test_iqstanzas.py (limited to 'tests/test_iqstanzas.py') diff --git a/tests/test_iqstanzas.py b/tests/test_iqstanzas.py new file mode 100644 index 00000000..9ae59297 --- /dev/null +++ b/tests/test_iqstanzas.py @@ -0,0 +1,93 @@ +from sleektest import * +from sleekxmpp.xmlstream.stanzabase import ET + + +class TestIqStanzas(SleekTest): + + def setUp(self): + """Start XML stream for testing.""" + self.streamStart() + + def tearDown(self): + """Shutdown the XML stream after testing.""" + self.streamClose() + + def testSetup(self): + """Test initializing default Iq values.""" + iq = self.Iq() + self.checkIq(iq, """ + + """) + + def testPayload(self): + """Test setting Iq stanza payload.""" + iq = self.Iq() + iq.setPayload(ET.Element('{test}tester')) + self.checkIq(iq, """ + + + + """, use_values=False) + + + def testUnhandled(self): + """Test behavior for Iq.unhandled.""" + self.streamRecv(""" + + + + """) + + iq = self.Iq() + iq['id'] = 'test' + iq['error']['condition'] = 'feature-not-implemented' + iq['error']['text'] = 'No handlers registered for this request.' + + self.streamSendIq(iq, """ + + + + + No handlers registered for this request. + + + + """) + + def testQuery(self): + """Test modifying query element of Iq stanzas.""" + iq = self.Iq() + + iq['query'] = 'query_ns' + self.checkIq(iq, """ + + + + """) + + iq['query'] = 'query_ns2' + self.checkIq(iq, """ + + + + """) + + self.failUnless(iq['query'] == 'query_ns2', "Query namespace doesn't match") + + del iq['query'] + self.checkIq(iq, """ + + """) + + def testReply(self): + """Test setting proper result type in Iq replies.""" + iq = self.Iq() + iq['to'] = 'user@localhost' + iq['type'] = 'get' + iq.reply() + + self.checkIq(iq, """ + + """) + +suite = unittest.TestLoader().loadTestsFromTestCase(TestIqStanzas) -- cgit v1.2.3 From 58f77d898f82ab108fa17d562a32c68d3ea35306 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Thu, 5 Aug 2010 20:23:07 -0400 Subject: Updated tests to use a relative import for SleekTest to please Python3. Fixed some tabs/spaces issues. --- tests/test_iqstanzas.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'tests/test_iqstanzas.py') diff --git a/tests/test_iqstanzas.py b/tests/test_iqstanzas.py index 9ae59297..98a01a26 100644 --- a/tests/test_iqstanzas.py +++ b/tests/test_iqstanzas.py @@ -1,4 +1,4 @@ -from sleektest import * +from . sleektest import * from sleekxmpp.xmlstream.stanzabase import ET @@ -18,7 +18,7 @@ class TestIqStanzas(SleekTest): self.checkIq(iq, """ """) - + def testPayload(self): """Test setting Iq stanza payload.""" iq = self.Iq() @@ -38,10 +38,10 @@ class TestIqStanzas(SleekTest): """) - iq = self.Iq() + iq = self.Iq() iq['id'] = 'test' - iq['error']['condition'] = 'feature-not-implemented' - iq['error']['text'] = 'No handlers registered for this request.' + iq['error']['condition'] = 'feature-not-implemented' + iq['error']['text'] = 'No handlers registered for this request.' self.streamSendIq(iq, """ @@ -72,21 +72,21 @@ class TestIqStanzas(SleekTest): """) - self.failUnless(iq['query'] == 'query_ns2', "Query namespace doesn't match") + self.failUnless(iq['query'] == 'query_ns2', "Query namespace doesn't match") - del iq['query'] - self.checkIq(iq, """ + del iq['query'] + self.checkIq(iq, """ """) def testReply(self): """Test setting proper result type in Iq replies.""" iq = self.Iq() - iq['to'] = 'user@localhost' - iq['type'] = 'get' + iq['to'] = 'user@localhost' + iq['type'] = 'get' iq.reply() - self.checkIq(iq, """ + self.checkIq(iq, """ """) -- cgit v1.2.3 From 7a5ef2849218e122b04e244aeedd67844a0690b2 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Wed, 11 Aug 2010 18:41:57 -0400 Subject: Updated SleekTest.streamClose to check that the stream was actually started before closing it. Updated tests for Iq stanzas to not start a stream for every test; tests now run a lot faster. The call to streamClose must still be in the tearDown method to ensure it is called in the case of an error. --- tests/test_iqstanzas.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'tests/test_iqstanzas.py') diff --git a/tests/test_iqstanzas.py b/tests/test_iqstanzas.py index 98a01a26..2dabc5e9 100644 --- a/tests/test_iqstanzas.py +++ b/tests/test_iqstanzas.py @@ -4,10 +4,6 @@ from sleekxmpp.xmlstream.stanzabase import ET class TestIqStanzas(SleekTest): - def setUp(self): - """Start XML stream for testing.""" - self.streamStart() - def tearDown(self): """Shutdown the XML stream after testing.""" self.streamClose() @@ -32,6 +28,7 @@ class TestIqStanzas(SleekTest): def testUnhandled(self): """Test behavior for Iq.unhandled.""" + self.streamStart() self.streamRecv(""" -- cgit v1.2.3