def test_client_lost_connection(self):
     "Tests to make sure that the deferred is called upon a lost connection"
     d = FakeDeferred()
     client = UrlClientFactory('www.example.com', ['example'], d)
     proto = client.buildProtocol(('localhost', 0))
     proto.connectionLost('reason')
     self.assertEquals(d.callback, "called back")
 def test_client_receive(self):
     "Tests to make sure that the client is receiving data properly"
     d = FakeDeferred()
     client = UrlClientFactory('www.example.com', ['example'], d)
     proto = client.buildProtocol(('localhost', 0))
     transport = proto_helpers.StringTransport()
     proto.makeConnection(transport)
     test_dict = json.dumps({'url': 'www.example.com', 'kw': ['example']})
     proto.dataReceived(test_dict)
     self.assertEqual(proto.data, test_dict)
 def test_client_send(self):
     "Tests to make sure that the client sends the correct data to the server"
     d = FakeDeferred()
     client = UrlClientFactory('www.example.com', ['example'], d)
     proto = client.buildProtocol(('localhost', 0))
     transport = proto_helpers.StringTransport()
     proto.makeConnection(transport)
     print "transport", transport.value()
     test_dict = json.dumps({'url': 'www.example.com', 'kw': ['example']})
     self.assertEqual(transport.value(), test_dict)