def to_json(self, *args, **kwargs): """Return the JSON representation of the data. Takes the same arguments as Python's built-in ``json.dumps``. """ ret = self.opts.json_module.dumps(self.data, *args, **kwargs) # On Python 2, json.dumps returns bytestrings # On Python 3, json.dumps returns unicode # Ensure that a bytestring is returned if isinstance(ret, text_type): return binary_type(ret.encode('utf-8')) return ret
def to_json(self, *args, **kwargs): '''Return the JSON representation of the data. Takes the same arguments as Pythons built-in ``json.dumps``. ''' ret = self.opts.json_module.dumps(self.data, *args, **kwargs) # On Python 2, json.dumps returns bytestrings # On Python 3, json.dumps returns unicode # Ensure that a bytestring is returned if isinstance(ret, text_type): return binary_type(ret.encode('utf-8')) return ret
def test_json(self): json_data = self.serialized.json expected = binary_type(json.dumps(self.serialized.data).encode("utf-8")) assert_equal(json_data, expected)
def test_json(serialized_user): json_data = serialized_user.json expected = binary_type(json.dumps(serialized_user.data).encode("utf-8")) assert json_data == expected
def test_dumps_returns_json(user): ser = UserSchema() serialized, errors = ser.dump(user) json_data, errors = ser.dumps(user) expected = binary_type(json.dumps(serialized).encode("utf-8")) assert json_data == expected