Skip to content

Commit e28211d

Browse files
committed
Change API limit default call
1 parent ee7ad5b commit e28211d

2 files changed

Lines changed: 62 additions & 58 deletions

File tree

opus/api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def count(self, **kwargs):
6363
res = self.load('meta/result_count', **kwargs)
6464
return int(res['data'][0]['result_count'])
6565

66-
def data(self, limit=None, page=1, **kwargs):
66+
def data(self, limit=100, page=1, **kwargs):
6767
'''Get data for a search'''
6868
if limit is None:
6969
kwargs['limit'] = self.count(**kwargs)
@@ -76,7 +76,7 @@ def metadata(self, ring_obs_id):
7676
'''Get detail for a single observation'''
7777
return Metadata(self.load('metadata/'+ring_obs_id))
7878

79-
def images(self, size='med', limit=None, page=1, **kwargs):
79+
def images(self, size='med', limit=100, page=1, **kwargs):
8080
'''Get image results for a search'''
8181
size = size.lower()
8282
if size not in ['thumb', 'small', 'med', 'full']:
@@ -105,7 +105,7 @@ def file(self, ring_obs_id):
105105
json = self.load('files/'+ring_obs_id)
106106
return File(ring_obs_id, json['data'][ring_obs_id])
107107

108-
def files(self, limit=None, page=1, **kwargs):
108+
def files(self, limit=100, page=1, **kwargs):
109109
'''Get all files results for a search'''
110110
if limit is None:
111111
kwargs['limit'] = self.count(**kwargs)

tests/test_api.py

Lines changed: 59 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -67,50 +67,51 @@ def test_api_count(api):
6767

6868
assert resp == 1591
6969

70+
7071
@responses.activate
7172
def test_api_data(api):
72-
result_count = open('tests/api/meta/result_count.json', 'r').read()
73-
responses.add(responses.GET,
74-
'http://localhost/meta/result_count.json',
75-
body=result_count)
76-
77-
data = open('tests/api/data_all.json', 'r').read()
73+
data = open('tests/api/data.json', 'r').read()
7874
responses.add(responses.GET,
7975
'http://localhost/data.json',
8076
body=data)
8177

82-
resp = api.data(planet='Saturn', target='pan')
78+
resp = api.data(limit=10, page=2, planet='Saturn', target='pan')
8379

84-
assert len(responses.calls) == 2
80+
assert len(responses.calls) == 1
8581
if six.PY3:
86-
assert responses.calls[0].request.url == 'http://localhost/meta/result_count.json?planet=Saturn&target=pan'
87-
assert responses.calls[1].request.url == 'http://localhost/data.json?planet=Saturn&target=pan&limit=1591'
82+
assert responses.calls[0].request.url == 'http://localhost/data.json?planet=Saturn&target=pan&limit=10&page=2'
8883
else:
89-
assert 'limit=1591' in responses.calls[1].request.url
90-
assert responses.calls[1].response.text == data
84+
assert 'limit=10' in responses.calls[0].request.url
85+
assert 'page=2' in responses.calls[0].request.url
86+
87+
assert responses.calls[0].response.text == data
9188

92-
assert len(resp) == 1591
89+
assert len(resp) == 10
9390

9491

9592
@responses.activate
96-
def test_api_data_limit(api):
97-
data = open('tests/api/data.json', 'r').read()
93+
def test_api_data_limit_none(api):
94+
result_count = open('tests/api/meta/result_count.json', 'r').read()
95+
responses.add(responses.GET,
96+
'http://localhost/meta/result_count.json',
97+
body=result_count)
98+
99+
data = open('tests/api/data_all.json', 'r').read()
98100
responses.add(responses.GET,
99101
'http://localhost/data.json',
100102
body=data)
101103

102-
resp = api.data(limit=10, page=2, planet='Saturn', target='pan')
104+
resp = api.data(planet='Saturn', target='pan', limit=None)
103105

104-
assert len(responses.calls) == 1
106+
assert len(responses.calls) == 2
105107
if six.PY3:
106-
assert responses.calls[0].request.url == 'http://localhost/data.json?planet=Saturn&target=pan&limit=10&page=2'
108+
assert responses.calls[0].request.url == 'http://localhost/meta/result_count.json?planet=Saturn&target=pan'
109+
assert responses.calls[1].request.url == 'http://localhost/data.json?planet=Saturn&target=pan&limit=1591'
107110
else:
108-
assert 'limit=10' in responses.calls[0].request.url
109-
assert 'page=2' in responses.calls[0].request.url
110-
111-
assert responses.calls[0].response.text == data
111+
assert 'limit=1591' in responses.calls[1].request.url
112+
assert responses.calls[1].response.text == data
112113

113-
assert len(resp) == 10
114+
assert len(resp) == 1591
114115

115116
@responses.activate
116117
def test_api_metadata(api):
@@ -129,39 +130,41 @@ def test_api_metadata(api):
129130

