I'd like to merge the attached test into trunk tomorrow. Any objections? Just a few tests.
This patch is copyrighted by me and licensed under AGPLv3-or-later.
diff --git a/poker-network/ChangeLog b/poker-network/ChangeLog index f98e585..fd33653 100644 --- a/poker-network/ChangeLog +++ b/poker-network/ChangeLog @@ -1,6 +1,26 @@ 2009-07-04 Bradley M. Kuhn <[email protected]> * tests/run.in (COVERAGE_100_PERCENT): Added + ../pokernetwork/proxyfilter. + + * tests/test-proxyfilter.py.in + (ProxyFilterTestCase.test02_forceInitCoverHeaderReplace): Wrote test. + (ProxyFilterTestCase.test03_checkbadReason.MockDeferred.errback): + Wrote test. + + * tests/run.in (COVERAGE_100_PERCENT): Added + ../pokernetwork/OLDpokerclientpackets. + + * tests/test-pokerclientpackets.py.in: Added + OLDpokerclientpackets.py to the COVERAGE_FILES list. + (PokerClientPacketsTestCase.test_chips2amount_old): Wrote test. + + * configure.ac, tests/Makefile.am (TESTS): Added + test-nullfilter.py. + + * tests/test-nullfilter.py.in: Added file and wrote tests. + + * tests/run.in (COVERAGE_100_PERCENT): Added ../pokernetwork/countfilter. * tests/Makefile.am (TESTS): Added test-countfilter.py. diff --git a/poker-network/configure.ac b/poker-network/configure.ac index 028ef42..ddc14bd 100644 --- a/poker-network/configure.ac +++ b/poker-network/configure.ac @@ -1,8 +1,8 @@ # # Copyright (C) 2006, 2007, 2008, 2009 Loic Dachary <[email protected]> -# Copyright (C) 2008 Bradley M. Kuhn <[email protected]> -# Copyright (C) 2004, 2005, 2006 Mekensleep <[email protected]> -# 24 rue vieille du temple, 75004 Paris +# Copyright (C) 2008, 2009 Bradley M. Kuhn <[email protected]> +# Copyright (C) 2004, 2005, 2006 Mekensleep <[email protected]> +# 24 rue vieille du temple, 75004 Paris # # This software's license gives you freedom; you can copy, convey, # propagate, redistribute and/or modify this program under the terms of @@ -344,6 +344,7 @@ AC_CONFIG_FILES([ tests/test-proxy.py tests/test-proxyfilter.py tests/test-countfilter.py + tests/test-nullfilter.py tests/test-string.py tests/test-pokerchildren.py tests/test-webservice.py diff --git a/poker-network/tests/Makefile.am b/poker-network/tests/Makefile.am index 19e8e8d..a38ef94 100644 --- a/poker-network/tests/Makefile.am +++ b/poker-network/tests/Makefile.am @@ -120,6 +120,7 @@ TESTS = coverage-reset \ test-pokermemcache.py \ test-proxyfilter.py \ test-countfilter.py \ + test-nullfilter.py \ test-proxy.py \ test-pokerserver.py \ test-pokerserver-run-load.py \ diff --git a/poker-network/tests/run.in b/poker-network/tests/run.in index 0587c90..04a512d 100644 --- a/poker-network/tests/run.in +++ b/poker-network/tests/run.in @@ -69,6 +69,7 @@ COVERAGE_100_PERCENT=" ../pokernetwork/pokergameclient ../pokernetwork/pokernetworkconfig ../pokernetwork/pokerclientpackets +../pokernetwork/OLDpokerclientpackets ../pokernetwork/currencyclient ../pokernetwork/pokerpackets ../pokernetwork/pokeravatar @@ -83,6 +84,7 @@ COVERAGE_100_PERCENT=" ../pokernetwork/client ../pokernetwork/proxy ../pokernetwork/countfilter +../pokernetwork/proxyfilter ../pokernetwork/pokercashier ../pokernetwork/pokerauthmysql ../pokernetwork/user diff --git a/poker-network/tests/test-nullfilter.py.in b/poker-network/tests/test-nullfilter.py.in new file mode 100644 index 0000000..1cf8192 --- /dev/null +++ b/poker-network/tests/test-nullfilter.py.in @@ -0,0 +1,71 @@ +...@python@ +# -*- mode: python; coding: iso-8859-1 -*- +# more information about the above line at http://www.python.org/dev/peps/pep-0263/ +# +# Copyright (C) 2009 Bradley M. Kuhn <[email protected]> +# +# This software's license gives you freedom; you can copy, convey, +# propagate, redistribute and/or modify this program under the terms of +# the GNU Affero General Public License (AGPL) as published by the Free +# Software Foundation (FSF), either version 3 of the License, or (at your +# option) any later version of the AGPL published by the FSF. +# +# 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 Affero +# General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program in a file in the toplevel directory called +# "AGPLv3". If not, see <http://www.gnu.org/licenses/>. +# + +import sys, os, tempfile, shutil +sys.path.insert(0, "./..") +sys.path.insert(0, "..") +import unittest +from pokernetwork import nullfilter + +# ------------------------------------------------------------ +class NullFilterTestCase(unittest.TestCase): + # ------------------------------------------------------------------------- + def setUp(self): + pass + # ------------------------------------------------------------------------- + def tearDown(self): + pass + # ------------------------------------------------------------------------- + def test00_restfilter_none(self): + """test00_restfilter_none""" + + self.failUnless(nullfilter.rest_filter(None, None, None), + "nullfilter.rest_filter always returns True") + # ------------------------------------------------------------------------- + def test01_restfilter_strings(self): + """test01_restfilter_strings""" + + self.failUnless(nullfilter.rest_filter("SITE", "REQUEST", "PACKET"), + "nullfilter.rest_filter always returns True") +# ------------------------------------------------------------ +def GetTestSuite(): + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(NullFilterTestCase)) + + # Comment out above and use line below this when you wish to run just + # one test by itself (changing prefix as needed). +# suite.addTest(unittest.makeSuite(PokerGameHistoryTestCase, prefix = "test2")) + return suite +# ----------------------------------------------------------------------------- +def Run(verbose = 2): + return unittest.TextTestRunner(verbosity=verbose).run(GetTestSuite()) +# ----------------------------------------------------------------------------- +if __name__ == '__main__': + if Run().wasSuccessful(): + sys.exit(0) + else: + sys.exit(1) + +# Interpreted by emacs +# Local Variables: +# compile-command: "( cd .. ; ./config.status tests/test-nullfilter.py ) ; ( cd ../tests ; make VERBOSE_T=-1 COVERAGE_FILES='../pokernetwork/nullfilter.py' TESTS='coverage-reset test-nullfilter.py coverage-report' check )" +# End: diff --git a/poker-network/tests/test-pokerclientpackets.py.in b/poker-network/tests/test-pokerclientpackets.py.in index 881ef02..8ba063b 100644 --- a/poker-network/tests/test-pokerclientpackets.py.in +++ b/poker-network/tests/test-pokerclientpackets.py.in @@ -2,6 +2,7 @@ # -*- mode: python -*- # # Copyright (C) 2007, 2008 Loic Dachary <[email protected]> +# Copyright (C) 2009 Bradley M. Kuhn <[email protected]> # # This software's license gives you freedom; you can copy, convey, # propagate, redistribute and/or modify this program under the terms of @@ -112,6 +113,9 @@ class PokerClientPacketsTestCase(testpackets.PacketsTestBase): def test_chips2amount(self): self.assertEqual(10, pokerclientpackets.chips2amount([1, 2, 4, 2])) + def test_chips2amount_old(self): + self.assertEqual(10, OLDpokerclientpackets.chips2amount([1, 2, 4, 2])) + def defineTestPacket(self): d = {} d['PacketFactory'] = {} @@ -178,5 +182,5 @@ if __name__ == '__main__': # Interpreted by emacs # Local Variables: -# compile-command: "( cd .. ; ./config.status tests/test-pokerclientpackets.py ) ; ( cd ../tests ; make COVERAGE_FILES='../pokernetwork/pokerclientpackets.py' TESTS='coverage-reset test-pokerclientpackets.py coverage-report' check )" +# compile-command: "( cd .. ; ./config.status tests/test-pokerclientpackets.py ) ; ( cd ../tests ; make COVERAGE_FILES='../pokernetwork/pokerclientpackets.py ../pokernetwork/OLDpokerclientpackets.py' TESTS='coverage-reset test-pokerclientpackets.py coverage-report' check )" # End: diff --git a/poker-network/tests/test-proxyfilter.py.in b/poker-network/tests/test-proxyfilter.py.in index 61bdcca..7b0fbca 100644 --- a/poker-network/tests/test-proxyfilter.py.in +++ b/poker-network/tests/test-proxyfilter.py.in @@ -1,7 +1,8 @@ #...@python@ # -*- mode: python -*- # -# Copyright (C) 2008 Loic Dachary <[email protected]> +# Copyright (C) 2008 Loic Dachary <[email protected]> +# Copyright (C) 2009 Bradley M. Kuhn <[email protected]> # # This software's license gives you freedom; you can copy, convey, # propagate, redistribute and/or modify this program under the terms of @@ -80,15 +81,13 @@ settings_xml_proxy = """<?xml version="1.0" encoding="ISO-8859-1"?> <users temporary="BOT"/> </server> """ - class ProxyTestCase(unittest.TestCase): - def destroyDb(self, arg = None): if len("@MYSQL_TEST_DBROOT_PASSWORD@") > 0: os.system("@MYSQL@ -u @MYSQL_TEST_DBROOT@ --password='@MYSQL_TEST_DBROOT_PASSWORD@' -e 'DROP DATABASE IF EXISTS pokernetworktest'") else: os.system("@MYSQL@ -u @MYSQL_TEST_DBROOT@ -e 'DROP DATABASE IF EXISTS pokernetworktest'") - + # -------------------------------------------------------------- def initServer(self): settings = pokernetworkconfig.Config([]) settings.loadFromString(settings_xml_server) @@ -97,7 +96,7 @@ class ProxyTestCase(unittest.TestCase): self.server_service.startService() self.server_site = pokersite.PokerSite(settings, pokerservice.PokerRestTree(self.server_service)) self.server_port = reactor.listenTCP(19481, self.server_site, interface="127.0.0.1") - + # -------------------------------------------------------------- def initProxy(self): settings = pokernetworkconfig.Config([]) settings.loadFromString(settings_xml_proxy) @@ -106,7 +105,7 @@ class ProxyTestCase(unittest.TestCase): self.proxy_service.startService() self.proxy_site = pokersite.PokerSite(settings, pokerservice.PokerRestTree(self.proxy_service)) self.proxy_port = reactor.listenTCP(19480, self.proxy_site, interface="127.0.0.1") - + # -------------------------------------------------------------- def setUp(self): testclock._seconds_reset() pokermemcache.memcache = pokermemcache.MemcacheMockup @@ -114,19 +113,19 @@ class ProxyTestCase(unittest.TestCase): self.destroyDb() self.initServer() self.initProxy() - + # -------------------------------------------------------------- def tearDownServer(self): self.server_site.stopFactory() d = self.server_service.stopService() d.addCallback(lambda x: self.server_port.stopListening()) return d - + # -------------------------------------------------------------- def tearDownProxy(self): self.proxy_site.stopFactory() d = self.proxy_service.stopService() d.addCallback(lambda x: self.proxy_port.stopListening()) return d - + # -------------------------------------------------------------- def tearDown(self): d = defer.DeferredList(( self.tearDownServer(), @@ -135,7 +134,7 @@ class ProxyTestCase(unittest.TestCase): d.addCallback(self.destroyDb) d.addCallback(lambda x: reactor.disconnectAll()) return d - + # -------------------------------------------------------------- def test01_ping_proxy(self): """ Ping to the proxy. @@ -146,7 +145,7 @@ class ProxyTestCase(unittest.TestCase): self.assertEqual('[]', str(result)) d.addCallback(checkPing) return d - + # -------------------------------------------------------------- def test02_ping_server(self): """ Ping to the server. @@ -157,7 +156,7 @@ class ProxyTestCase(unittest.TestCase): self.assertEqual('[]', str(result)) d.addCallback(checkPing) return d - + # -------------------------------------------------------------- def test03_listTables(self): """ Select all tables. The list obtained from the proxy contains the tables @@ -172,7 +171,7 @@ class ProxyTestCase(unittest.TestCase): self.assertEqual('Table1', tables[0]['name']) d.addCallback(checkTables) return d - + # -------------------------------------------------------------- def test04_tableJoin(self): """ Join a table thru a proxy. @@ -185,7 +184,7 @@ class ProxyTestCase(unittest.TestCase): self.assertEqual('Table1', packets[0]['name']) d.addCallback(checkTable) return d - + # -------------------------------------------------------------- def test05_connectionrefused(self): """ Create a route that leads to a non-existent server. @@ -199,7 +198,7 @@ class ProxyTestCase(unittest.TestCase): self.assertSubstring('Connection was refused by other side', result.value.response) d.addBoth(checkTable) return d - + # -------------------------------------------------------------- def test06_tableSeat_auth(self): """ Join a table thru a proxy, using an authenticated session @@ -235,7 +234,7 @@ class ProxyTestCase(unittest.TestCase): return d1 d.addCallback(seat) return d - + # -------------------------------------------------------------- def test07_tourneyRegister(self): """ Register to a tourney thru a proxy, using an authenticated session @@ -274,7 +273,7 @@ class ProxyTestCase(unittest.TestCase): return result d.addCallback(checkTable) return d - + # -------------------------------------------------------------- def test08_tableSeat_relogin(self): """ Join a table thru a proxy, using an anonymous session that becomes an @@ -324,7 +323,7 @@ class ProxyTestCase(unittest.TestCase): return d1 d.addCallback(seat) return d - + # -------------------------------------------------------------- def test09_pokerPoll(self): """ """ @@ -335,7 +334,7 @@ class ProxyTestCase(unittest.TestCase): self.assertEqual(0, len(packets)) d.addCallback(checkTable) return d - + # -------------------------------------------------------------- def test10_error500(self): """ """ @@ -349,9 +348,9 @@ class ProxyTestCase(unittest.TestCase): return True d.addErrback(checkError) return d - +################################################################################ class ProxyFilterTestCase(unittest.TestCase): - + # -------------------------------------------------------------- def test01_rest_filter_finished_request(self): """ proxyfilter.rest_filter should ignore finished request @@ -382,10 +381,44 @@ class ProxyFilterTestCase(unittest.TestCase): r.finish() r.noLongerQueued() proxyfilter.rest_filter(Site(), r, Packet()) - + # -------------------------------------------------------------- + def test02_forceInitCoverHeaderReplace(self): + from pokernetwork.proxyfilter import ProxyClient + + pc = ProxyClient("COMMAND", "REST", "VERSION", + { 'proxy-connection' : 'ThisWillBeGone', + 'cookie' : 'ThisWillStay'}, "DATA", "FATHER") + self.assertEquals(pc.father, "FATHER") + self.assertEquals(pc.command, "COMMAND") + self.assertEquals(pc.rest, "REST") + self.assertEquals(pc.headers, {'cookie' : 'ThisWillStay', + 'connection' : 'close'}) + self.assertEquals(pc.data, "DATA") + # -------------------------------------------------------------- + def test03_checkbadReason(self): + class MockReason(): + def check(mrS, reason): return False + class MockDeferred(): + def __init__(mdS): + mdS.errbackCount = 0 + mdS.called = False + def errback(mdS, reason): + mdS.errbackCount += 1 + self.failUnless(isinstance(reason, MockReason)) + + from pokernetwork.proxyfilter import ProxyClientFactory + + pcf = ProxyClientFactory("command", "rest", "version", "headers", "data", "father", + "verbose", "destination") + + pcf.deferred = MockDeferred() + pcf.clientConnectionLost(None, MockReason()) + + self.assertEquals(pcf.deferred.errbackCount, 1) +################################################################################ def Run(): loader = runner.TestLoader() -# loader.methodPrefix = "test10" +# loader.methodPrefix = "test_trynow" suite = loader.suiteFactory() suite.addTest(loader.loadClass(ProxyTestCase)) suite.addTest(loader.loadClass(ProxyFilterTestCase)) @@ -400,7 +433,7 @@ if __name__ == '__main__': sys.exit(0) else: sys.exit(1) - +################################################################################ # Interpreted by emacs # Local Variables: # compile-command: "( cd .. ; ./config.status tests/test-proxyfilter.py ) ; ( cd ../tests ; make COVERAGE_FILES='../pokernetwork/proxyfilter.py' VERBOSE_T=-1 TESTS='coverage-reset test-proxyfilter.py coverage-report' check )"
-- -- bkuhn
_______________________________________________ Pokersource-users mailing list [email protected] https://mail.gna.org/listinfo/pokersource-users
