diff --git a/nobel/prizes.py b/nobel/prizes.py index 856f137..894e221 100644 --- a/nobel/prizes.py +++ b/nobel/prizes.py @@ -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' @@ -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 diff --git a/nobel/test/test_nobel.py b/nobel/test/test_nobel.py index 054546b..f81f15f 100644 --- a/nobel/test/test_nobel.py +++ b/nobel/test/test_nobel.py @@ -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)