From b1bbe6423b6d95a588a7563e82f5c9c246fbb929 Mon Sep 17 00:00:00 2001 From: Jon Stroop Date: Sat, 1 Mar 2025 22:44:04 -0500 Subject: [PATCH 1/2] add CI badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7aab7d4..7d92c7e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # Fitbit Client -[![CI](https://github.com/jpstroop/fitbit-client/actions/workflows/ci.yml/badge.svg)](https://github.com/jpstroop/fitbit-client/actions/workflows/ci.yml) +[![CI](https://github.com/jpstroop/fitbit-client-python/actions/workflows/ci.yml/badge.svg)](https://github.com/jpstroop/fitbit-client-python/actions/workflows/ci.yml) [![codecov](https://codecov.io/gh/jpstroop/fitbit-client-python/graph/badge.svg?token=DM0JD8VKZ4)](https://codecov.io/gh/jpstroop/fitbit-client-python) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) [![Python 3.13+](https://img.shields.io/badge/python-3.13+-blue.svg)](https://www.python.org/downloads/release/python-3130/) From 5b7bf2a325d1a2919beb47a37e2515cdbc8a0c38 Mon Sep 17 00:00:00 2001 From: Jon Stroop Date: Sat, 1 Mar 2025 22:51:41 -0500 Subject: [PATCH 2/2] fix coverage --- tests/resources/nutrition/test_create_food.py | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/resources/nutrition/test_create_food.py b/tests/resources/nutrition/test_create_food.py index 8bc1c79..b8a0d48 100644 --- a/tests/resources/nutrition/test_create_food.py +++ b/tests/resources/nutrition/test_create_food.py @@ -102,3 +102,43 @@ def test_create_food_calories_from_fat_must_be_integer(nutrition_resource): assert exc_info.value.error_type == "client_validation" assert exc_info.value.field_name == "CALORIES_FROM_FAT" assert "Calories from fat must be an integer" in str(exc_info.value) + + +def test_create_food_with_calories_from_fat(nutrition_resource, mock_response): + """Test creating food with calories from fat as an integer""" + mock_response.json.return_value = {"foodId": 12345, "name": "Test Food", "calories": 100} + nutrition_resource.oauth.request.return_value = mock_response + + result = nutrition_resource.create_food( + name="Test Food", + default_food_measurement_unit_id=147, + default_serving_size=100.0, + calories=100, + description="Test food description", + form_type=FoodFormType.DRY, + nutritional_values={ + NutritionalValue.CALORIES_FROM_FAT: 20, # Integer value should work fine + NutritionalValue.PROTEIN: 20.0, + NutritionalValue.TOTAL_CARBOHYDRATE: 0.0, + }, + ) + + assert result == mock_response.json.return_value + nutrition_resource.oauth.request.assert_called_once_with( + "POST", + "https://api.fitbit.com/1/user/-/foods.json", + data=None, + json=None, + params={ + "name": "Test Food", + "defaultFoodMeasurementUnitId": 147, + "defaultServingSize": 100.0, + "calories": 100, + "description": "Test food description", + "formType": "DRY", + "caloriesFromFat": 20, # Should be passed as an integer + "protein": 20.0, + "totalCarbohydrate": 0.0, + }, + headers={"Accept-Locale": "en_US", "Accept-Language": "en_US"}, + )