def test_getThing_with_next(self): from collective.flattr.browser.flattr import Flattr mocker = Mocker() view = Flattr(self.portal, self.layer['request']) obj = mocker.patch(view) obj.opener mocker.result(MockOpener('[ { "type": "thing", "resource": "https://api.flattr.dev/rest/v2/things/1", "link": "https://flattr.dev/thing/1", "id": 1 }, { "type": "thing", "resource": "https://api.flattr.dev/rest/v2/things/2", "link": "https://flattr.dev/thing/2", "id": 2} ]', verify_data=lambda x: 'count=30&page=' in x.get_data())) mocker.count(2) # if the same thing is called twice, it is called for the first page # and again for the second page. So there is a result, what means that # there is a next page with mocker: ret = view.getThings() self.failUnless(u'data' in ret) self.failUnless(u'next_page' in ret) self.assertTrue(ret['next_page']) self.assertEquals(ret['data'][0], { "type": "thing", "resource": "https://api.flattr.dev/rest/v2/things/1", "link": "https://flattr.dev/thing/1", "id": 1 }) self.assertEquals(ret['data'][1], { "type": "thing", "resource": "https://api.flattr.dev/rest/v2/things/2", "link": "https://flattr.dev/thing/2", "id": 2})
def test_getThing(self): from collective.flattr.browser.flattr import Flattr mocker = Mocker() view = Flattr(self.portal, self.layer['request']) def test_func(x): return 'count=30&page=' in x.get_data() obj = mocker.patch(view) obj.opener mocker.result(MockOpener('[ { "type": "thing", "resource": "https://api.flattr.dev/rest/v2/things/1", "link": "https://flattr.dev/thing/1", "id": 1 }, { "type": "thing", "resource": "https://api.flattr.dev/rest/v2/things/2", "link": "https://flattr.dev/thing/2", "id": 2} ]', verify_data=test_func)) obj.opener mocker.result(MockOpener('', verify_data=test_func, error=True)) with mocker: ret = view.getThings() self.failUnless(u'data' in ret) self.failUnless(u'next_page' in ret) self.assertFalse(ret['next_page']) self.assertEquals(ret['data'][0], { "type": "thing", "resource": "https://api.flattr.dev/rest/v2/things/1", "link": "https://flattr.dev/thing/1", "id": 1 }) self.assertEquals(ret['data'][1], { "type": "thing", "resource": "https://api.flattr.dev/rest/v2/things/2", "link": "https://flattr.dev/thing/2", "id": 2})