MCPcopy Index your code
hub / github.com/MongoEngine/mongoengine / test_dynamic_delta

Method test_dynamic_delta

tests/document/test_delta.py:696–738  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

694 assert 1 == Person.objects(age=24).count()
695
696 def test_dynamic_delta(self):
697 class Doc(DynamicDocument):
698 pass
699
700 Doc.drop_collection()
701 doc = Doc()
702 doc.save()
703
704 doc = Doc.objects.first()
705 assert doc._get_changed_fields() == []
706 assert doc._delta() == ({}, {})
707
708 doc.string_field = "hello"
709 assert doc._get_changed_fields() == ["string_field"]
710 assert doc._delta() == ({"string_field": "hello"}, {})
711
712 doc._changed_fields = []
713 doc.int_field = 1
714 assert doc._get_changed_fields() == ["int_field"]
715 assert doc._delta() == ({"int_field": 1}, {})
716
717 doc._changed_fields = []
718 dict_value = {"hello": "world", "ping": "pong"}
719 doc.dict_field = dict_value
720 assert doc._get_changed_fields() == ["dict_field"]
721 assert doc._delta() == ({"dict_field": dict_value}, {})
722
723 doc._changed_fields = []
724 list_value = ["1", 2, {"hello": "world"}]
725 doc.list_field = list_value
726 assert doc._get_changed_fields() == ["list_field"]
727 assert doc._delta() == ({"list_field": list_value}, {})
728
729 # Test unsetting
730 doc._changed_fields = []
731 doc.dict_field = {}
732 assert doc._get_changed_fields() == ["dict_field"]
733 assert doc._delta() == ({}, {"dict_field": 1})
734
735 doc._changed_fields = []
736 doc.list_field = []
737 assert doc._get_changed_fields() == ["list_field"]
738 assert doc._delta() == ({}, {"list_field": 1})
739
740 def test_delta_with_dbref_true(self):
741 person, organization, employee = self.circular_reference_deltas_2(

Callers

nothing calls this directly

Calls 6

drop_collectionMethod · 0.80
_get_changed_fieldsMethod · 0.80
_deltaMethod · 0.80
DocClass · 0.70
saveMethod · 0.45
firstMethod · 0.45

Tested by

no test coverage detected