Skip to content

Commit dcafcf7

Browse files
committed
test(): templatetags test
1 parent ce43577 commit dcafcf7

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

simple_history/templatetags/getattributes.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
def getattribute(value, arg):
77
"""Gets an attribute of an object dynamically from a string name"""
88

9-
if hasattr(value, str(arg)):
10-
return getattr(value, arg)
9+
return getattr(value, arg, None)
1110

1211
register.filter('getattribute', getattribute)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from simple_history.templatetags.getattributes import getattribute
2+
3+
from django.test import TestCase
4+
5+
6+
class Foo(object):
7+
bar = "bar"
8+
9+
10+
class TestGetAttributes(TestCase):
11+
12+
def test_get_existing_attributes_return_it(self):
13+
self.assertEqual(getattribute(Foo(), 'bar'), 'bar')
14+
15+
def test_get_missing_attributes_return_None(self):
16+
self.assertIsNone(getattribute(Foo(), 'baz'))

0 commit comments

Comments
 (0)