130131
@responses.activate
131132
def test_api_images(api):
132-
result_count = open('tests/api/meta/result_count.json', 'r').read()
133-
responses.add(responses.GET,
134-
'http://localhost/meta/result_count.json',
135-
body=result_count)
136-
137133
images = open('tests/api/images/med.json', 'r').read()
138134
responses.add(responses.GET,
139135
'http://localhost/images/med.json',
140136
body=images)
141137

142-
resp = api.images(size='med', planet='Saturn', target='pan')
138+
resp = api.images(size='med', limit=10, page=2, planet='Saturn', target='pan')
143139

144-
assert len(responses.calls) == 2
140+
assert len(responses.calls) == 1
145141
if six.PY3:
146-
assert responses.calls[0].request.url == 'http://localhost/meta/result_count.json?planet=Saturn&target=pan'
147-
assert responses.calls[1].request.url == 'http://localhost/images/med.json?planet=Saturn&target=pan&limit=1591'
148-
assert responses.calls[1].response.text == images
142+
assert responses.calls[0].request.url == 'http://localhost/images/med.json?planet=Saturn&target=pan&limit=10&page=2'
143+
assert responses.calls[0].response.text == images
144+
145+
assert len(resp) == 10
146+
149147

150148
@responses.activate
151-
def test_api_images_limit(api):
149+
def test_api_images_limit_none(api):
150+
result_count = open('tests/api/meta/result_count.json', 'r').read()
151+
responses.add(responses.GET,
152+
'http://localhost/meta/result_count.json',
153+
body=result_count)
154+
152155
images = open('tests/api/images/med.json', 'r').read()
153156
responses.add(responses.GET,
154157
'http://localhost/images/med.json',
155158
body=images)
156159

157-
resp = api.images(size='med', limit=10, page=2, planet='Saturn', target='pan')
160+
resp = api.images(size='med', planet='Saturn', target='pan', limit=None)
158161

159-
assert len(responses.calls) == 1
162+
assert len(responses.calls) == 2
160163
if six.PY3:
161-
assert responses.calls[0].request.url == 'http://localhost/images/med.json?planet=Saturn&target=pan&limit=10&page=2'
162-
assert responses.calls[0].response.text == images
164+
assert responses.calls[0].request.url == 'http://localhost/meta/result_count.json?planet=Saturn&target=pan'
165+
assert responses.calls[1].request.url == 'http://localhost/images/med.json?planet=Saturn&target=pan&limit=1591'
166+
assert responses.calls[1].response.text == images
163167

164-
assert len(resp) == 10
165168

166169
@responses.activate
167170
def test_api_image(api):
@@ -208,40 +211,41 @@ def test_api_file(api):
208211

209212
@responses.activate
210213
def test_api_files(api):
211-
result_count = open('tests/api/meta/result_count.json', 'r').read()
212-
responses.add(responses.GET,
213-
'http://localhost/meta/result_count.json',
214-
body=result_count)
215-
216214
files = open('tests/api/files.json', 'r').read()
217215
responses.add(responses.GET,
218216
'http://localhost/files.json',
219217
body=files)
220218

221-
resp = api.files(planet='Saturn', target='pan')
219+
resp = api.files(limit=10, page=2, planet='Saturn', target='pan')
222220

223-
assert len(responses.calls) == 2
221+
assert len(responses.calls) == 1
224222
if six.PY3:
225-
assert responses.calls[0].request.url == 'http://localhost/meta/result_count.json?planet=Saturn&target=pan'
226-
assert responses.calls[1].request.url == 'http://localhost/files.json?planet=Saturn&target=pan&limit=1591'
227-
assert responses.calls[1].response.text == files
223+
assert responses.calls[0].request.url == 'http://localhost/files.json?planet=Saturn&target=pan&limit=10&page=2'
224+
assert responses.calls[0].response.text == files
225+
226+
assert len(resp) == 10
228227

229228

230229
@responses.activate
231-
def test_api_files_limit(api):
230+
def test_api_files_limit_none(api):
231+
result_count = open('tests/api/meta/result_count.json', 'r').read()
232+
responses.add(responses.GET,
233+
'http://localhost/meta/result_count.json',
234+
body=result_count)
235+
232236
files = open('tests/api/files.json', 'r').read()
233237
responses.add(responses.GET,
234238
'http://localhost/files.json',
235239
body=files)
236240

237-
resp = api.files(limit=10, page=2, planet='Saturn', target='pan')
241+
resp = api.files(planet='Saturn', target='pan', limit=None)
238242

239-
assert len(responses.calls) == 1
243+
assert len(responses.calls) == 2
240244
if six.PY3:
241-
assert responses.calls[0].request.url == 'http://localhost/files.json?planet=Saturn&target=pan&limit=10&page=2'
242-
assert responses.calls[0].response.text == files
245+
assert responses.calls[0].request.url == 'http://localhost/meta/result_count.json?planet=Saturn&target=pan'
246+
assert responses.calls[1].request.url == 'http://localhost/files.json?planet=Saturn&target=pan&limit=1591'
247+
assert responses.calls[1].response.text == files
243248

244-
assert len(resp) == 10
245249

246250
@responses.activate
247251
def test_api_mults(api):

0 commit comments

Comments
 (0)