'Testing whether the API returns the correct circuits'

@deferred(timeout=10)
def test_get_circuits(self):

    mock_hop = MockObject()
    mock_hop.host = 'somewhere'
    mock_hop.port = 4242
    mock_circuit = MockObject()
    mock_circuit.state = 'TESTSTATE'
    mock_circuit.goal_hops = 42
    mock_circuit.bytes_up = 200
    mock_circuit.bytes_down = 400
    mock_circuit.creation_time = 1234
    mock_circuit.hops = [mock_hop]
    self.tunnel_community.circuits = {'abc': mock_circuit}
    def verify_response(response):
        response_json = json.loads(response)
        self.assertEqual(len(response_json['circuits']), 1)
        self.assertEqual(response_json['circuits'][0]['state'], 'TESTSTATE')
        self.assertEqual(response_json['circuits'][0]['bytes_up'], 200)
        self.assertEqual(response_json['circuits'][0]['bytes_down'], 400)
        self.assertEqual(len(response_json['circuits'][0]['hops']), 1)
        self.assertEqual(response_json['circuits'][0]['hops'][0]['host'], 'somewhere:4242')
    self.should_check_equality = False
    return self.do_request('debug/circuits', expected_code=200).addCallback(verify_response)
