File: test_formats.py

package info (click to toggle)
python-tx-xmpp 0.10.1.post1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,468 kB
  • sloc: python: 12,915; makefile: 3
file content (54 lines) | stat: -rw-r--r-- 1,454 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
# Copyright (c) Ralph Meijer.
# See LICENSE for details.

"""
Tests for L{tx_xmpp.format}
"""

from __future__ import division, absolute_import

from twisted.trial import unittest
from twisted.words.xish import domish

from tx_xmpp import formats


class MoodTests(unittest.TestCase):
    """
    Tests for L{formats.Mood}.
    """

    def test_fromXml(self):
        """
        Moods are parsed from Elements.
        """
        element = domish.Element((formats.NS_MOOD, "mood"))
        element.addElement("happy")
        element.addElement("text", content="Really happy!")
        mood = formats.Mood.fromXml(element)
        self.assertEquals("happy", mood.value)
        self.assertEquals("Really happy!", mood.text)


class TuneTests(unittest.TestCase):
    """
    Tests for L{formats.Tune}.
    """

    def test_fromXmlTrack(self):
        """
        The track filed in a user tune is parsed.
        """
        element = domish.Element((formats.NS_TUNE, "tune"))
        element.addElement("track", content="The Power")
        tune = formats.Tune.fromXml(element)
        self.assertEquals("The Power", tune.track)

    def test_fromXmlLength(self):
        """
        The length filed in a user tune is parsed as an int.
        """
        element = domish.Element((formats.NS_TUNE, "tune"))
        element.addElement("length", content="322")
        tune = formats.Tune.fromXml(element)
        self.assertEquals(322, tune.length)