-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
192 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import pytest | ||
|
||
from beanie.exceptions import ApplyChangesException | ||
from beanie.odm.documents import MergeStrategy | ||
from tests.odm.models import DocumentToTestSync | ||
|
||
|
||
class TestSync: | ||
async def test_merge_remote(self): | ||
doc = DocumentToTestSync() | ||
await doc.insert() | ||
|
||
doc2 = await DocumentToTestSync.get(doc.id) | ||
doc2.s = "foo" | ||
|
||
doc.i = 100 | ||
await doc.save() | ||
|
||
await doc2.sync() | ||
|
||
assert doc2.s == "TEST" | ||
assert doc2.i == 100 | ||
|
||
async def test_merge_local(self): | ||
doc = DocumentToTestSync(d={"option_1": {"s": "foo"}}) | ||
await doc.insert() | ||
|
||
doc2 = await DocumentToTestSync.get(doc.id) | ||
doc2.s = "foo" | ||
doc2.n.option_1.s = "bar" | ||
doc2.d["option_1"]["s"] = "bar" | ||
|
||
doc.i = 100 | ||
await doc.save() | ||
|
||
await doc2.sync(merge_strategy=MergeStrategy.local) | ||
|
||
assert doc2.s == "foo" | ||
assert doc2.n.option_1.s == "bar" | ||
assert doc2.d["option_1"]["s"] == "bar" | ||
|
||
assert doc2.i == 100 | ||
|
||
async def test_merge_local_impossible_apply_changes(self): | ||
doc = DocumentToTestSync(d={"option_1": {"s": "foo"}}) | ||
await doc.insert() | ||
|
||
doc2 = await DocumentToTestSync.get(doc.id) | ||
doc2.d["option_1"]["s"] = {"foo": "bar"} | ||
|
||
doc.d = {"option_1": "nothing"} | ||
await doc.save() | ||
with pytest.raises(ApplyChangesException): | ||
await doc2.sync(merge_strategy=MergeStrategy.local) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters