def test_object_response_success(): response_json = _get_resource_json("complete_data.json") r = requests.Response() r.status_code = 200 r.json = MagicMock(return_value=response_json) with patch.object(bkm.delay_request, 'get', return_value=r) as mock_get: actual_data = bkm._get_object_json(endpoint=bkm.ENDPOINT + str(1)) expected_data = response_json["data"] assert mock_get.call_count == 1 assert actual_data == expected_data
def test_get_response_nodata(): param = { "has_images": 1, "rights_type_permissive": 1, "limit": 1, "offset": 70000 } response_json = _get_resource_json("response_nodata.json") r = requests.Response() r.status_code = 200 r.json = MagicMock(return_value=response_json) with patch.object(bkm.delay_request, 'get', return_value=r) as mock_get: actual_data = bkm._get_object_json(query_param=param) assert len(actual_data) == 0 assert mock_get.call_count == 1
def test_get_response_failure(): param = { "has_images": 1, "rights_type_permissive": 1, "limit": -1, "offset": 0 } response_json = _get_resource_json("response_error.json") r = requests.Response() r.status_code = 500 r.json = MagicMock(return_value=response_json) with patch.object(bkm.delay_request, 'get', return_value=r) as mock_get: actual_data = bkm._get_object_json(query_param=param) expected_data = None assert mock_get.call_count == 3 assert actual_data == expected_data