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'}})
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"}})
def setUp(self): super(TestStrippingJSONParser, self).setUp() self.parser = StrippingJSONParser()