From: Tomas Babej Date: Sat, 3 Jan 2015 11:16:49 +0000 (+0100) Subject: Tests: Cover setting read only attributes X-Git-Url: https://git.madduck.net/etc/taskwarrior.git/commitdiff_plain/39ac0a190486d08dcba1c3301581e8129a2fca26?ds=inline;hp=-c Tests: Cover setting read only attributes --- 39ac0a190486d08dcba1c3301581e8129a2fca26 diff --git a/tasklib/tests.py b/tasklib/tests.py index 72aebb9..4548df9 100644 --- a/tasklib/tests.py +++ b/tasklib/tests.py @@ -371,6 +371,21 @@ class TaskTest(TasklibTest): t['depends'] = set([dependency]) self.assertEqual(set(t._modified_fields), set()) + def test_setting_read_only_attrs_through_init(self): + # Test that we are unable to set readonly attrs through __init__ + for readonly_key in Task.read_only_fields: + kwargs = {'description': 'test task', readonly_key: 'value'} + self.assertRaises(RuntimeError, + lambda: Task(self.tw, **kwargs)) + + def test_setting_read_only_attrs_through_setitem(self): + # Test that we are unable to set readonly attrs through __init__ + for readonly_key in Task.read_only_fields: + t = Task(self.tw, description='test task') + self.assertRaises(RuntimeError, + lambda: t.__setitem__(readonly_key, 'value')) + + class AnnotationTest(TasklibTest): def setUp(self):