コード例 #1
0
    def test_deserialize_called_with_response_body(self):
        response = Response("Hello, World!", 0)
        sender = MockSender(response)
        deserializer = FakeDeserializer(None)
        client = Client(sender, deserializer)

        client.send_lookup(Lookup())

        self.assertEqual(response.payload, deserializer.input)
コード例 #2
0
    def test_deserialize_called_with_response_body(self):
        response = Response('Hello, World!', 0)

        sender = MockSender(response)
        deserializer = FakeDeserializer({})
        client = Client(sender, deserializer)

        client.send(Lookup('1', '2'))

        self.assertEqual(response.payload, deserializer.input)
コード例 #3
0
    def test_result_correctly_assigned_to_corresponding_lookup(self):
        lookup = Lookup('1')
        expected_result = {"candidates": [{"street": "2"}]}

        sender = MockSender(Response('{[]}', 0))
        deserializer = FakeDeserializer(expected_result)
        client = Client(sender, deserializer)

        client.send(lookup)

        self.assertEqual('2', lookup.result[0].street)
コード例 #4
0
    def test_result_correctly_assigned_to_corresponding_lookup(self):
        raw_result = {"meta": {}, "addresses": [{"text": "Hello, World!"}]}
        expected_result = Result(raw_result)
        lookup = Lookup('Hello, World!')
        sender = MockSender(Response('[]', 0))
        deserializer = FakeDeserializer(raw_result)
        client = Client(sender, deserializer)

        client.send(lookup)

        self.assertEqual(expected_result.addresses[0].text, lookup.result.addresses[0].text)
コード例 #5
0
    def test_results_correctly_assigned_to_corresponding_lookup(self):
        raw_results = [{"input_index": 0}, {"input_index": 1}]
        expected_results = [Result(raw_results[0]), Result(raw_results[1])]
        batch = Batch()
        batch.add(Lookup())
        batch.add(Lookup())
        sender = MockSender(Response("[]", 0))
        deserializer = FakeDeserializer(raw_results)
        client = Client(sender, deserializer)

        client.send_batch(batch)

        self.assertEqual(expected_results[0].input_index,
                         batch[0].result.input_index)
        self.assertEqual(expected_results[1].input_index,
                         batch[1].result.input_index)
コード例 #6
0
    def test_candidates_correctly_assigned_to_lookup(self):
        raw_candidates = [{'address1': 'street 1'}, {'address1': 'street 2'}]
        expected_candidates = [
            Candidate(raw_candidates[0]),
            Candidate(raw_candidates[1])
        ]
        lookup = Lookup('1', '2')
        sender = MockSender(Response('[]', 0))
        deserializer = FakeDeserializer(raw_candidates)
        client = Client(sender, deserializer)

        client.send(lookup)

        self.assertEqual(expected_candidates[0].address1,
                         lookup.result[0].address1)
        self.assertEqual(expected_candidates[1].address1,
                         lookup.result[1].address1)
コード例 #7
0
    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)
コード例 #8
0
    def send(self, request):
        response = Response(None,
                            self.status_codes[self.current_status_code_index])
        self.current_status_code_index += 1

        return response
コード例 #9
0
 def send(self, request):
     if not self.exception:
         return None
     else:
         return Response(None, None, self.exception)
    def send(self, request):
        self.request = request

        return Response("[]", 200)