[MediaWiki-commits] [Gerrit] operations...pybal[master]: Add some protocol BGP class test cases
Ema has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/355415 ) Change subject: Add some protocol BGP class test cases .. Add some protocol BGP class test cases Change-Id: I9b5fc5b5cf760cea54c677cf06dfbd82c0dd5e22 --- M pybal/bgp/test/test_bgp.py 1 file changed, 46 insertions(+), 1 deletion(-) Approvals: Ema: Verified; Looks good to me, approved diff --git a/pybal/bgp/test/test_bgp.py b/pybal/bgp/test/test_bgp.py index 44e9acc..4cad2be 100644 --- a/pybal/bgp/test/test_bgp.py +++ b/pybal/bgp/test/test_bgp.py @@ -9,8 +9,12 @@ from .. import ip, bgp -import unittest +import unittest, mock +from twisted.test import proto_helpers +from twisted.python.failure import Failure +from twisted.internet.error import ConnectionLost +from twisted.internet.address import IPv4Address, IPv6Address class AttributeTestCase(unittest.TestCase): @@ -81,3 +85,44 @@ def testFreeSpace(self): self.assertEquals(self.msg.freeSpace(), bgp.MAX_LEN-len(self.msg)) + +class BGPTestCase(unittest.TestCase): +def setUp(self): +self.factory = bgp.BGPPeering(myASN=64600, peerAddr='127.0.0.1') +# FIXME: Should configure this in a better way in bgp.FSM +self.factory.fsm.allowAutomaticStart = False +self.proto = self.factory.buildProtocol(IPv4Address('TCP', '127.0.0.1', 0)) +self.proto.fsm.allowAutomaticStart = False +self.tr = proto_helpers.StringTransportWithDisconnection() +self.tr.protocol = self.proto +self.assertRaises(AttributeError, self.proto.makeConnection, self.tr) + +def tearDown(self): +# The BGPPeering factory keeps its own separate FSM +self.factory.fsm.idleHoldTimer.cancel() +self.proto.fsm.idleHoldTimer.cancel() + +def testConnectionLost(self): +failure = Failure(ConnectionLost("Unit test")) + +with mock.patch.object(self.proto.fsm, 'connectionFailed') as mock_method: +self.proto.connectionLost(failure) +mock_method.assert_called() + +mock_method.reset_mock() +self.proto.disconnected = True +self.proto.connectionLost(failure) +mock_method.assert_not_called() + +def testDataReceived(self): +d = b"Unit testing data" +self.proto.dataReceived(d) +self.assertIn(d, self.proto.receiveBuffer) + +def testCloseConnection(self): +with mock.patch.object(self.proto.fsm, 'connectionFailed') as mock_method: +self.tr.connected = True +self.proto.closeConnection() +self.assertTrue(self.proto.disconnected) +self.assertTrue(self.tr.disconnecting or not self.tr.connected) +mock_method.assert_called() -- To view, visit https://gerrit.wikimedia.org/r/355415 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I9b5fc5b5cf760cea54c677cf06dfbd82c0dd5e22 Gerrit-PatchSet: 5 Gerrit-Project: operations/debs/pybal Gerrit-Branch: master Gerrit-Owner: Mark BergsmaGerrit-Reviewer: Ema Gerrit-Reviewer: Giuseppe Lavagetto Gerrit-Reviewer: Volans Gerrit-Reviewer: jenkins-bot <> ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] operations...pybal[master]: Add some protocol BGP class test cases
Mark Bergsma has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/355415 ) Change subject: Add some protocol BGP class test cases .. Add some protocol BGP class test cases Change-Id: I9b5fc5b5cf760cea54c677cf06dfbd82c0dd5e22 --- M pybal/bgp/test_bgp.py 1 file changed, 46 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/operations/debs/pybal refs/changes/15/355415/1 diff --git a/pybal/bgp/test_bgp.py b/pybal/bgp/test_bgp.py index 3615341..42a734b 100644 --- a/pybal/bgp/test_bgp.py +++ b/pybal/bgp/test_bgp.py @@ -10,8 +10,12 @@ import ip import bgp -import unittest +import unittest, mock +from twisted.test import proto_helpers +from twisted.python.failure import Failure +from twisted.internet.error import ConnectionLost +from twisted.internet.address import IPv4Address, IPv6Address class AttributeTestCase(unittest.TestCase): @@ -82,3 +86,44 @@ def testFreeSpace(self): self.assertEquals(self.msg.freeSpace(), bgp.MAX_LEN-len(self.msg)) + +class BGPTestCase(unittest.TestCase): +def setUp(self): +self.factory = bgp.BGPPeering(myASN=64600, peerAddr='127.0.0.1') +# FIXME: Should configure this in a better way in bgp.FSM +self.factory.fsm.allowAutomaticStart = False +self.proto = self.factory.buildProtocol(IPv4Address('TCP', '127.0.0.1', 0)) +self.proto.fsm.allowAutomaticStart = False +self.tr = proto_helpers.StringTransportWithDisconnection() +self.tr.protocol = self.proto +self.assertRaises(AttributeError, self.proto.makeConnection, self.tr) + +def tearDown(self): +# The BGPPeering factory keeps its own separate FSM +self.factory.fsm.idleHoldTimer.cancel() +self.proto.fsm.idleHoldTimer.cancel() + +def testConnectionLost(self): +failure = Failure(ConnectionLost("Unit test")) + +with mock.patch.object(self.proto.fsm, 'connectionFailed') as mock_method: +self.proto.connectionLost(failure) +mock_method.assert_called() + +mock_method.reset_mock() +self.proto.disconnected = True +self.proto.connectionLost(failure) +mock_method.assert_not_called() + +def testDataReceived(self): +d = b"Unit testing data" +self.proto.dataReceived(d) +self.assertIn(d, self.proto.receiveBuffer) + +def testCloseConnection(self): +with mock.patch.object(self.proto.fsm, 'connectionFailed') as mock_method: +self.tr.connected = True +self.proto.closeConnection() +self.assertTrue(self.proto.disconnected) +self.assertTrue(self.tr.disconnecting or not self.tr.connected) +mock_method.assert_called() -- To view, visit https://gerrit.wikimedia.org/r/355415 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I9b5fc5b5cf760cea54c677cf06dfbd82c0dd5e22 Gerrit-PatchSet: 1 Gerrit-Project: operations/debs/pybal Gerrit-Branch: master Gerrit-Owner: Mark Bergsma___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits