Esempio n. 1
0
    def test_python3_decode_string(self):
        string = Mock(spec=str)
        delattr(string, "decode")

        decoded_string = decode_utf8(string)

        assert decoded_string == string
Esempio n. 2
0
    def _decode_json_response(self, response, with_utf8=False):
        """
        Get decoded json response from response.

        :param response: Response from the database
        :param with_utf8: UTF-8 decode response before json decoding
        :raises: ReqlDriverError | ReqlAuthError
        :return: Json decoded response of the original response
        """

        if with_utf8:
            response = decode_utf8(response)

        json_response = self._json_decoder.decode(response)

        if not json_response.get("success"):
            if 10 <= json_response["error_code"] <= 20:
                raise ReqlAuthError(json_response["error"], self._host, self._port)

            raise ReqlDriverError(json_response["error"])

        return json_response
Esempio n. 3
0
    def test_python2_decode_string(self):
        string = Mock()

        decoded_string = decode_utf8(string)

        string.decode.assert_called_once_with("utf-8")