Philipp Hörist pushed to branch master at gajim / gajim


Commits:
1fd46efa by Philipp Hörist at 2025-09-28T10:39:02+02:00
cfix: Add more test for data deletion and fix deletion order

- - - - -


2 changed files:

- gajim/common/storage/archive/storage.py
- test/database/test_methods.py


Changes:

=====================================
gajim/common/storage/archive/storage.py
=====================================
@@ -1088,9 +1088,10 @@ def remove_history_for_jid(self, session: Session, 
account: str, jid: JID) -> No
             Receipt,
             DisplayedMarker,
             Reaction,
+            Message,
+            # Tables with fk constraints
             Thread,
             SecurityLabel,
-            Message,
         ]
 
         for table in tables:
@@ -1118,6 +1119,7 @@ def remove_all_history(self, session: Session) -> None:
         session.execute(delete(Reaction))
         session.execute(delete(Message))
 
+        # Tables with fk constraints
         session.execute(delete(SecurityLabel))
         session.execute(delete(Thread))
         session.execute(delete(Encryption))


=====================================
test/database/test_methods.py
=====================================
@@ -25,6 +25,7 @@
 from gajim.common.storage.archive.models import MessageError
 from gajim.common.storage.archive.models import Moderation
 from gajim.common.storage.archive.models import Occupant
+from gajim.common.storage.archive.models import SecurityLabel
 from gajim.common.storage.archive.storage import MessageArchiveStorage
 from gajim.common.util.datetime import utc_now
 
@@ -340,11 +341,13 @@ def test_remove_history(self) -> None:
         remote_jid = JID.from_string("[email protected]")
         self._insert_messages("testacc1", remote_jid=remote_jid, count=10)
 
+        # Moderation message should no match any message to
+        # test if orphan data are removed
         mod = Moderation(
             account_="testacc1",
             remote_jid_=remote_jid,
             occupant_=None,
-            stanza_id="stanzaid1",
+            stanza_id="DoNotMatchID",
             by=None,
             reason=None,
             timestamp=utc_now(),
@@ -365,6 +368,32 @@ def test_remove_history(self) -> None:
 
         self._archive.insert_object(error)
 
+        seclabel = SecurityLabel(
+            account_="testacc1",
+            remote_jid_=remote_jid,
+            label_hash="hash1",
+            displaymarking="dm",
+            bgcolor="red",
+            fgcolor="blue",
+            updated_at=utc_now(),
+        )
+
+        m = Message(
+            account_="testacc1",
+            remote_jid_=remote_jid,
+            resource="test",
+            type=MessageType.CHAT,
+            direction=ChatDirection.INCOMING,
+            timestamp=utc_now(),
+            state=MessageState.ACKNOWLEDGED,
+            id="123",
+            stanza_id="stanzaid123",
+            text="testmessage",
+            security_label_=seclabel,
+            thread_id_="testthreadid",
+        )
+        self._archive.insert_object(m)
+
         with self._archive.get_session() as s:
             result = s.scalar(select(MessageError))
             self.assertIsNotNone(result)



View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/1fd46efaa6823d13a70fd1bc14e17e2ca752c59f

-- 
View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/1fd46efaa6823d13a70fd1bc14e17e2ca752c59f
You're receiving this email because of your account on dev.gajim.org.


_______________________________________________
Commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to