def test_parse_include_metadata(self):
        parser = JSONParser()

        string = json.dumps([])
        stream = BytesIO(string.encode('utf-8'))

        with self.assertRaises(ParseError):
            parser.parse(stream, None, self.parser_context)
Esempio n. 2
0
    def test_parse_invalid_data(self):
        parser = JSONParser()

        string = json.dumps([])
        stream = BytesIO(string.encode('utf-8'))

        with self.assertRaises(ParseError):
            parser.parse(stream, None, self.parser_context)
Esempio n. 3
0
    def test_parse_include_metadata(self):
        parser = JSONParser()

        stream = BytesIO(self.string.encode('utf-8'))
        data = parser.parse(stream, None, self.parser_context)

        self.assertEqual(data['_meta'], {'random_key': 'random_value'})
Esempio n. 4
0
    def test_parse_invalid_data_key(self):
        parser = JSONParser()

        string = json.dumps({
            'data': [{
                'id': 123,
                'type': 'Blog',
                'attributes': {
                    'json-value': {'JsonKey': 'JsonValue'}
                },
            }]
        })
        stream = BytesIO(string.encode('utf-8'))

        with self.assertRaises(ParseError):
            parser.parse(stream, None, self.parser_context)
    def test_parse_include_metadata(self):
        parser = JSONParser()

        stream = BytesIO(self.string.encode('utf-8'))
        data = parser.parse(stream, None, self.parser_context)

        self.assertEqual(data['_meta'], {'random_key': 'random_value'})
Esempio n. 6
0
    def test_parse_include_metadata_format_field_names(self):
        parser = JSONParser()

        stream = BytesIO(self.string.encode('utf-8'))
        data = parser.parse(stream, None, self.parser_context)

        self.assertEqual(data['_meta'], {'random_key': 'random_value'})
        self.assertEqual(data['json_value'], {'JsonKey': 'JsonValue'})
    def test_parse_include_metadata_format_field_names(self):
        parser = JSONParser()

        stream = BytesIO(self.string.encode('utf-8'))
        data = parser.parse(stream, None, self.parser_context)

        self.assertEqual(data['_meta'], {'random_key': 'random_value'})
        self.assertEqual(data['json_value'], {'JsonKey': 'JsonValue'})
    def test_parse_include_metadata_format_field_names(self):
        parser = JSONParser()

        stream = BytesIO(self.string.encode("utf-8"))
        data = parser.parse(stream, None, self.parser_context)

        self.assertEqual(data["_meta"], {"random_key": "random_value"})
        self.assertEqual(data["json_value"], {"JsonKey": "JsonValue"})
Esempio n. 9
0
    def test_patch_doesnt_raise_attribute_error(self):
        parser = JSONParser()

        stream = BytesIO(self.string.encode('utf-8'))

        data = parser.parse(stream, None, self.parser_context)

        assert data['id'] == 123
        assert data['body'] == 'hello'
    def test_parse_invalid_data_key(self):
        parser = JSONParser()

        string = json.dumps(
            {
                "data": [
                    {
                        "id": 123,
                        "type": "Blog",
                        "attributes": {"json-value": {"JsonKey": "JsonValue"}},
                    }
                ]
            }
        )
        stream = BytesIO(string.encode("utf-8"))

        with self.assertRaises(ParseError):
            parser.parse(stream, None, self.parser_context)
    def test_patch_doesnt_raise_attribute_error(self):
        parser = JSONParser()

        stream = BytesIO(self.string.encode("utf-8"))

        data = parser.parse(stream, None, self.parser_context)

        assert data["id"] == 123
        assert data["body"] == "hello"