Ejemplo n.º 1
0
    def test_flush_buffer_to_stream_empty_items_key(self):
        stream = io.StringIO()
        bsh = BufferStreamHandler(stream)
        messages = {'items': []}
        bsh.message_buffer = messages
        bsh.flush_buffer_to_stream()

        # what is returned is the string representation of the buffer, which
        # should always be an array of strings. Opted to hard code the expected
        # value to higlight clearly what is expected rather than str(messages)
        self.assertEqual(stream.getvalue().strip(), '')
Ejemplo n.º 2
0
    def test_flush_buffer_to_stream_empty_object(self):
        stream = io.StringIO()
        bsh = BufferStreamHandler(stream)
        messages = {'items': [{}]}
        bsh.message_buffer = messages
        bsh.flush_buffer_to_stream()

        # what is returned is the string representation of the buffer, which
        # should always be an array of strings. Opted to hard code the expected
        # value to higlight clearly what is expected rather than str(messages)
        self.assertEqual(stream.getvalue().strip(), '{"items": [{}]}')

        try:
            json.loads(stream.getvalue().strip())
        except Exception:  # pylint: disable=broad-except
            self.fail("the outputted object is not valid json")