Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_init(self):
serializer = JsonSerializer()
assert isinstance(serializer, BaseSerializer)
assert serializer.DEFAULT_ENCODING == "utf-8"
assert serializer.encoding == "utf-8"
def test_dumps(self):
assert (
JsonSerializer().dumps({"hi": 1}) == '{"hi": 1}'
or JsonSerializer().dumps({"hi": 1}) == '{"hi":1}' # json
) # ujson
def test_loads_with_none(self):
assert JsonSerializer().loads(None) is None
def test_set_config_updates_existing_values(self):
assert not isinstance(caches.get("default").serializer, JsonSerializer)
caches.set_config(
{
"default": {
"cache": "aiocache.SimpleMemoryCache",
"serializer": {"class": "aiocache.serializers.JsonSerializer"},
}
}
)
assert isinstance(caches.get("default").serializer, JsonSerializer)
def test_init_fails_if_msgpack_not_installed(self):
with mock.patch("aiocache.serializers.serializers.msgpack", None):
with pytest.raises(RuntimeError):
MsgPackSerializer()
assert JsonSerializer(), "Other serializers should still initialize"
def test_dumps_with_none(self):
assert JsonSerializer().dumps(None) == "null"
def test_dumps_and_loads(self):
obj = {"hi": 1}
serializer = JsonSerializer()
assert serializer.loads(serializer.dumps(obj)) == obj
async def new_search(request):
upload_image = request.files.get("image")
if not upload_image:
raise NotFound(message='not image file')
image_types = ['image/jpeg', 'image/jpg', 'image/png']
if upload_image.type not in image_types:
raise NotFound(message='not image file')
upload_image_type = upload_image.type.split('/')[-1]
file_name = str(time.time())[:10] + '.' + upload_image_type
file_path = upload_image_path + file_name
with open(file_path, "wb") as f:
f.write(request.files["image"][0].body)
search_results = image_search(file_path)[:5]
cache = SimpleMemoryCache(serializer=JsonSerializer())
response_dict = {
'site_name': site_name,
'upload_image': file_name,
'search_results': search_results
}
await cache.set("response_dict", response_dict)
return response_dict
def __init__(self, serializer=None, **kwargs):
super().__init__(**kwargs)
self.serializer = serializer or JsonSerializer()
def __init__(self, serializer=None, **kwargs):
super().__init__(**kwargs)
self.serializer = serializer or JsonSerializer()