Changeset View
Changeset View
Standalone View
Standalone View
tests/unit/test-019-contact.py
Show First 20 Lines • Show All 274 Lines • ▼ Show 20 Lines | <email> | ||||
<text>user.one@example.org</text> | <text>user.one@example.org</text> | ||||
</email> | </email> | ||||
</vcard> | </vcard> | ||||
</vcards> | </vcards> | ||||
--=_4ff5155d75dc1328b7f5fe10ddce8d24-- | --=_4ff5155d75dc1328b7f5fe10ddce8d24-- | ||||
""" | """ | ||||
class TestContactXML(unittest.TestCase): | class TestContactXML(unittest.TestCase): | ||||
contact = Contact() | contact = Contact() | ||||
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): | ||||
self.contact.set_name("test") | self.contact.set_name("test") | ||||
self.assertEqual("test", self.contact.name()) | self.assertEqual("test", self.contact.name()) | ||||
self.assertIsInstance(self.contact.__str__(), str) | self.assertIsInstance(self.contact.__str__(), str) | ||||
def test_002_full(self): | def test_002_full(self): | ||||
self.contact.set_name("test") | self.contact.set_name("test") | ||||
# TODO: add more setters and getter tests here | # TODO: add more setters and getter tests here | ||||
def test_010_load_from_xml(self): | def test_010_load_from_xml(self): | ||||
contact = contact_from_string(xml_contact) | contact = contact_from_string(xml_contact) | ||||
self.assertEqual(contact.get_uid(), '437656b2-d55e-11e4-a43b-080027b7afc5') | self.assertEqual(contact.get_uid(), '437656b2-d55e-11e4-a43b-080027b7afc5') | ||||
Lint: PEP8 E501: line too long (83 > 79 characters) | |||||
self.assertEqual(contact.name(), 'Sample Dude') | self.assertEqual(contact.name(), 'Sample Dude') | ||||
def test_011_load_from_message(self): | def test_011_load_from_message(self): | ||||
contact = contact_from_message(message_from_string(contact_mime_message)) | contact = contact_from_message(message_from_string(contact_mime_message)) | ||||
Lint: PEP8 E501 line too long (81 > 79 characters) Lint: PEP8 E501: line too long (81 > 79 characters) | |||||
self.assertEqual(contact.get_uid(), '05cfc56d-2bb3-46d1-ada4-5f5310337fb2') | self.assertEqual(contact.get_uid(), '05cfc56d-2bb3-46d1-ada4-5f5310337fb2') | ||||
Lint: PEP8 E501 line too long (83 > 79 characters) Lint: PEP8 E501: line too long (83 > 79 characters) | |||||
self.assertEqual(contact.name(), 'User One') | self.assertEqual(contact.name(), 'User One') | ||||
def test_020_to_dict(self): | def test_020_to_dict(self): | ||||
data = contact_from_string(xml_contact).to_dict() | data = contact_from_string(xml_contact).to_dict() | ||||
self.assertIsInstance(data, dict) | self.assertIsInstance(data, dict) | ||||
self.assertIsInstance(data['lastmodified-date'], datetime.datetime) | self.assertIsInstance(data['lastmodified-date'], datetime.datetime) | ||||
self.assertEqual(data['uid'], '437656b2-d55e-11e4-a43b-080027b7afc5') | self.assertEqual(data['uid'], '437656b2-d55e-11e4-a43b-080027b7afc5') | ||||
Show All 21 Lines | def test_020_to_dict(self): | ||||
self.assertEqual(data['email'][0]['type'], 'home') | self.assertEqual(data['email'][0]['type'], 'home') | ||||
self.assertEqual(data['email'][0]['address'], 'home@kolab.org') | self.assertEqual(data['email'][0]['address'], 'home@kolab.org') | ||||
self.assertEqual(len(data['url']), 1) | self.assertEqual(len(data['url']), 1) | ||||
self.assertEqual(len(data['key']), 1) | self.assertEqual(len(data['key']), 1) | ||||
self.assertEqual(data['key'][0]['type'], 'pgp') | self.assertEqual(data['key'][0]['type'], 'pgp') | ||||
self.assertIsInstance(data['photo'], dict) | self.assertIsInstance(data['photo'], dict) | ||||
self.assertEqual(data['photo']['mimetype'], 'image/gif') | self.assertEqual(data['photo']['mimetype'], 'image/gif') | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
unittest.main() | unittest.main() | ||||
No newline at end of file |
line too long (83 > 79 characters)