Example #1
0
    def test_apply_to_stanza(self):
        stanza_obj = stanza.Presence(type_=structs.PresenceType.PROBE)
        self.assertEqual(stanza_obj.show, structs.PresenceShow.NONE)

        ps = structs.PresenceState(available=True,
                                   show=structs.PresenceShow.DND)
        ps.apply_to_stanza(stanza_obj)
        self.assertEqual(
            structs.PresenceType.AVAILABLE,
            stanza_obj.type_
        )
        self.assertEqual(
            structs.PresenceShow.DND,
            stanza_obj.show
        )

        ps = structs.PresenceState()
        ps.apply_to_stanza(stanza_obj)
        self.assertEqual(
            structs.PresenceType.UNAVAILABLE,
            stanza_obj.type_
        )
        self.assertEqual(
            stanza_obj.show,
            structs.PresenceShow.NONE,
        )
Example #2
0
    def test_apply_to_stanza(self):
        stanza_obj = stanza.Presence(type_="probe")
        self.assertEqual(
            "probe",
            stanza_obj.type_
        )
        self.assertIsNone(stanza_obj.show)

        ps = structs.PresenceState(available=True, show="dnd")
        ps.apply_to_stanza(stanza_obj)
        self.assertEqual(
            None,
            stanza_obj.type_
        )
        self.assertEqual(
            "dnd",
            stanza_obj.show
        )

        ps = structs.PresenceState()
        ps.apply_to_stanza(stanza_obj)
        self.assertEqual(
            "unavailable",
            stanza_obj.type_
        )
        self.assertIsNone(
            stanza_obj.show
        )
Example #3
0
 def test_init_available_validate_show(self):
     with self.assertRaises(ValueError):
         ps = structs.PresenceState(available=True, show="foobar")
     for value in ["dnd", "xa", "away", None, "chat"]:
         value = structs.PresenceShow(value)
         ps = structs.PresenceState(available=True, show=value)
         self.assertEqual(value, ps.show)
Example #4
0
 def test_repr(self):
     self.assertEqual("<PresenceState>", repr(structs.PresenceState()))
     self.assertEqual("<PresenceState available>",
                      repr(structs.PresenceState(available=True)))
     self.assertEqual(
         "<PresenceState available show=<PresenceShow.DND: 'dnd'>>",
         repr(
             structs.PresenceState(available=True,
                                   show=structs.PresenceShow.DND)))
Example #5
0
    def test_from_stanza(self):
        stanza_obj = stanza.Presence(type_=structs.PresenceType.AVAILABLE)
        stanza_obj.show = structs.PresenceShow.XA
        self.assertEqual(
            structs.PresenceState(available=True,
                                  show=structs.PresenceShow.XA),
            structs.PresenceState.from_stanza(stanza_obj))

        stanza_obj = stanza.Presence(type_=structs.PresenceType.UNAVAILABLE, )
        self.assertEqual(structs.PresenceState(available=False),
                         structs.PresenceState.from_stanza(stanza_obj))
Example #6
0
    def test_from_stanza(self):
        stanza_obj = stanza.Presence(type_=None)
        stanza_obj.show = "xa"
        self.assertEqual(
            structs.PresenceState(available=True, show="xa"),
            structs.PresenceState.from_stanza(stanza_obj)
        )

        stanza_obj = stanza.Presence(type_="unavailable")
        self.assertEqual(
            structs.PresenceState(available=False),
            structs.PresenceState.from_stanza(stanza_obj)
        )
Example #7
0
 def test_repr(self):
     self.assertEqual(
         "<PresenceState>",
         repr(structs.PresenceState())
     )
     self.assertEqual(
         "<PresenceState available>",
         repr(structs.PresenceState(available=True))
     )
     self.assertEqual(
         "<PresenceState available show='dnd'>",
         repr(structs.PresenceState(available=True, show="dnd"))
     )
Example #8
0
 def test_from_stanza_nonstrict_by_default(self):
     stanza_obj = stanza.Presence(type_="unavailable")
     stanza_obj.show = "dnd"
     self.assertEqual(
         structs.PresenceState(available=False),
         structs.PresenceState.from_stanza(stanza_obj)
     )
Example #9
0
 def test_immutable(self):
     ps = structs.PresenceState()
     with self.assertRaises(AttributeError):
         ps.foo = "bar"
     with self.assertRaises(AttributeError):
         ps.available = True
     with self.assertRaises(AttributeError):
         ps.show = "baz"
Example #10
0
 def test_from_stanza_nonstrict_by_default(self):
     stanza_obj = stanza.Presence(
         type_=structs.PresenceType.UNAVAILABLE
     )
     stanza_obj.show = structs.PresenceShow.AWAY
     self.assertEqual(
         structs.PresenceState(available=False),
         structs.PresenceState.from_stanza(stanza_obj)
     )
