Our connection object will be in charge of making our message available to all the other clients and, probably in the near future, letting us know when there are new messages.
The first step to drive the development of our Connection object is to start building a TestConnection test case and a test_broadcast test to make our expectations of the implementation clear:
class TestConnection(unittest.TestCase):
def test_broadcast(self):
c = Connection(("localhost", 9090))
c.broadcast("some message")
assert c.get_messages()[-1] == "some message"
Our test specifies that once we've sent a message in broadcast, the latest entry in the messages visible in the chat should be our own message (as it was the last message sent). Obviously, running our test now will fail because the Connection object doesn't exist at all, so let's make one.
A possible idea for how to implement cross-client communication...