def test_copy(self): sd = SafeDict.MsgSafeDict(self._msg, {'foo': 'bar'}) copy = sd.copy() items = list(copy.items()) items.sort() self.assertEqual(items, [ ('allmsg_cc', '[email protected], [email protected]'), ('foo', 'bar'), ('msg_from', 'bar'), ('msg_subject', 'baz'), ('msg_to', 'foo'), ])
def test_allmsg_key(self): sd = SafeDict.MsgSafeDict(self._msg, {'cc': 'value'}) si = '%(allmsg_cc)s' % sd self.assertEqual(si, '[email protected], [email protected]')
def test_allmsg_no_key(self): sd = SafeDict.MsgSafeDict(self._msg) si = '%(allmsg_date)s' % sd self.assertEqual(si, 'n/a')
def test_msg_key(self): sd = SafeDict.MsgSafeDict(self._msg, {'to': 'value'}) si = '%(msg_to)s' % sd self.assertEqual(si, 'foo')
def test_normal_key(self): sd = SafeDict.MsgSafeDict(self._msg, {'key': 'value'}) si = '%(key)s' % sd self.assertEqual(si, 'value')
def test_key_error_not_string(self): key = () sd = SafeDict.SafeDict({}) self.assertEqual(sd[key], '<Missing key: ()>')
def test_key_error(self): sd = SafeDict.SafeDict({'foo': 'bar'}) si = '%(baz)s' % sd self.assertEqual(si, '%(baz)s')
def test_okay(self): sd = SafeDict.SafeDict({'foo': 'bar'}) si = '%(foo)s' % sd self.assertEqual(si, 'bar')