コード例 #1
0
class TestStrippingJSONParser(unittest.TestCase):
    def setUp(self):
        super(TestStrippingJSONParser, self).setUp()
        self.parser = StrippingJSONParser()

    def test_parser(self):
        content = json.dumps({'root': {'hello': 'world'}}).encode('utf-8')
        stream = six.BytesIO(content)

        actual_data = self.parser.parse(stream=stream,
                                        parser_context={'parse_root': 'root'})

        self.assertEqual(actual_data, OrderedDict([('hello', 'world')]))

    def test_parser_no_root(self):
        content = json.dumps({'root': {'hello': 'world'}}).encode('utf-8')
        stream = six.BytesIO(content)

        actual_data = self.parser.parse(stream=stream, parser_context={})

        self.assertEqual(actual_data, {'root': {'hello': 'world'}})

    def test_parser_different_root(self):
        content = json.dumps({'root': {'hello': 'world'}}).encode('utf-8')
        stream = six.BytesIO(content)

        actual_data = self.parser.parse(stream=stream,
                                        parser_context={'parse_root': 'foo'})

        self.assertEqual(actual_data, {'root': {'hello': 'world'}})
コード例 #2
0
class TestStrippingJSONParser(unittest.TestCase):
    def setUp(self):
        super(TestStrippingJSONParser, self).setUp()
        self.parser = StrippingJSONParser()

    def test_parser(self):
        content = json.dumps({"root": {"hello": "world"}}).encode("utf-8")
        stream = six.BytesIO(content)

        actual_data = self.parser.parse(stream=stream, parser_context={"parse_root": "root"})

        self.assertEqual(actual_data, OrderedDict([("hello", "world")]))

    def test_parser_no_root(self):
        content = json.dumps({"root": {"hello": "world"}}).encode("utf-8")
        stream = six.BytesIO(content)

        actual_data = self.parser.parse(stream=stream, parser_context={})

        self.assertEqual(actual_data, {"root": {"hello": "world"}})

    def test_parser_different_root(self):
        content = json.dumps({"root": {"hello": "world"}}).encode("utf-8")
        stream = six.BytesIO(content)

        actual_data = self.parser.parse(stream=stream, parser_context={"parse_root": "foo"})

        self.assertEqual(actual_data, {"root": {"hello": "world"}})
コード例 #3
0
 def setUp(self):
     super(TestStrippingJSONParser, self).setUp()
     self.parser = StrippingJSONParser()
コード例 #4
0
 def setUp(self):
     super(TestStrippingJSONParser, self).setUp()
     self.parser = StrippingJSONParser()