|
12 | 12 | import httpretty |
13 | 13 |
|
14 | 14 | from pycrunchbase import CrunchBase, Relationship |
| 15 | +from pycrunchbase.resource.relationship import NoneRelationship |
15 | 16 |
|
16 | 17 | MOCK_RELATIONSHIP_PAGE = '''{ |
17 | 18 | "paging": { |
@@ -224,58 +225,6 @@ def test_exception_raised_when_making_calls(self): |
224 | 225 | cb = CrunchBase('123') |
225 | 226 | cb.organizations('organization') |
226 | 227 |
|
227 | | - @httpretty.activate |
228 | | - def test_more_relationship_for_relationship_summary(self): |
229 | | - """Load more relationship data from summary""" |
230 | | - data = {'data': json.loads(MOCK_RELATIONSHIP_PAGE)} |
231 | | - httpretty.register_uri( |
232 | | - httpretty.GET, |
233 | | - 'https://api.crunchbase.com/v/2/organization/example/past_team' |
234 | | - '?user_key=123', |
235 | | - body=json.dumps(data)) |
236 | | - |
237 | | - rs = Relationship('past_team', json.loads(PAST_TEAM_RELATIONSHIP)) |
238 | | - cb = CrunchBase('123') |
239 | | - |
240 | | - rs = cb.more(rs) |
241 | | - self.assertIsNotNone(rs) |
242 | | - self.assertEquals(3, len(rs)) |
243 | | - |
244 | | - def test_more_relationship_for_relationship_page1(self): |
245 | | - """At summary page, there is no more next page, so return None""" |
246 | | - past_team = json.loads(PAST_TEAM_RELATIONSHIP) |
247 | | - past_team['paging']['total_items'] = 1 |
248 | | - rs = Relationship('past_team', past_team) |
249 | | - cb = CrunchBase('123') |
250 | | - |
251 | | - self.assertIsNone(cb.more(rs)) |
252 | | - |
253 | | - @httpretty.activate |
254 | | - def test_more_relationship_for_relationship_page2(self): |
255 | | - """At page 1, there is no more next page, so return None""" |
256 | | - return_data = json.loads(MOCK_RELATIONSHIP_PAGE) |
257 | | - return_data['paging']['total_items'] = 6 |
258 | | - return_data['paging']['first_page_url'] = None |
259 | | - return_data['paging']['items_per_page'] = 3 |
260 | | - return_data['paging']['next_page_url'] = ( |
261 | | - 'https://api.crunchbase.com/v/2/organization/example/past_team' |
262 | | - 'user_key=123&page=2') |
263 | | - rs = Relationship('past_team', return_data) |
264 | | - |
265 | | - return_data['paging']['next_page_url'] = None |
266 | | - return_data['paging']['current_page'] = 2 |
267 | | - data = {'data': return_data} |
268 | | - httpretty.register_uri( |
269 | | - httpretty.GET, |
270 | | - 'https://api.crunchbase.com/v/2/organization/example/past_team' |
271 | | - 'user_key=123&page=2', |
272 | | - body=json.dumps(data)) |
273 | | - cb = CrunchBase('123') |
274 | | - rs = cb.more(rs) |
275 | | - |
276 | | - self.assertIsNotNone(rs) |
277 | | - self.assertEqual(2, rs.current_page) |
278 | | - |
279 | 228 | @httpretty.activate |
280 | 229 | def test_get_funding_round_data(self): |
281 | 230 | httpretty.register_uri( |
@@ -359,3 +308,89 @@ def test_get_acquisition_data(self): |
359 | 308 | acquisition = cb.acquisition('uuid1') |
360 | 309 | self.assertEqual(acquisition.disposition_of_acquired, "Combined") |
361 | 310 | self.assertEqual(acquisition.acquisition_type, "Acqui-hire") |
| 311 | + |
| 312 | + |
| 313 | +class LoadMoreTestCase(TestCase): |
| 314 | + def setUp(self): |
| 315 | + self.cb = CrunchBase('123') |
| 316 | + |
| 317 | + def test_more_from_relationship_summary_but_no_more(self): |
| 318 | + """At summary page, there is no more next page, |
| 319 | + because the summary already contains everything, |
| 320 | + i.e. total_items < 8 since CrunchBase defaults to returning |
| 321 | + 8 in the relationship summary, so return NoneRelationship""" |
| 322 | + past_team = json.loads(PAST_TEAM_RELATIONSHIP) |
| 323 | + past_team['paging']['total_items'] = 1 |
| 324 | + rs = Relationship('past_team', past_team) |
| 325 | + |
| 326 | + self.assertIsInstance(self.cb.more(rs), NoneRelationship) |
| 327 | + |
| 328 | + @httpretty.activate |
| 329 | + def test_more_from_relationship_summary_returns_error(self): |
| 330 | + """Load more relationship data from summary""" |
| 331 | + httpretty.register_uri( |
| 332 | + httpretty.GET, |
| 333 | + 'https://api.crunchbase.com/v/2/organization/example/past_team' |
| 334 | + '?user_key=123', |
| 335 | + body=json.dumps({'data': {'error': 'error'}})) |
| 336 | + |
| 337 | + rs = Relationship('past_team', json.loads(PAST_TEAM_RELATIONSHIP)) |
| 338 | + |
| 339 | + rs = self.cb.more(rs) |
| 340 | + self.assertIsInstance(rs, NoneRelationship) |
| 341 | + |
| 342 | + @httpretty.activate |
| 343 | + def test_more_relationship_for_relationship_summary(self): |
| 344 | + """Load more relationship data from summary""" |
| 345 | + data = {'data': json.loads(MOCK_RELATIONSHIP_PAGE)} |
| 346 | + httpretty.register_uri( |
| 347 | + httpretty.GET, |
| 348 | + 'https://api.crunchbase.com/v/2/organization/example/past_team' |
| 349 | + '?user_key=123', |
| 350 | + body=json.dumps(data)) |
| 351 | + |
| 352 | + rs = Relationship('past_team', json.loads(PAST_TEAM_RELATIONSHIP)) |
| 353 | + |
| 354 | + rs = self.cb.more(rs) |
| 355 | + self.assertIsNotNone(rs) |
| 356 | + self.assertEquals(3, len(rs)) |
| 357 | + |
| 358 | + @httpretty.activate |
| 359 | + def test_more_relationship_for_relationship_page2(self): |
| 360 | + """At page 1, there a next_page, get it and return the Relationship""" |
| 361 | + data = { |
| 362 | + "paging": { |
| 363 | + "items_per_page": 8, |
| 364 | + "current_page": 1, |
| 365 | + "number_of_pages": 2, |
| 366 | + "next_page_url": "https://api.crunchbase.com/v/2/" |
| 367 | + "organization/example/past_team?user_key=123&page=2", |
| 368 | + "prev_page_url": None, |
| 369 | + "total_items": 10, |
| 370 | + "sort_order": "custom" |
| 371 | + }, |
| 372 | + "items": [{}, {}, {}, {}, {}, {}, {}, {}] |
| 373 | + } |
| 374 | + rs = Relationship('past_team', data) |
| 375 | + |
| 376 | + httpretty.register_uri( |
| 377 | + httpretty.GET, |
| 378 | + 'https://api.crunchbase.com/v/2/organization/example/past_team' |
| 379 | + '?user_key=123&page=2', |
| 380 | + body=json.dumps({ |
| 381 | + "data": { |
| 382 | + "paging": { |
| 383 | + "items_per_page": 8, |
| 384 | + "current_page": 2, |
| 385 | + "number_of_pages": 2, |
| 386 | + "next_page_url": None, |
| 387 | + "prev_page_url": None, |
| 388 | + "total_items": 10, |
| 389 | + "sort_order": "custom" |
| 390 | + }, |
| 391 | + "items": [{}, {}] |
| 392 | + }})) |
| 393 | + |
| 394 | + more_rs = self.cb.more(rs) |
| 395 | + |
| 396 | + self.assertEqual(2, len(more_rs)) |
0 commit comments