Example #11
0
 def test_init_compat(self):
     with self.assertWarnsRegex(
             DeprecationWarning,
             "as of aioxmpp 1.0, the show argument must use "
             "PresenceShow instead of str") as ctx:
         ps = structs.PresenceState(True, "dnd")
     self.assertIn(
         "test_structs.py",
         ctx.filename,
     )
     self.assertTrue(ps.available)
     self.assertEqual(ps.show, structs.PresenceShow.DND)
Example #12
0
    def test_apply_to_stanza(self):
        stanza_obj = stanza.Presence(type_=structs.PresenceType.PROBE)
        self.assertIsNone(stanza_obj.show)

        ps = structs.PresenceState(available=True, show="dnd")
        ps.apply_to_stanza(stanza_obj)
        self.assertEqual(
            structs.PresenceType.AVAILABLE,
            stanza_obj.type_
        )
        self.assertEqual(
            "dnd",
            stanza_obj.show
        )

        ps = structs.PresenceState()
        ps.apply_to_stanza(stanza_obj)
        self.assertEqual(
            structs.PresenceType.UNAVAILABLE,
            stanza_obj.type_
        )
        self.assertIsNone(
            stanza_obj.show
        )
Example #13
0
 def test_equality(self):
     self.assertEqual(
         structs.PresenceState(),
         structs.PresenceState()
     )
     self.assertEqual(
         structs.PresenceState(available=True),
         structs.PresenceState(available=True)
     )
     self.assertEqual(
         structs.PresenceState(available=True, show="dnd"),
         structs.PresenceState(available=True, show="dnd")
     )
     self.assertFalse(
         structs.PresenceState(available=True, show="dnd") !=
         structs.PresenceState(available=True, show="dnd")
     )
Example #14
0
    def test_proper_exception_on_invalid_ordering_operand(self):
        with self.assertRaises(TypeError):
            structs.PresenceState() < 1

        with self.assertRaises(TypeError):
            structs.PresenceState() > 1

        with self.assertRaises(TypeError):
            structs.PresenceState() >= 1

        with self.assertRaises(TypeError):
            structs.PresenceState() <= 1

        self.assertFalse(structs.PresenceState() == 0)
        self.assertTrue(structs.PresenceState() != 0)
Example #15
0
    def test_ordering(self):
        values = [
            structs.PresenceState(),
            structs.PresenceState(available=True, show="dnd"),
            structs.PresenceState(available=True, show="xa"),
            structs.PresenceState(available=True, show="away"),
            structs.PresenceState(available=True),
            structs.PresenceState(available=True, show="chat"),
        ]

        for i in range(1, len(values)-1):
            for v1, v2 in zip(values[:-i], values[i:]):
                self.assertLess(v1, v2)
                self.assertLessEqual(v1, v2)
                self.assertNotEqual(v1, v2)
                self.assertGreater(v2, v1)
                self.assertGreaterEqual(v2, v1)
Example #16
0
    def test_ordering(self):
        values = [
            structs.PresenceState(),
            structs.PresenceState(available=True,
                                  show=structs.PresenceShow.XA),
            structs.PresenceState(available=True,
                                  show=structs.PresenceShow.AWAY),
            structs.PresenceState(available=True),
            structs.PresenceState(available=True,
                                  show=structs.PresenceShow.CHAT),
            structs.PresenceState(available=True,
                                  show=structs.PresenceShow.DND),
        ]

        for i in range(1, len(values)-1):
            for v1, v2 in zip(values[:-i], values[i:]):
                self.assertLess(v1, v2)
                self.assertLessEqual(v1, v2)
                self.assertNotEqual(v1, v2)
                self.assertGreater(v2, v1)
                self.assertGreaterEqual(v2, v1)
Example #17
0
 def test_init_available_with_show(self):
     ps = structs.PresenceState(available=True, show="dnd")
     self.assertTrue(ps.available)
     self.assertEqual("dnd", ps.show)
Example #18
0
 def test_equality_deals_with_different_types(self):
     self.assertNotEqual(structs.PresenceState(), None)
     self.assertNotEqual(structs.PresenceState(), "foo")
     self.assertNotEqual(structs.PresenceState(), 123)
Example #19
0
 def test_init_unavailable_forbids_show(self):
     with self.assertRaises(ValueError):
         structs.PresenceState(available=False,
                               show=structs.PresenceShow.DND)
Example #20
0
 def test_init_available_with_show(self):
     ps = structs.PresenceState(available=True,
                                show=structs.PresenceShow.DND)
     self.assertTrue(ps.available)
     self.assertIs(structs.PresenceShow.DND, ps.show)
Example #21
0
 def test_init_normalizes_available(self):
     ps = structs.PresenceState(available="foo")
     self.assertIs(True, ps.available)
Example #22
0
 def test_init_available(self):
     ps = structs.PresenceState(available=True)
     self.assertTrue(ps.available)
Example #23
0
 def test_init_defaults(self):
     ps = structs.PresenceState()
     self.assertFalse(ps.available)
     self.assertEqual(ps.show, structs.PresenceShow.NONE)
Example #24
0
 def test_init_defaults(self):
     ps = structs.PresenceState()
     self.assertFalse(ps.available)
     self.assertIsNone(ps.show)