From 39ac0a190486d08dcba1c3301581e8129a2fca26 Mon Sep 17 00:00:00 2001 From: Tomas Babej Date: Sat, 3 Jan 2015 12:16:49 +0100 Subject: [PATCH] Tests: Cover setting read only attributes --- tasklib/tests.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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): -- 2.39.5