def test_empty_batch_not_sent(self):
        sender = RequestCapturingSender()
        client = Client(sender, None)

        client.send_batch(Batch())

        self.assertIsNone(sender.request)
    def test_successfully_sends_batch(self):
        expected_payload = "Hello, World!"
        sender = RequestCapturingSender()
        serializer = FakeSerializer(expected_payload)
        client = Client(sender, serializer)
        batch = Batch()
        batch.add(Lookup())
        batch.add(Lookup())

        client.send_batch(batch)

        self.assertEqual(expected_payload, sender.request.payload)
    def test_candidates_correctly_assigned_to_corresponding_lookup(self):
        candidate0 = {
            'input_index': 0,
            'candidate_index': 0,
            'addressee': 'Mister 0'
        }
        candidate1 = {
            'input_index': 1,
            'candidate_index': 0,
            'addressee': 'Mister 1'
        }
        candidate2 = {
            'input_index': 1,
            'candidate_index': 1,
            'addressee': 'Mister 2'
        }
        raw_candidates = [candidate0, candidate1, candidate2]

        expected_candidates = [
            Candidate(candidate0),
            Candidate(candidate1),
            Candidate(candidate2)
        ]
        batch = Batch()
        batch.add(Lookup())
        batch.add(Lookup())
        sender = MockSender(Response("[]", 0))
        deserializer = FakeDeserializer(raw_candidates)
        client = Client(sender, deserializer)

        client.send_batch(batch)

        self.assertEqual(expected_candidates[0].addressee,
                         batch[0].result[0].addressee)
        self.assertEqual(expected_candidates[1].addressee,
                         batch[1].result[0].addressee)
        self.assertEqual(expected_candidates[2].addressee,
                         batch[1].result[1].addressee)