Skip to content

Commit b370ebc

Browse files
committed
fix coverage
1 parent 409b80e commit b370ebc

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

tests/resources/nutrition/test_create_food.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,43 @@ def test_create_food_calories_from_fat_must_be_integer(nutrition_resource):
102102
assert exc_info.value.error_type == "client_validation"
103103
assert exc_info.value.field_name == "CALORIES_FROM_FAT"
104104
assert "Calories from fat must be an integer" in str(exc_info.value)
105+
106+
107+
def test_create_food_with_calories_from_fat(nutrition_resource, mock_response):
108+
"""Test creating food with calories from fat as an integer"""
109+
mock_response.json.return_value = {"foodId": 12345, "name": "Test Food", "calories": 100}
110+
nutrition_resource.oauth.request.return_value = mock_response
111+
112+
result = nutrition_resource.create_food(
113+
name="Test Food",
114+
default_food_measurement_unit_id=147,
115+
default_serving_size=100.0,
116+
calories=100,
117+
description="Test food description",
118+
form_type=FoodFormType.DRY,
119+
nutritional_values={
120+
NutritionalValue.CALORIES_FROM_FAT: 20, # Integer value should work fine
121+
NutritionalValue.PROTEIN: 20.0,
122+
NutritionalValue.TOTAL_CARBOHYDRATE: 0.0,
123+
},
124+
)
125+
126+
assert result == mock_response.json.return_value
127+
nutrition_resource.oauth.request.assert_called_once_with(
128+
"POST",
129+
"https://api.fitbit.com/1/user/-/foods.json",
130+
data=None,
131+
json=None,
132+
params={
133+
"name": "Test Food",
134+
"defaultFoodMeasurementUnitId": 147,
135+
"defaultServingSize": 100.0,
136+
"calories": 100,
137+
"description": "Test food description",
138+
"formType": "DRY",
139+
"caloriesFromFat": 20, # Should be passed as an integer
140+
"protein": 20.0,
141+
"totalCarbohydrate": 0.0,
142+
},
143+
headers={"Accept-Locale": "en_US", "Accept-Language": "en_US"},
144+
)

0 commit comments

Comments
 (0)