File: event_builders_test.py

package info (click to toggle)
python-matrix-nio 0.25.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,224 kB
  • sloc: python: 23,670; makefile: 36; sh: 8
file content (69 lines) | stat: -rw-r--r-- 2,181 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import pytest

import nio.event_builders as builders


class TestClass:
    def test_base_class(self):
        with pytest.raises(NotImplementedError):
            builders.EventBuilder().as_dict()

    def test_enable_encryption(self):
        event = builders.EnableEncryptionBuilder(
            algorithm="test", rotation_ms=9801, rotation_msgs=101
        ).as_dict()

        assert event == {
            "type": "m.room.encryption",
            "state_key": "",
            "content": {
                "algorithm": "test",
                "rotation_period_ms": 9801,
                "rotation_period_msgs": 101,
            },
        }

    def test_change_name(self):
        event = builders.ChangeNameBuilder("foo").as_dict()
        assert event == {
            "type": "m.room.name",
            "state_key": "",
            "content": {"name": "foo"},
        }
        too_long_name = "TooLongName" * 256
        with pytest.raises(
            ValueError, match=f"Room name exceeds 255 characters: {too_long_name}"
        ):
            builders.ChangeNameBuilder(too_long_name)

    def test_change_topic(self):
        event = builders.ChangeTopicBuilder("Lorem ipsum").as_dict()
        assert event == {
            "type": "m.room.topic",
            "state_key": "",
            "content": {"topic": "Lorem ipsum"},
        }

    def test_change_join_rules(self):
        event = builders.ChangeJoinRulesBuilder("invite").as_dict()
        assert event == {
            "type": "m.room.join_rules",
            "state_key": "",
            "content": {"join_rule": "invite"},
        }

    def test_change_guest_access(self):
        event = builders.ChangeGuestAccessBuilder("can_join").as_dict()
        assert event == {
            "type": "m.room.guest_access",
            "state_key": "",
            "content": {"guest_access": "can_join"},
        }

    def test_change_history_visibility(self):
        event = builders.ChangeHistoryVisibilityBuilder("joined").as_dict()
        assert event == {
            "type": "m.room.history_visibility",
            "state_key": "",
            "content": {"history_visibility": "joined"},
        }