r47159 - use existing test fakes, don't define new ones

glyph-TA+aISz0psMTMxyoc4vAAJOcrHinNvQL0E9HWUfgJXw@public.gmane.org Tue, 5 Apr 2016 15:00:17 -0600 (MDT)
Newsgroups gmane.comp.python.twisted.commits
Message-ID <[email protected]>
Author: glyph
Date: Tue Apr  5 15:00:11 2016
New Revision: 47159

Modified:
   branches/haproxy-endpoint-8203-2/twisted/protocols/haproxy/test/test_wrapper.py

Log:
use existing test fakes, don't define new ones

Modified: branches/haproxy-endpoint-8203-2/twisted/protocols/haproxy/test/test_wrapper.py
==============================================================================
--- branches/haproxy-endpoint-8203-2/twisted/protocols/haproxy/test/test_wrapper.py	(original)
+++ branches/haproxy-endpoint-8203-2/twisted/protocols/haproxy/test/test_wrapper.py	Tue Apr  5 15:00:11 2016
@@ -8,24 +8,11 @@
 from twisted.trial import unittest
 from twisted.internet import address
 from twisted.internet import protocol
+from twisted.test.proto_helpers import StringTransportWithDisconnection
 
 from .. import _wrapper
 
 
-class StaticTransport(object):
-
-    """
-    Transport stand-in that maintains test state.
-    """
-
-    def __init__(self):
-        self.disconnected = False
-
-
-    def loseConnection(self):
-        self.disconnected = True
-
-
 
 class StaticProtocol(protocol.Protocol):
 
@@ -70,10 +57,12 @@
         proto = factory.buildProtocol(
             address.IPv4Address('TCP', b'127.1.1.1', 8080),
         )
-        transport = StaticTransport()
+        transport = StringTransportWithDisconnection()
+        transport.protocol = proto
         proto.makeConnection(transport)
         proto.dataReceived(b'NOTPROXY anything can go here\r\n')
-        self.assertTrue(transport.disconnected)
+        self.assertFalse(transport.connected)
+
 
     def test_invalidPartialHeaderDisconnects(self):
         """
@@ -83,11 +72,12 @@
         proto = factory.buildProtocol(
             address.IPv4Address('TCP', b'127.1.1.1', 8080),
         )
-        transport = StaticTransport()
+        transport = StringTransportWithDisconnection()
+        transport.protocol = proto
         proto.makeConnection(transport)
         proto.dataReceived(b'PROXY TCP4 1.1.1.1\r\n')
         proto.dataReceived(b'2.2.2.2 8080\r\n')
-        self.assertTrue(transport.disconnected)
+        self.assertFalse(transport.connected)
 
 
     def test_validIPv4HeaderResolves_getPeerHost(self):
@@ -98,7 +88,7 @@
         proto = factory.buildProtocol(
             address.IPv4Address('TCP', b'127.0.0.1', 8080),
         )
-        transport = StaticTransport()
+        transport = StringTransportWithDisconnection()
         proto.makeConnection(transport)
         proto.dataReceived(b'PROXY TCP4 1.1.1.1 2.2.2.2 8080 8888\r\n')
         self.assertEqual(proto.getPeer().host, b'1.1.1.1')
@@ -131,7 +121,7 @@
         proto = factory.buildProtocol(
             address.IPv6Address('TCP', b'::1', 8080),
         )
-        transport = StaticTransport()
+        transport = StringTransportWithDisconnection()
         proto.makeConnection(transport)
         proto.dataReceived(b'PROXY TCP6 ::1 ::2 8080 8888\r\n')
         self.assertEqual(proto.getPeer().host, b'::1')
@@ -164,7 +154,7 @@
         proto = factory.buildProtocol(
             address.IPv6Address('TCP', b'::1', 8080),
         )
-        transport = StaticTransport()
+        transport = StringTransportWithDisconnection()
         proto.makeConnection(transport)
         proto.dataReceived(b'PROXY TCP6 ::1 ::2 8080 8888\r\nHTTP/1.1 / GET')
         self.assertEqual(proto.wrappedProtocol.data, b'HTTP/1.1 / GET')
@@ -178,12 +168,13 @@
         proto = factory.buildProtocol(
             address.IPv6Address('TCP', b'::1', 8080),
         )
-        transport = StaticTransport()
+        transport = StringTransportWithDisconnection()
         proto.makeConnection(transport)
         proto.dataReceived(b'PROXY TCP6 ::1 ::2 ')
         proto.dataReceived(b'8080 8888\r\nHTTP/1.1 / GET')
         self.assertEqual(proto.wrappedProtocol.data, b'HTTP/1.1 / GET')
 
+
     def test_overflowBytesSentToWrappedProtocolAfter(self):
         """
         Test if wrapper writes all data to wrapped protocol after parsing.
