def test_relationinfo_local(self):
r = context.RelationInfo('rel:10', hookenv.local_unit())
# Updates work, with standard strings.
r[sentinel.key] = 'value'
hookenv.relation_set.assert_called_once_with(
'rel:10', {sentinel.key: 'value'})
# Python 2 unicode strings work too.
hookenv.relation_set.reset_mock()
r[sentinel.key] = six.u('value')
hookenv.relation_set.assert_called_once_with(
'rel:10', {sentinel.key: six.u('value')})
# Byte strings fail under Python 3.
if six.PY3:
with self.assertRaises(ValueError):
r[sentinel.key] = six.b('value')
# Deletes work
del r[sentinel.key]
hookenv.relation_set.assert_called_with('rel:10', {sentinel.key: None})
# Attempting to write a non-string fails
with self.assertRaises(ValueError):
r[sentinel.key] = 42
评论列表
文章目录