Changeset View
Changeset View
Standalone View
Standalone View
tests/unit/test-018-note.py
Show All 11 Lines | <note xmlns="http://kolab.org" version="3.0"> | ||||
<uid>d407f007-cb52-42cb-8e06-67f6132d718f</uid> | <uid>d407f007-cb52-42cb-8e06-67f6132d718f</uid> | ||||
<prodid>Roundcube-libkolab-1.1 Libkolabxml-1.1</prodid> | <prodid>Roundcube-libkolab-1.1 Libkolabxml-1.1</prodid> | ||||
<creation-date>2015-03-26T08:12:37Z</creation-date> | <creation-date>2015-03-26T08:12:37Z</creation-date> | ||||
<last-modification-date>2015-03-26T08:12:37Z</last-modification-date> | <last-modification-date>2015-03-26T08:12:37Z</last-modification-date> | ||||
<categories>One</categories> | <categories>One</categories> | ||||
<categories>Two</categories> | <categories>Two</categories> | ||||
<classification>PUBLIC</classification> | <classification>PUBLIC</classification> | ||||
<summary>Kolab Note</summary> | <summary>Kolab Note</summary> | ||||
<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"> | ||||
Lint: PEP8 E501: line too long (115 > 79 characters) | |||||
<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> | ||||
Lint: PEP8 E501 line too long (132 > 79 characters) Lint: PEP8 E501: line too long (132 > 79 characters) | |||||
<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): | ||||
note = Note() | note = Note() | ||||
note.set_summary("test") | note.set_summary("test") | ||||
note.set_description("Description") | note.set_description("Description") | ||||
note.set_classification("CONFIDENTIAL") | note.set_classification("CONFIDENTIAL") | ||||
note.add_category("Foo") | note.add_category("Foo") | ||||
note.add_category("Bar") | note.add_category("Bar") | ||||
# print str(note) | # print str(note) | ||||
self.assertEqual(len(note.get_uid()), 36) | self.assertEqual(len(note.get_uid()), 36) | ||||
self.assertEqual(note.summary(), "test") | self.assertEqual(note.summary(), "test") | ||||
self.assertEqual(note.description(), "Description") | self.assertEqual(note.description(), "Description") | ||||
self.assertEqual(note.get_classification(), "CONFIDENTIAL") | self.assertEqual(note.get_classification(), "CONFIDENTIAL") | ||||
self.assertEqual(note.get_classification(False), kolabformat.ClassConfidential) | self.assertEqual(note.get_classification(False), kolabformat.ClassConfidential) | ||||
Lint: PEP8 E501 line too long (87 > 79 characters) Lint: PEP8 E501: line too long (87 > 79 characters) | |||||
self.assertEqual(len(note.categories()), 2) | self.assertEqual(len(note.categories()), 2) | ||||
def test_010_load_from_xml(self): | def test_010_load_from_xml(self): | ||||
note = note_from_string(xml_note) | note = note_from_string(xml_note) | ||||
self.assertEqual(note.get_uid(), "d407f007-cb52-42cb-8e06-67f6132d718f") | self.assertEqual(note.get_uid(), "d407f007-cb52-42cb-8e06-67f6132d718f") | ||||
Lint: PEP8 E501 line too long (80 > 79 characters) Lint: PEP8 E501: line too long (80 > 79 characters) | |||||
self.assertEqual(note.summary(), "Kolab Note") | self.assertEqual(note.summary(), "Kolab Note") | ||||
self.assertIsInstance(note.get_created(), datetime.datetime) | self.assertIsInstance(note.get_created(), datetime.datetime) | ||||
self.assertEqual(note.get_created().tzinfo, pytz.utc) | self.assertEqual(note.get_created().tzinfo, pytz.utc) | ||||
self.assertIsInstance(note.get_lastmodified(), datetime.datetime) | self.assertIsInstance(note.get_lastmodified(), datetime.datetime) | ||||
self.assertEqual(note.get_lastmodified().tzinfo, pytz.utc) | self.assertEqual(note.get_lastmodified().tzinfo, pytz.utc) | ||||
def test_011_to_xml(self): | def test_011_to_xml(self): | ||||
note = Note() | note = Note() | ||||
with self.assertRaises(ValueError): | with self.assertRaises(ValueError): | ||||
note.set_classification(-1) | note.set_classification(-1) | ||||
def test_012_to_xml(self): | def test_012_to_xml(self): | ||||
# minimal | # minimal | ||||
note = Note() | note = Note() | ||||
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) | ||||
Lint: PEP8 E501 line too long (85 > 79 characters) Lint: PEP8 E501: line too long (85 > 79 characters) | |||||
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)) | ||||
Lint: PEP8 E501 line too long (86 > 79 characters) Lint: PEP8 E501: line too long (86 > 79 characters) | |||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
unittest.main() | unittest.main() |
line too long (115 > 79 characters)