How to use the gabbi.utils.not_binary function in gabbi

To help you get started, we’ve selected a few gabbi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cdent / gabbi / gabbi / case.py View on Github external
def assert_in_or_print_output(self, expected, iterable):
        """Assert the iterable contains expected or print some output.

        If the output is long, it is limited by either GABBI_MAX_CHARS_OUTPUT
        in the environment or the MAX_CHARS_OUTPUT constant.
        """
        if utils.not_binary(utils.parse_content_type(self.content_type)[0]):
            if expected in iterable:
                return

            if self.response_data:
                dumper_class = self.get_content_handler(self.content_type)
                if dumper_class:
                    full_response = dumper_class.dumps(self.response_data,
                                                       pretty=True, test=self)
                else:
                    full_response = self.output
            else:
                full_response = self.output

            max_chars = os.getenv('GABBI_MAX_CHARS_OUTPUT', MAX_CHARS_OUTPUT)
            response = full_response[0:max_chars]
            is_truncated = (len(response) != len(full_response))
github cdent / gabbi / gabbi / httpclient.py View on Github external
def _print_body(self, headers, content):
        """Output body if not binary."""
        content_type = utils.extract_content_type(headers)[0]
        if self._show_body and utils.not_binary(content_type):
            content = utils.decode_response_content(headers, content)
            # TODO(cdent): Using the JSONHandler here instead of
            # just the json module to make it clear that eventually
            # we could pretty print any printable output by using a
            # handler's loads() and dumps(). Not doing that now
            # because it would be pointless (no other interesting
            # handlers) and this approach may be entirely wrong.
            if content and jsonhandler.JSONHandler.accepts(content_type):
                data = jsonhandler.JSONHandler.loads(content)
                content = jsonhandler.JSONHandler.dumps(data, pretty=True)
            self._verbose_output('')
            self._verbose_output(content)
github cdent / gabbi / gabbi / case.py View on Github external
def _test_data_to_string(self, data, content_type):
        """Turn the request data into a string.

        If the data is not binary, replace template strings.

        If the result of the template handling is not a string,
        run the result through the dumper.
        """
        dumper_class = self.get_content_handler(content_type)
        if not _is_complex_type(data):
            if isinstance(data, six.string_types) and data.startswith('<@'):
                info = self.load_data_file(data.replace('<@', '', 1))
                if utils.not_binary(content_type):
                    data = six.text_type(info, 'UTF-8')
                else:
                    # Return early we are binary content
                    return info
        else:
            # We have a complex data structure, try to dump it.
            if dumper_class:
                data = self.replace_template(data)
                data = dumper_class.dumps(data, test=self)
            else:
                raise ValueError(
                    'unable to process data to %s' % content_type)

        data = self.replace_template(data)

        # If the result after template handling is not a string, dump