mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-30 07:51:27 +00:00
c6919293b6
I've learned that there is no problem in grouping mutations like we do with queries. This is a big mistake from my side, now we have legacy not so conveniently placed endpoints. I've grouped all mutations, left the copies of old ones flattened in the root for backwards compatibility. We will migrate to mutation groups on client side, and backups now only use grouped mutations. Tests are updated.
34 lines
843 B
Python
34 lines
843 B
Python
import pytest
|
|
|
|
from pydantic import BaseModel
|
|
from datetime import datetime
|
|
from typing import Optional
|
|
|
|
from selfprivacy_api.utils.redis_model_storage import store_model_as_hash, hash_as_model
|
|
from selfprivacy_api.utils.redis_pool import RedisPool
|
|
|
|
TEST_KEY = "model_storage"
|
|
redis = RedisPool().get_connection()
|
|
|
|
|
|
@pytest.fixture()
|
|
def clean_redis():
|
|
redis.delete(TEST_KEY)
|
|
|
|
|
|
class DummyModel(BaseModel):
|
|
name: str
|
|
date: Optional[datetime]
|
|
|
|
|
|
def test_store_retrieve():
|
|
model = DummyModel(name="test", date=datetime.now())
|
|
store_model_as_hash(redis, TEST_KEY, model)
|
|
assert hash_as_model(redis, TEST_KEY, DummyModel) == model
|
|
|
|
|
|
def test_store_retrieve_none():
|
|
model = DummyModel(name="test", date=None)
|
|
store_model_as_hash(redis, TEST_KEY, model)
|
|
assert hash_as_model(redis, TEST_KEY, DummyModel) == model
|