add exclude to save_related method, switch to same relation_map from iter
This commit is contained in:
@ -91,6 +91,14 @@ async def test_saving_related_fk_rel():
|
||||
assert count == 1
|
||||
assert comp.hq.saved
|
||||
|
||||
comp.hq.name = "Suburbs 2"
|
||||
assert not comp.hq.saved
|
||||
assert comp.saved
|
||||
|
||||
count = await comp.save_related(exclude={"hq"})
|
||||
assert count == 0
|
||||
assert not comp.hq.saved
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_saving_many_to_many():
|
||||
@ -123,6 +131,16 @@ async def test_saving_many_to_many():
|
||||
assert hq.nicks[0].saved
|
||||
assert hq.nicks[1].saved
|
||||
|
||||
hq.nicks[0].name = "Kabucha a"
|
||||
hq.nicks[1].name = "Kabucha2 a"
|
||||
assert not hq.nicks[0].saved
|
||||
assert not hq.nicks[1].saved
|
||||
|
||||
count = await hq.save_related(exclude={"nicks": ...})
|
||||
assert count == 0
|
||||
assert not hq.nicks[0].saved
|
||||
assert not hq.nicks[1].saved
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_saving_reversed_relation():
|
||||
@ -211,3 +229,16 @@ async def test_saving_nested():
|
||||
assert hq.nicks[0].level.saved
|
||||
assert hq.nicks[1].saved
|
||||
assert hq.nicks[1].level.saved
|
||||
|
||||
hq.nicks[0].level.name = "Low 2"
|
||||
hq.nicks[1].level.name = "Medium 2"
|
||||
assert not hq.nicks[0].level.saved
|
||||
assert not hq.nicks[1].level.saved
|
||||
assert hq.nicks[0].saved
|
||||
assert hq.nicks[1].saved
|
||||
count = await hq.save_related(follow=True, exclude={"nicks": {"level"}})
|
||||
assert count == 0
|
||||
assert hq.nicks[0].saved
|
||||
assert not hq.nicks[0].level.saved
|
||||
assert hq.nicks[1].saved
|
||||
assert not hq.nicks[1].level.saved
|
||||
|
||||
@ -4,7 +4,12 @@ import sqlalchemy
|
||||
import ormar
|
||||
from ormar.models.mixins import ExcludableMixin
|
||||
from ormar.queryset.prefetch_query import sort_models
|
||||
from ormar.queryset.utils import translate_list_to_dict, update_dict_from_list, update
|
||||
from ormar.queryset.utils import (
|
||||
subtract_dict,
|
||||
translate_list_to_dict,
|
||||
update_dict_from_list,
|
||||
update,
|
||||
)
|
||||
from tests.settings import DATABASE_URL
|
||||
|
||||
|
||||
@ -79,6 +84,21 @@ def test_updating_dict_inc_set_with_dict():
|
||||
}
|
||||
|
||||
|
||||
def test_subtracting_dict_inc_set_with_dict():
|
||||
curr_dict = {
|
||||
"aa": Ellipsis,
|
||||
"bb": Ellipsis,
|
||||
"cc": {"aa": {"xx", "yy"}, "bb": Ellipsis},
|
||||
}
|
||||
dict_to_update = {
|
||||
"uu": Ellipsis,
|
||||
"bb": {"cc", "dd"},
|
||||
"cc": {"aa": {"xx": {"oo": Ellipsis}}, "bb": Ellipsis},
|
||||
}
|
||||
test = subtract_dict(curr_dict, dict_to_update)
|
||||
assert test == {"aa": Ellipsis, "cc": {"aa": {"yy": Ellipsis}}}
|
||||
|
||||
|
||||
def test_updating_dict_inc_set_with_dict_inc_set():
|
||||
curr_dict = {
|
||||
"aa": Ellipsis,
|
||||
@ -99,6 +119,23 @@ def test_updating_dict_inc_set_with_dict_inc_set():
|
||||
}
|
||||
|
||||
|
||||
def test_subtracting_dict_inc_set_with_dict_inc_set():
|
||||
curr_dict = {
|
||||
"aa": Ellipsis,
|
||||
"bb": Ellipsis,
|
||||
"cc": {"aa": {"xx", "yy"}, "bb": Ellipsis},
|
||||
"dd": {"aa", "bb"},
|
||||
}
|
||||
dict_to_update = {
|
||||
"aa": Ellipsis,
|
||||
"bb": {"cc", "dd"},
|
||||
"cc": {"aa": {"xx", "oo", "zz", "ii"}},
|
||||
"dd": {"aa", "bb"},
|
||||
}
|
||||
test = subtract_dict(curr_dict, dict_to_update)
|
||||
assert test == {"cc": {"aa": {"yy"}, "bb": Ellipsis}}
|
||||
|
||||
|
||||
database = databases.Database(DATABASE_URL, force_rollback=True)
|
||||
metadata = sqlalchemy.MetaData()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user