File: test_events.py

package info (click to toggle)
gajim 2.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 17,512 kB
  • sloc: python: 79,978; sh: 591; xml: 67; makefile: 6
file content (53 lines) | stat: -rw-r--r-- 1,632 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# This file is part of Gajim.
#
# SPDX-License-Identifier: GPL-3.0-or-later

from __future__ import annotations

import unittest
from unittest.mock import MagicMock

from nbxmpp.protocol import JID

from gajim.common import app  # type: ignore # noqa: F401
from gajim.common import events
from gajim.common.modules.contacts import GroupchatContact
from gajim.common.storage.events.storage import EventStorage
from gajim.common.util.datetime import utc_now


class EventsTest(unittest.TestCase):
    def setUp(self) -> None:
        self._event_storage = EventStorage()
        self._event_storage.init()

        self._account = "testacc1"

        self._group_chat_contact = MagicMock(spec_set=GroupchatContact)
        self._group_chat_contact.account = self._account
        self._group_chat_contact.jid = JID.from_string("groupchat@example.org")

    def tearDown(self) -> None:
        self._event_storage.shutdown()

    def test_insert_muc_room_destroyed(self) -> None:
        event_data = events.MUCRoomDestroyed(
            timestamp=utc_now(),
            reason="Reason",
            alternate=JID.from_string("some-alternate@example.org"),
        )

        self._event_storage.store(self._group_chat_contact, event_data)

        events_list = self._event_storage.load(
            self._group_chat_contact, True, utc_now().timestamp(), 1
        )
        first_event = events_list[0]
        assert isinstance(first_event, events.MUCRoomDestroyed)
        self.assertEqual(
            first_event.alternate, JID.from_string("some-alternate@example.org")
        )


if __name__ == "__main__":
    unittest.main()