diff --git a/README.md b/README.md index a26d34c..15d3e2a 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,8 @@ GET /api/resources/find-resources-in-batch?id=riscv-ubuntu-20.04-boot&resource_v - Each `id` parameter must have a corresponding `resource_version` parameter - Use `resource_version=None` to retrieve all versions of a resource -- Returns 404 if any requested resource is missing +- Returns a list of resources that were found even if not all requested resources were found. +- Returns an empty list is no resources were found. ### 2. Advanced Resource Search diff --git a/functions/get_resources_by_batch.py b/functions/get_resources_by_batch.py index 4a8d6d0..1d622eb 100644 --- a/functions/get_resources_by_batch.py +++ b/functions/get_resources_by_batch.py @@ -80,23 +80,6 @@ def find_resources_in_batch(req: func.HttpRequest) -> func.HttpResponse: collection.find({"$or": queries}, RESOURCE_FIELDS) ) - # Check if any resources were found - if not resources: - return create_error_response( - 404, "No requested resources were found" - ) - - # Check if at least one instance of each requested ID is present - found_ids = {resource.get("id") for resource in resources} - missing_ids = set(ids) - found_ids - - if missing_ids: - return create_error_response( - 404, - "The following requested resources were not found: " - f"{', '.join(missing_ids)}", - ) - return func.HttpResponse( body=json.dumps(resources), status_code=200, diff --git a/tests/resources_api_unit_tests.py b/tests/resources_api_unit_tests.py index 168d504..de8c27d 100644 --- a/tests/resources_api_unit_tests.py +++ b/tests/resources_api_unit_tests.py @@ -107,10 +107,14 @@ def test_get_resources_by_batch_not_found_partial(self): f"{self.base_url}/resources/find-resources-in-batch?{query_string}" ) response = requests.get(url) - self.assertEqual(response.status_code, 404) + self.assertEqual(response.status_code, 200) data = response.json() - self.assertIn("error", data) - self.assertIn("non-existent", data["error"]) + self.assertIsInstance(data, list) + self.assertEqual(len(data), 1) + + found_ids = [r["id"] for r in data] + self.assertEqual(len(found_ids), 1) + self.assertEqual("arm-hello64-static", found_ids[0]) def test_get_resources_by_batch_not_found_all(self): """Test batch retrieval where all resources are missing.""" @@ -128,7 +132,10 @@ def test_get_resources_by_batch_not_found_all(self): f"{self.base_url}/resources/find-resources-in-batch?{query_string}" ) response = requests.get(url) - self.assertEqual(response.status_code, 404) + self.assertEqual(response.status_code, 200) + data = response.json() + self.assertIsInstance(data, list) + self.assertEqual(len(data), 0) def test_get_resources_by_batch_mismatched_parameters(self): """Test batch retrieval with mismatched number of id and version @@ -173,10 +180,14 @@ def test_get_resources_by_batch_valid_id_invalid_version(self): f"{self.base_url}/resources/find-resources-in-batch?{query_string}" ) response = requests.get(url) - self.assertEqual(response.status_code, 404) + self.assertEqual(response.status_code, 200) data = response.json() - self.assertIn("error", data) - self.assertIn("riscv-ubuntu-20.04-boot", data["error"]) + self.assertIsInstance(data, list) + self.assertEqual(len(data), 1) + + found_ids = [r["id"] for r in data] + self.assertEqual(len(found_ids), 1) + self.assertEqual("arm-hello64-static", found_ids[0]) # FILTER ENDPOINT TESTS def test_get_filters(self):