Skip to content

Commit caccc4b

Browse files
committed
Add DataDict in Range
1 parent 5ae0cb1 commit caccc4b

2 files changed

Lines changed: 13 additions & 9 deletions

File tree

opus/range.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
# -*- coding: utf-8 -*-
22

3-
class Range(object):
3+
from .data import DataDict
4+
5+
class Range(DataDict):
46
def __init__(self, field, json):
5-
self.max = float(json['max'])
6-
self.min = float(json['min'])
7-
self.nulls = int(json['nulls'])
7+
DataDict.__init__(self)
88
self._field = field
9+
self.append('min', float(json['min']))
10+
self.append('max', float(json['max']))
11+
self.append('null', int(json['nulls']))
912

1013
def __repr__(self):
11-
return 'OPUS API Range endpoints for field: {}'.format(self._field)
14+
return 'OPUS API Range endpoints for field: `{}`\n'.format(self._field) + \
15+
'\n'.join(' - {} : {}'.format(key, value) for key, value in self.items())

tests/test_api.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,10 @@ def test_api_range(api):
275275
assert responses.calls[0].request.url == 'http://localhost/meta/range/endpoints/ringradius1.json?target=Saturn'
276276
assert responses.calls[0].response.text == range_endpoints
277277

278-
assert repr(resp) == 'OPUS API Range endpoints for field: ringradius1'
279-
assert resp.min == 60000
280-
assert resp.max == 1.29e+07
281-
assert resp.nulls == 115573
278+
assert 'OPUS API Range endpoints for field: `ringradius1`' in repr(resp)
279+
assert resp['min'] == 60000
280+
assert resp['max'] == 1.29e+07
281+
assert resp['null'] == 115573
282282

283283

284284
@responses.activate

0 commit comments

Comments
 (0)