Skip to content

Commit

Permalink
test: issue-10 🚨 Add tests for changed marker
Browse files Browse the repository at this point in the history
  • Loading branch information
ddanier committed Nov 10, 2023
1 parent 1e4a644 commit 0e2f1f6
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pydantic_changedetect/changedetect.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,12 @@ def model_mark_changed(self, marker: str) -> None:

self.model_changed_markers.add(marker)

def unmark_changed(self, marker: str) -> None:
def model_unmark_changed(self, marker: str) -> None:
"""Remove one changed marker."""

self.model_changed_markers.discard(marker)

def has_changed_marker(
def model_has_changed_marker(
self,
marker: str,
) -> bool:
Expand Down
51 changes: 51 additions & 0 deletions tests/test_changedetect.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,3 +485,54 @@ def test_compatibility_methods_work():
assert something.__changed_fields_recursive__ == {"id"}
with pytest.warns(DeprecationWarning):
assert something.__original__ == {"id": 1}


# Changed markers


def test_changed_markers_can_be_set():
something = Something(id=1)

something.model_mark_changed("test")
assert "test" in something.model_changed_markers
assert something.model_has_changed_marker("test")


def test_changed_markers_can_be_unset():
something = Something(id=1)

something.model_mark_changed("test")
assert something.model_has_changed_marker("test")

something.model_unmark_changed("test")
assert not something.model_has_changed_marker("test")


def test_changed_markers_will_be_also_reset():
something = Something(id=1)

something.model_mark_changed("test")
assert something.model_has_changed_marker("test")

something.model_reset_changed()
assert not something.model_has_changed_marker("test")


def test_model_is_changed_if_marker_or_change_exists():
something = Something(id=1)

assert not something.model_has_changed
something.model_mark_changed("test")
assert something.model_has_changed
something.model_reset_changed()

assert not something.model_has_changed
something.model_set_changed("id")
assert something.model_has_changed
something.model_reset_changed()

assert not something.model_has_changed
something.model_set_changed("id")
something.model_mark_changed("test")
assert something.model_has_changed
something.model_reset_changed()

0 comments on commit 0e2f1f6

Please sign in to comment.