コード例 #1
0
ファイル: test_request.py プロジェクト: gridl/selenium-wire
    def test_response_repr(self):
        request_id = uuid.uuid4()
        data = self._response_data()

        response = Response(request_id, data, Mock())

        self.assertEqual(repr(response), "Response('{}', {})".format(request_id, data))
コード例 #2
0
    def test_create_response(self):
        data = self._response_data()

        response = Response(uuid.uuid4(), data, Mock())

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.reason, 'OK')
        self.assertEqual(len(response.headers), 2)
        self.assertEqual(response.headers['Content-Type'], 'application/json')
コード例 #3
0
    def test_load_response_body(self):
        mock_client = Mock()
        mock_client.get_response_body.return_value = b'the body'
        data = self._response_data()
        request_id = uuid.uuid4()

        response = Response(request_id, data, mock_client)
        body = response.body

        self.assertEqual(body, b'the body')
        mock_client.get_response_body.assert_called_once_with(request_id)
コード例 #4
0
    def test_load_response_body_uses_cached_data(self):
        mock_client = Mock()
        mock_client.get_response_body.return_value = b'the body'
        data = self._response_data()
        request_id = uuid.uuid4()

        response = Response(request_id, data, mock_client)
        response.body  # Retrieves the body
        body = response.body  # Uses the previously retrieved body

        self.assertEqual(body, b'the body')
        mock_client.get_response_body.assert_called_once_with(request_id)
コード例 #5
0
    def test_response_str(self):
        data = self._response_data()

        response = Response(uuid.uuid4(), data, Mock())

        self.assertEqual(str(response), '200 OK'.format(data))
コード例 #6
0
    def test_get_header_case_insensitive(self):
        data = self._response_data()

        response = Response(uuid.uuid4(), data, Mock())

        self.assertEqual(response.headers['content-type'], 'application/json')