Skip to content

Commit

Permalink
Add motivation attribute to Prize objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
vibragiel committed Sep 13, 2013
1 parent 052a309 commit 6ae5d15
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion nobel/prizes.py
Expand Up @@ -7,7 +7,7 @@
class Prize(NobelObject):
"""Nobel Prize."""

attributes = ('category', 'year', 'laureates')
attributes = ('category', 'year', 'laureates', 'motivation')
unique_together = ('category', 'year',)
resource = 'prize'
resource_plural = 'prizes'
Expand All @@ -19,6 +19,8 @@ def _parse(cls, data, full=False):
if 'laureates' in data:
obj.laureates = [cls.api.laureates._parse(l, full=False)
for l in data['laureates']]
if 'motivation' in data['laureates'][0]:
obj.motivation = data['laureates'][0]['motivation']

return obj

Expand Down
16 changes: 16 additions & 0 deletions nobel/test/test_nobel.py
Expand Up @@ -335,6 +335,22 @@ def test_parse(self, mocked_parse):
assert mocked_parse.call_count == 2
assert obj.laureates == ['laureate object', 'laureate object']

@mock.patch('nobel.laureates.Laureate._parse')
def test_parse_motivation_in_laureate(self, mocked_parse):
mocked_parse.return_value = 'laureate object'
data = {u'category': u'physics', u'year': u'2006',
u'laureates': [{u'id': 1, u'motivation': u'because'}]}
obj = self.api.prizes._parse(data)
assert obj.motivation == u'because'

@mock.patch('nobel.laureates.Laureate._parse')
def test_parse_motivation_in_prize(self, mocked_parse):
mocked_parse.return_value = 'laureate object'
data = {u'category': u'physics', u'year': u'2006',
u'motivation': u'because'}
obj = self.api.prizes._parse(data)
assert obj.motivation == u'because'

def test_unicode(self):
data = {u'category': u'physics', u'year': u'2006'}
obj = self.api.prizes._parse(data)
Expand Down

0 comments on commit 6ae5d15

Please sign in to comment.