Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_response(limit, marker):
mock_box_response = Mock(BoxResponse)
mock_network_response = Mock(DefaultNetworkResponse)
mock_box_response.network_response = mock_network_response
mock_json = {}
# The marker string should be of format: "marker_i", where i is the offset. Parse that out.
# If the marker is None, then begin paging from the start of the entries.
offset = 0
if marker is not None:
offset = int(marker.split('_')[1])
mock_json['entries'] = entries[offset:limit + offset]
# A next_marker is only returned if there are more pages left.
if (offset + limit) < len(entries):
mock_json['next_marker'] = 'marker_{0}'.format(offset + limit)
elif next_marker_value_for_last_page is not self.NO_NEXT_MARKER:
mock_json['next_marker'] = next_marker_value_for_last_page
def empty_events_response(final_stream_position):
# pylint:disable=redefined-outer-name
mock_box_response = Mock(BoxResponse)
mock_network_response = Mock(DefaultNetworkResponse)
mock_box_response.network_response = mock_network_response
mock_box_response.json.return_value = mock_json = {'next_stream_position': final_stream_position, 'entries': []}
mock_box_response.content = json.dumps(mock_json).encode()
mock_box_response.status_code = 200
mock_box_response.ok = True
return mock_box_response
def get_response(limit, offset):
mock_box_response = Mock(BoxResponse)
mock_network_response = Mock(DefaultNetworkResponse)
mock_box_response.network_response = mock_network_response
mock_box_response.json.return_value = mock_json = {
'entries': entries[offset:limit + offset],
'total_count': len(entries),
'limit': limit,
}
mock_box_response.content = json.dumps(mock_json).encode()
mock_box_response.status_code = 200
mock_box_response.ok = True
return mock_box_response
return get_response
def get_response(limit, offset):
items_json, items = mock_items
entries = items_json[offset:limit + offset]
mock_box_response = Mock(BoxResponse)
mock_network_response = Mock(DefaultNetworkResponse)
mock_box_response.network_response = mock_network_response
mock_box_response.json.return_value = mock_json = {
'entries': entries,
'total_count': len(entries),
'limit': limit,
'offset': offset,
}
mock_box_response.content = json.dumps(mock_json).encode()
mock_box_response.status_code = 200
mock_box_response.ok = True
return mock_box_response, items[offset:limit + offset]
return get_response
def box_response_constructor(self):
"""Get the constructor for the container class representing an API response"""
return _BoxResponse