@@ -192,7 +183,7 @@
         proto = factory.buildProtocol(
             address.IPv6Address('TCP', b'::1', 8080),
         )
-        transport = StaticTransport()
+        transport = StringTransportWithDisconnection()
         proto.makeConnection(transport)
         proto.dataReceived(b'PROXY TCP6 ::1 ::2 ')
         proto.dataReceived(b'8080 8888\r\nHTTP/1.1 / GET')
@@ -260,10 +251,11 @@
         proto = factory.buildProtocol(
             address.IPv6Address('TCP', b'::1', 8080),
         )
-        transport = StaticTransport()
+        transport = StringTransportWithDisconnection()
+        transport.protocol = proto
         proto.makeConnection(transport)
         proto.dataReceived(b'\x00' + self.IPV4HEADER[1:])
-        self.assertTrue(transport.disconnected)
+        self.assertFalse(transport.connected)
 
 
     def test_validIPv4HeaderResolves_getPeerHost(self):
@@ -274,7 +266,7 @@
         proto = factory.buildProtocol(
             address.IPv4Address('TCP', b'127.0.0.1', 8080),
         )
-        transport = StaticTransport()
+        transport = StringTransportWithDisconnection()
         proto.makeConnection(transport)
         proto.dataReceived(self.IPV4HEADER)
         self.assertEqual(proto.getPeer().host, b'127.0.0.1')
@@ -307,7 +299,7 @@
         proto = factory.buildProtocol(
             address.IPv4Address('TCP', b'::1', 8080),
         )
-        transport = StaticTransport()
+        transport = StringTransportWithDisconnection()
         proto.makeConnection(transport)
         proto.dataReceived(self.IPV6HEADER)
         self.assertEqual(proto.getPeer().host, b'0:0:0:0:0:0:0:1')
@@ -340,7 +332,7 @@
         proto = factory.buildProtocol(
             address.UNIXAddress(b'/home/test/sockets/server.sock'),
         )
-        transport = StaticTransport()
+        transport = StringTransportWithDisconnection()
         proto.makeConnection(transport)
         proto.dataReceived(self.UNIXHEADER)
         self.assertEqual(proto.getPeer().name, b'/home/tests/mysockets/sock')
@@ -363,7 +355,7 @@
         proto = factory.buildProtocol(
             address.IPv6Address('TCP', b'::1', 8080),
         )
-        transport = StaticTransport()
+        transport = StringTransportWithDisconnection()
         proto.makeConnection(transport)
         proto.dataReceived(self.IPV6HEADER + b'HTTP/1.1 / GET')
         self.assertEqual(proto.wrappedProtocol.data, b'HTTP/1.1 / GET')
@@ -377,7 +369,7 @@
         proto = factory.buildProtocol(
             address.IPv6Address('TCP', b'::1', 8080),
         )
-        transport = StaticTransport()
+        transport = StringTransportWithDisconnection()
         proto.makeConnection(transport)
         proto.dataReceived(self.IPV6HEADER[:18])
         proto.dataReceived(self.IPV6HEADER[18:] + b'HTTP/1.1 / GET')