Changeset View
Changeset View
Standalone View
Standalone View
tests/unit/test-018-note.py
Show All 19 Lines | <note xmlns="http://kolab.org" version="3.0"> | ||||
<description><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> | <description><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> | ||||
<html><head><meta name="qrichtext" content="1" /><meta http-equiv="Content-Type" /></head><body> | <html><head><meta name="qrichtext" content="1" /><meta http-equiv="Content-Type" /></head><body> | ||||
<p>This is a HTML note</p> | <p>This is a HTML note</p> | ||||
</body></html></description> | </body></html></description> | ||||
<color/> | <color/> | ||||
</note> | </note> | ||||
""" | """ | ||||
class TestNoteXML(unittest.TestCase): | class TestNoteXML(unittest.TestCase): | ||||
def assertIsInstance(self, _value, _type): | def assertIsInstance(self, _value, _type): | ||||
if hasattr(unittest.TestCase, 'assertIsInstance'): | if hasattr(unittest.TestCase, 'assertIsInstance'): | ||||
return unittest.TestCase.assertIsInstance(self, _value, _type) | return unittest.TestCase.assertIsInstance(self, _value, _type) | ||||
else: | else: | ||||
if (type(_value)) == _type: | if (type(_value)) == _type: | ||||
return True | return True | ||||
else: | else: | ||||
raise AssertionError, "%s != %s" % (type(_value), _type) | raise AssertionError("%s != %s" % (type(_value), _type)) | ||||
def test_001_minimal(self): | def test_001_minimal(self): | ||||
note = Note() | note = Note() | ||||
note.set_summary("test") | note.set_summary("test") | ||||
self.assertEqual(note.summary(), "test") | self.assertEqual(note.summary(), "test") | ||||
self.assertIsInstance(note.__str__(), str) | self.assertIsInstance(note.__str__(), str) | ||||
def test_002_full(self): | def test_002_full(self): | ||||
Show All 32 Lines | def test_012_to_xml(self): | ||||
xml = str(note) | xml = str(note) | ||||
self.assertTrue('<summary/>' in xml) | self.assertTrue('<summary/>' in xml) | ||||
self.assertTrue('<description/>' in xml) | self.assertTrue('<description/>' in xml) | ||||
def test_020_to_dict(self): | def test_020_to_dict(self): | ||||
data = note_from_string(xml_note).to_dict() | data = note_from_string(xml_note).to_dict() | ||||
self.assertIsInstance(data, dict) | self.assertIsInstance(data, dict) | ||||
self.assertTrue(data.has_key('uid')) | self.assertTrue('uid' in data) | ||||
self.assertIsInstance(data.get('created', None), datetime.datetime) | self.assertIsInstance(data.get('created', None), datetime.datetime) | ||||
self.assertIsInstance(data.get('lastmodified-date', None), datetime.datetime) | self.assertIsInstance(data.get('lastmodified-date', None), datetime.datetime) | ||||
self.assertEqual(data.get('summary', None), "Kolab Note") | self.assertEqual(data.get('summary', None), "Kolab Note") | ||||
self.assertEqual(data.get('classification', None), 'PUBLIC') | self.assertEqual(data.get('classification', None), 'PUBLIC') | ||||
self.assertIsInstance(data.get('categories', None), list) | self.assertIsInstance(data.get('categories', None), list) | ||||
self.assertEqual(len(data.get('categories', None)), 2) | self.assertEqual(len(data.get('categories', None)), 2) | ||||
self.assertTrue('<p>This is a HTML note</p>' in data.get('description', None)) | self.assertTrue('<p>This is a HTML note</p>' in data.get('description', None)) | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
unittest.main() | unittest.main() |