Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
Expand Down
40 changes: 40 additions & 0 deletions tests/resources/nutrition/test_create_food.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
)