| 1 |
# Copyright (c) Ralph Meijer. |
| 2 |
# See LICENSE for details. |
| 3 |
|
| 4 |
""" |
| 5 |
Tests for L{tx_xmpp.format} |
| 6 |
""" |
| 7 |
|
| 8 |
from twisted.trial import unittest |
| 9 |
from twisted.words.xish import domish |
| 10 |
|
| 11 |
from .. import formats |
| 12 |
|
| 13 |
|
| 14 |
class MoodTests(unittest.TestCase): |
| 15 |
""" |
| 16 |
Tests for L{formats.Mood}. |
| 17 |
""" |
| 18 |
|
| 19 |
def test_fromXml(self): |
| 20 |
""" |
| 21 |
Moods are parsed from Elements. |
| 22 |
""" |
| 23 |
element = domish.Element((formats.NS_MOOD, "mood")) |
| 24 |
element.addElement("happy") |
| 25 |
element.addElement("text", content="Really happy!") |
| 26 |
mood = formats.Mood.fromXml(element) |
| 27 |
self.assertEquals("happy", mood.value) |
| 28 |
self.assertEquals("Really happy!", mood.text) |
| 29 |
|
| 30 |
|
| 31 |
class TuneTests(unittest.TestCase): |
| 32 |
""" |
| 33 |
Tests for L{formats.Tune}. |
| 34 |
""" |
| 35 |
|
| 36 |
def test_fromXmlTrack(self): |
| 37 |
""" |
| 38 |
The track filed in a user tune is parsed. |
| 39 |
""" |
| 40 |
element = domish.Element((formats.NS_TUNE, "tune")) |
| 41 |
element.addElement("track", content="The Power") |
| 42 |
tune = formats.Tune.fromXml(element) |
| 43 |
self.assertEquals("The Power", tune.track) |
| 44 |
|
| 45 |
def test_fromXmlLength(self): |
| 46 |
""" |
| 47 |
The length filed in a user tune is parsed as an int. |
| 48 |
""" |
| 49 |
element = domish.Element((formats.NS_TUNE, "tune")) |
| 50 |
element.addElement("length", content="322") |
| 51 |
tune = formats.Tune.fromXml(element) |
| 52 |
self.assertEquals(322, tune.length) |