def test_no_data_path(self): result = {} func = Mock() with pytest.raises(Exception) as excinfo: _paginate_dict(result, func, alc_marker_path=[]) ex_str = "alc_data_path must be specified for queries " \ "that return a dict." assert ex_str in str(excinfo)
def test_bad_path(self): result = { 'k1': { 'badpath': {} } } func = Mock() with patch('%s.invoke_with_throttling_retries' % pbm) as mock_invoke: res = _paginate_dict( result, func, alc_marker_path=['k1', 'k2', 'Marker'], alc_data_path=['k1', 'k2', 'Data'], alc_marker_param='Marker' ) assert res == result assert mock_invoke.mock_calls == []
def test_two_iterations(self): e1 = Mock() e2 = Mock() e3 = Mock() e4 = Mock() e5 = Mock() e6 = Mock() func = Mock() res1 = { 'k1': { 'k2': { 'Data': [e1, e2], 'Foo1': 'bar1', 'Marker': 'marker1' } } } res2 = { 'k1': { 'k2': { 'Data': [e3, e4], 'Foo2': 'bar2', 'Marker': 'marker2' } } } res3 = { 'k1': { 'k2': { 'Data': [e5, e6], 'Foo3': 'bar3' } } } expected = { 'k1': { 'k2': { 'Data': [e1, e2, e3, e4, e5, e6], 'Foo3': 'bar3' } } } def se_invoke(self, func, *args, **kwargs): if 'MarkerParam' not in kwargs: return -1 if kwargs['MarkerParam'] == 'marker1': return res2 if kwargs['MarkerParam'] == 'marker2': return res3 return kwargs['MarkerParam'] with patch('%s.invoke_with_throttling_retries' % pbm) as mock_invoke: mock_invoke.side_effect = se_invoke res = _paginate_dict( res1, func, 'foo', alc_marker_path=['k1', 'k2', 'Marker'], alc_data_path=['k1', 'k2', 'Data'], alc_marker_param='MarkerParam' ) assert res == expected assert mock_invoke.mock_calls == [ call( func, 'foo', alc_marker_path=['k1', 'k2', 'Marker'], alc_data_path=['k1', 'k2', 'Data'], alc_marker_param='MarkerParam', MarkerParam='marker1' ), call( func, 'foo', alc_marker_path=['k1', 'k2', 'Marker'], alc_data_path=['k1', 'k2', 'Data'], alc_marker_param='MarkerParam', MarkerParam='marker2' ) ]