mirror of
https://github.com/joaovitoriasilva/endurain.git
synced 2026-01-10 00:07:57 -05:00
Refactor health modules into health namespace package
Moved health_sleep, health_steps, health_targets, and health_weight modules into a unified health/ namespace package. Updated all imports and test references accordingly to improve code organization and maintainability.
This commit is contained in:
@@ -19,10 +19,10 @@ import activities.activity_workout_steps.models
|
||||
import followers.models
|
||||
import gears.gear.models
|
||||
import gears.gear_components.models
|
||||
import health_sleep.models
|
||||
import health_steps.models
|
||||
import health_targets.models
|
||||
import health_weight.models
|
||||
import health.health_sleep.models
|
||||
import health.health_steps.models
|
||||
import health.health_targets.models
|
||||
import health.health_weight.models
|
||||
import migrations.models
|
||||
import notifications.models
|
||||
import password_reset_tokens.models
|
||||
|
||||
@@ -25,10 +25,10 @@ import followers.router as followers_router
|
||||
import garmin.router as garmin_router
|
||||
import gears.gear.router as gears_router
|
||||
import gears.gear_components.router as gear_components_router
|
||||
import health_sleep.router as health_sleep_router
|
||||
import health_weight.router as health_weight_router
|
||||
import health_steps.router as health_steps_router
|
||||
import health_targets.router as health_targets_router
|
||||
import health.health_sleep.router as health_sleep_router
|
||||
import health.health_weight.router as health_weight_router
|
||||
import health.health_steps.router as health_steps_router
|
||||
import health.health_targets.router as health_targets_router
|
||||
import notifications.router as notifications_router
|
||||
import password_reset_tokens.router as password_reset_tokens_router
|
||||
import profile.browser_redirect_router as profile_browser_redirect_router
|
||||
|
||||
@@ -9,14 +9,14 @@ import core.logger as core_logger
|
||||
|
||||
import garmin.utils as garmin_utils
|
||||
|
||||
import health_weight.crud as health_weight_crud
|
||||
import health_weight.schema as health_weight_schema
|
||||
import health.health_weight.crud as health_weight_crud
|
||||
import health.health_weight.schema as health_weight_schema
|
||||
|
||||
import health_steps.crud as health_steps_crud
|
||||
import health_steps.schema as health_steps_schema
|
||||
import health.health_steps.crud as health_steps_crud
|
||||
import health.health_steps.schema as health_steps_schema
|
||||
|
||||
import health_sleep.crud as health_sleep_crud
|
||||
import health_sleep.schema as health_sleep_schema
|
||||
import health.health_sleep.crud as health_sleep_crud
|
||||
import health.health_sleep.schema as health_sleep_schema
|
||||
|
||||
import users.user.crud as users_crud
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@ from sqlalchemy import func, desc
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
|
||||
import health_sleep.schema as health_sleep_schema
|
||||
import health_sleep.models as health_sleep_models
|
||||
import health.health_sleep.schema as health_sleep_schema
|
||||
import health.health_sleep.models as health_sleep_models
|
||||
|
||||
import core.logger as core_logger
|
||||
|
||||
@@ -3,9 +3,9 @@ from typing import Annotated, Callable
|
||||
from fastapi import APIRouter, Depends, Security, HTTPException
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
import health_sleep.schema as health_sleep_schema
|
||||
import health_sleep.crud as health_sleep_crud
|
||||
import health_sleep.sleep_scoring as sleep_scoring
|
||||
import health.health_sleep.schema as health_sleep_schema
|
||||
import health.health_sleep.crud as health_sleep_crud
|
||||
import health.health_sleep.sleep_scoring as health_sleep_sleep_scoring
|
||||
|
||||
import auth.security as auth_security
|
||||
|
||||
@@ -158,7 +158,7 @@ async def create_health_sleep(
|
||||
raise HTTPException(status_code=400, detail="Date field is required.")
|
||||
|
||||
# Calculate sleep scores before saving
|
||||
sleep_scoring._calculate_and_set_sleep_scores(health_sleep)
|
||||
health_sleep_sleep_scoring._calculate_and_set_sleep_scores(health_sleep)
|
||||
|
||||
# Convert date to string format for CRUD function
|
||||
date_str = health_sleep.date.isoformat()
|
||||
@@ -216,7 +216,7 @@ async def edit_health_sleep(
|
||||
found, or database operations fail.
|
||||
"""
|
||||
# Recalculate sleep scores when editing
|
||||
sleep_scoring._calculate_and_set_sleep_scores(health_sleep)
|
||||
health_sleep_sleep_scoring._calculate_and_set_sleep_scores(health_sleep)
|
||||
|
||||
# Updates the health_sleep in the database and returns it
|
||||
return health_sleep_crud.edit_health_sleep(token_user_id, health_sleep, db)
|
||||
@@ -2,7 +2,7 @@
|
||||
Sleep scoring calculations.
|
||||
"""
|
||||
|
||||
import health_sleep.schema as health_sleep_schema
|
||||
import health.health_sleep.schema as health_sleep_schema
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
@@ -3,8 +3,8 @@ from sqlalchemy import func, desc
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
|
||||
import health_steps.schema as health_steps_schema
|
||||
import health_steps.models as health_steps_models
|
||||
import health.health_steps.schema as health_steps_schema
|
||||
import health.health_steps.models as health_steps_models
|
||||
|
||||
import core.logger as core_logger
|
||||
|
||||
@@ -3,8 +3,8 @@ from typing import Annotated, Callable
|
||||
from fastapi import APIRouter, Depends, Security, HTTPException
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
import health_steps.schema as health_steps_schema
|
||||
import health_steps.crud as health_steps_crud
|
||||
import health.health_steps.schema as health_steps_schema
|
||||
import health.health_steps.crud as health_steps_crud
|
||||
|
||||
import auth.security as auth_security
|
||||
|
||||
@@ -2,8 +2,8 @@ from fastapi import HTTPException, status
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
|
||||
import health_targets.models as health_targets_models
|
||||
import health_targets.schema as health_targets_schema
|
||||
import health.health_targets.models as health_targets_models
|
||||
import health.health_targets.schema as health_targets_schema
|
||||
|
||||
import core.logger as core_logger
|
||||
|
||||
@@ -3,8 +3,8 @@ from typing import Annotated, Callable
|
||||
from fastapi import APIRouter, Depends, Security
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
import health_targets.schema as health_targets_schema
|
||||
import health_targets.crud as health_targets_crud
|
||||
import health.health_targets.schema as health_targets_schema
|
||||
import health.health_targets.crud as health_targets_crud
|
||||
|
||||
import auth.security as auth_security
|
||||
|
||||
0
backend/app/health/health_weight/__init__.py
Normal file
0
backend/app/health/health_weight/__init__.py
Normal file
@@ -3,9 +3,9 @@ from sqlalchemy import func, desc
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
|
||||
import health_weight.schema as health_weight_schema
|
||||
import health_weight.models as health_weight_models
|
||||
import health_weight.utils as health_weight_utils
|
||||
import health.health_weight.schema as health_weight_schema
|
||||
import health.health_weight.models as health_weight_models
|
||||
import health.health_weight.utils as health_weight_utils
|
||||
|
||||
import core.logger as core_logger
|
||||
|
||||
@@ -4,8 +4,8 @@ from datetime import date
|
||||
from fastapi import APIRouter, Depends, Security, HTTPException
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
import health_weight.schema as health_weight_schema
|
||||
import health_weight.crud as health_weight_crud
|
||||
import health.health_weight.schema as health_weight_schema
|
||||
import health.health_weight.crud as health_weight_crud
|
||||
|
||||
import auth.security as auth_security
|
||||
|
||||
@@ -2,8 +2,8 @@ from sqlalchemy.orm import Session
|
||||
|
||||
import users.user.crud as users_crud
|
||||
|
||||
import health_weight.schema as health_weight_schema
|
||||
import health_weight.crud as health_weight_crud
|
||||
import health.health_weight.schema as health_weight_schema
|
||||
import health.health_weight.crud as health_weight_crud
|
||||
|
||||
|
||||
def calculate_bmi(
|
||||
@@ -8,7 +8,7 @@ import activities.activity_streams.crud as activity_streams_crud
|
||||
|
||||
import migrations.crud as migrations_crud
|
||||
|
||||
import health_weight.crud as health_weight_crud
|
||||
import health.health_weight.crud as health_weight_crud
|
||||
|
||||
import core.logger as core_logger
|
||||
import core.config as core_config
|
||||
|
||||
@@ -26,8 +26,8 @@ import activities.activity_media.crud as activity_media_crud
|
||||
import activities.activity_exercise_titles.crud as activity_exercise_titles_crud
|
||||
import gears.gear.crud as gear_crud
|
||||
import gears.gear_components.crud as gear_components_crud
|
||||
import health_weight.crud as health_weight_crud
|
||||
import health_targets.crud as health_targets_crud
|
||||
import health.health_weight.crud as health_weight_crud
|
||||
import health.health_targets.crud as health_targets_crud
|
||||
import notifications.crud as notifications_crud
|
||||
import users.user_default_gear.crud as user_default_gear_crud
|
||||
import users.user_goals.crud as user_goals_crud
|
||||
|
||||
@@ -67,11 +67,11 @@ import gears.gear_components.schema as gear_components_schema
|
||||
import notifications.crud as notifications_crud
|
||||
import notifications.schema as notifications_schema
|
||||
|
||||
import health_weight.crud as health_weight_crud
|
||||
import health_weight.schema as health_weight_schema
|
||||
import health.health_weight.crud as health_weight_crud
|
||||
import health.health_weight.schema as health_weight_schema
|
||||
|
||||
import health_targets.crud as health_targets_crud
|
||||
import health_targets.schema as health_targets_schema
|
||||
import health.health_targets.crud as health_targets_crud
|
||||
import health.health_targets.schema as health_targets_schema
|
||||
|
||||
import websocket.schema as websocket_schema
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import users.user.utils as users_utils
|
||||
import users.user.models as users_models
|
||||
import users.user_identity_providers.crud as user_idp_crud
|
||||
|
||||
import health_weight.utils as health_weight_utils
|
||||
import health.health_weight.utils as health_weight_utils
|
||||
|
||||
import server_settings.utils as server_settings_utils
|
||||
import server_settings.schema as server_settings_schema
|
||||
|
||||
@@ -14,7 +14,7 @@ import users.user.schema as users_schema
|
||||
import users.user_integrations.crud as user_integrations_crud
|
||||
import users.user_default_gear.crud as user_default_gear_crud
|
||||
import users.user_privacy_settings.crud as users_privacy_settings_crud
|
||||
import health_targets.crud as health_targets_crud
|
||||
import health.health_targets.crud as health_targets_crud
|
||||
|
||||
import core.logger as core_logger
|
||||
import core.config as core_config
|
||||
|
||||
@@ -26,10 +26,10 @@ import users.user.schema as user_schema
|
||||
# Variables and constants
|
||||
DEFAULT_ROUTER_MODULES = [
|
||||
"session.router",
|
||||
"health_sleep.router",
|
||||
"health_steps.router",
|
||||
"health_targets.router",
|
||||
"health_weight.router",
|
||||
"health.health_sleep.router",
|
||||
"health.health_steps.router",
|
||||
"health.health_targets.router",
|
||||
"health.health_weight.router",
|
||||
]
|
||||
|
||||
|
||||
@@ -139,13 +139,13 @@ def _include_router_if_exists(app: FastAPI, dotted: str):
|
||||
mod = import_module(dotted)
|
||||
router = getattr(mod, "router", None)
|
||||
if router is not None:
|
||||
if dotted == "health_sleep.router":
|
||||
if dotted == "health.health_sleep.router":
|
||||
app.include_router(router, prefix="/health_sleep")
|
||||
elif dotted == "health_steps.router":
|
||||
elif dotted == "health.health_steps.router":
|
||||
app.include_router(router, prefix="/health_steps")
|
||||
elif dotted == "health_targets.router":
|
||||
elif dotted == "health.health_targets.router":
|
||||
app.include_router(router, prefix="/health_targets")
|
||||
elif dotted == "health_weight.router":
|
||||
elif dotted == "health.health_weight.router":
|
||||
app.include_router(router, prefix="/health_weight")
|
||||
else:
|
||||
app.include_router(router)
|
||||
|
||||
@@ -5,9 +5,9 @@ from unittest.mock import MagicMock, patch
|
||||
from fastapi import HTTPException, status
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
|
||||
import health_sleep.crud as health_sleep_crud
|
||||
import health_sleep.schema as health_sleep_schema
|
||||
import health_sleep.models as health_sleep_models
|
||||
import health.health_sleep.crud as health_sleep_crud
|
||||
import health.health_sleep.schema as health_sleep_schema
|
||||
import health.health_sleep.models as health_sleep_models
|
||||
|
||||
|
||||
class TestGetHealthSleepNumber:
|
||||
@@ -284,7 +284,7 @@ class TestCreateHealthSleep:
|
||||
mock_db.commit.assert_called_once()
|
||||
mock_db.refresh.assert_called_once()
|
||||
|
||||
@patch("health_sleep.crud.func")
|
||||
@patch("health.health_sleep.crud.func")
|
||||
def test_create_health_sleep_with_none_date(self, mock_func, mock_db):
|
||||
"""
|
||||
Test creation with None date sets current date.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import pytest
|
||||
from datetime import date as datetime_date
|
||||
|
||||
import health_sleep.models as health_sleep_models
|
||||
import health.health_sleep.models as health_sleep_models
|
||||
|
||||
|
||||
class TestHealthSleepModel:
|
||||
|
||||
@@ -4,8 +4,8 @@ from decimal import Decimal
|
||||
from unittest.mock import MagicMock, patch, ANY
|
||||
from fastapi import HTTPException, status
|
||||
|
||||
import health_sleep.schema as health_sleep_schema
|
||||
import health_sleep.models as health_sleep_models
|
||||
import health.health_sleep.schema as health_sleep_schema
|
||||
import health.health_sleep.models as health_sleep_models
|
||||
|
||||
|
||||
class TestReadHealthSleepAll:
|
||||
@@ -13,8 +13,10 @@ class TestReadHealthSleepAll:
|
||||
Test suite for read_health_sleep_all endpoint.
|
||||
"""
|
||||
|
||||
@patch("health_sleep.router.health_sleep_crud.get_health_sleep_number")
|
||||
@patch("health_sleep.router.health_sleep_crud.get_all_health_sleep_by_user_id")
|
||||
@patch("health.health_sleep.router.health_sleep_crud.get_health_sleep_number")
|
||||
@patch(
|
||||
"health.health_sleep.router.health_sleep_crud.get_all_health_sleep_by_user_id"
|
||||
)
|
||||
def test_read_health_sleep_all_success(
|
||||
self, mock_get_all, mock_get_number, fast_api_client, fast_api_app
|
||||
):
|
||||
@@ -80,8 +82,10 @@ class TestReadHealthSleepAll:
|
||||
assert data["total"] == 1
|
||||
assert len(data["records"]) == 1
|
||||
|
||||
@patch("health_sleep.router.health_sleep_crud.get_health_sleep_number")
|
||||
@patch("health_sleep.router.health_sleep_crud.get_all_health_sleep_by_user_id")
|
||||
@patch("health.health_sleep.router.health_sleep_crud.get_health_sleep_number")
|
||||
@patch(
|
||||
"health.health_sleep.router.health_sleep_crud.get_all_health_sleep_by_user_id"
|
||||
)
|
||||
def test_read_health_sleep_all_empty(
|
||||
self, mock_get_all, mock_get_number, fast_api_client, fast_api_app
|
||||
):
|
||||
@@ -110,8 +114,10 @@ class TestReadHealthSleepAllPagination:
|
||||
Test suite for read_health_sleep_all_pagination endpoint.
|
||||
"""
|
||||
|
||||
@patch("health_sleep.router.health_sleep_crud.get_health_sleep_number")
|
||||
@patch("health_sleep.router.health_sleep_crud.get_health_sleep_with_pagination")
|
||||
@patch("health.health_sleep.router.health_sleep_crud.get_health_sleep_number")
|
||||
@patch(
|
||||
"health.health_sleep.router.health_sleep_crud.get_health_sleep_with_pagination"
|
||||
)
|
||||
def test_read_health_sleep_all_pagination_success(
|
||||
self, mock_get_paginated, mock_get_number, fast_api_client, fast_api_app
|
||||
):
|
||||
@@ -179,8 +185,10 @@ class TestReadHealthSleepAllPagination:
|
||||
assert data["page_number"] == 1
|
||||
assert len(data["records"]) == 1
|
||||
|
||||
@patch("health_sleep.router.health_sleep_crud.get_health_sleep_number")
|
||||
@patch("health_sleep.router.health_sleep_crud.get_health_sleep_with_pagination")
|
||||
@patch("health.health_sleep.router.health_sleep_crud.get_health_sleep_number")
|
||||
@patch(
|
||||
"health.health_sleep.router.health_sleep_crud.get_health_sleep_with_pagination"
|
||||
)
|
||||
def test_read_health_sleep_all_pagination_different_page(
|
||||
self, mock_get_paginated, mock_get_number, fast_api_client, fast_api_app
|
||||
):
|
||||
@@ -212,8 +220,8 @@ class TestCreateHealthSleep:
|
||||
Test suite for create_health_sleep endpoint.
|
||||
"""
|
||||
|
||||
@patch("health_sleep.router.health_sleep_crud.create_health_sleep")
|
||||
@patch("health_sleep.router.health_sleep_crud.get_health_sleep_by_date")
|
||||
@patch("health.health_sleep.router.health_sleep_crud.create_health_sleep")
|
||||
@patch("health.health_sleep.router.health_sleep_crud.get_health_sleep_by_date")
|
||||
def test_create_health_sleep_success(
|
||||
self,
|
||||
mock_get_by_date,
|
||||
@@ -249,8 +257,8 @@ class TestCreateHealthSleep:
|
||||
data = response.json()
|
||||
assert data["total_sleep_seconds"] == 28800
|
||||
|
||||
@patch("health_sleep.router.health_sleep_crud.edit_health_sleep")
|
||||
@patch("health_sleep.router.health_sleep_crud.get_health_sleep_by_date")
|
||||
@patch("health.health_sleep.router.health_sleep_crud.edit_health_sleep")
|
||||
@patch("health.health_sleep.router.health_sleep_crud.get_health_sleep_by_date")
|
||||
def test_create_health_sleep_updates_existing(
|
||||
self, mock_get_by_date, mock_edit, fast_api_client, fast_api_app
|
||||
):
|
||||
@@ -301,9 +309,9 @@ class TestCreateHealthSleep:
|
||||
assert response.status_code == 400
|
||||
assert "Date field is required" in response.json()["detail"]
|
||||
|
||||
@patch("health_sleep.router.sleep_scoring._calculate_and_set_sleep_scores")
|
||||
@patch("health_sleep.router.health_sleep_crud.create_health_sleep")
|
||||
@patch("health_sleep.router.health_sleep_crud.get_health_sleep_by_date")
|
||||
@patch("health.health_sleep.router.sleep_scoring._calculate_and_set_sleep_scores")
|
||||
@patch("health.health_sleep.router.health_sleep_crud.create_health_sleep")
|
||||
@patch("health.health_sleep.router.health_sleep_crud.get_health_sleep_by_date")
|
||||
def test_create_health_sleep_calls_scoring(
|
||||
self, mock_get_by_date, mock_create, mock_scoring, fast_api_client, fast_api_app
|
||||
):
|
||||
@@ -340,7 +348,7 @@ class TestEditHealthSleep:
|
||||
Test suite for edit_health_sleep endpoint.
|
||||
"""
|
||||
|
||||
@patch("health_sleep.router.health_sleep_crud.edit_health_sleep")
|
||||
@patch("health.health_sleep.router.health_sleep_crud.edit_health_sleep")
|
||||
def test_edit_health_sleep_success(self, mock_edit, fast_api_client, fast_api_app):
|
||||
"""
|
||||
Test successful edit of health sleep entry.
|
||||
@@ -370,7 +378,7 @@ class TestEditHealthSleep:
|
||||
data = response.json()
|
||||
assert data["total_sleep_seconds"] == 32400
|
||||
|
||||
@patch("health_sleep.router.health_sleep_crud.edit_health_sleep")
|
||||
@patch("health.health_sleep.router.health_sleep_crud.edit_health_sleep")
|
||||
def test_edit_health_sleep_not_found(
|
||||
self, mock_edit, fast_api_client, fast_api_app
|
||||
):
|
||||
@@ -403,8 +411,8 @@ class TestEditHealthSleepScoringIntegration:
|
||||
Test suite for edit_health_sleep endpoint scoring integration.
|
||||
"""
|
||||
|
||||
@patch("health_sleep.router.sleep_scoring._calculate_and_set_sleep_scores")
|
||||
@patch("health_sleep.router.health_sleep_crud.edit_health_sleep")
|
||||
@patch("health.health_sleep.router.sleep_scoring._calculate_and_set_sleep_scores")
|
||||
@patch("health.health_sleep.router.health_sleep_crud.edit_health_sleep")
|
||||
def test_edit_health_sleep_calls_scoring(
|
||||
self, mock_edit, mock_scoring, fast_api_client, fast_api_app
|
||||
):
|
||||
@@ -441,7 +449,7 @@ class TestDeleteHealthSleep:
|
||||
Test suite for delete_health_sleep endpoint.
|
||||
"""
|
||||
|
||||
@patch("health_sleep.router.health_sleep_crud.delete_health_sleep")
|
||||
@patch("health.health_sleep.router.health_sleep_crud.delete_health_sleep")
|
||||
def test_delete_health_sleep_success(
|
||||
self, mock_delete, fast_api_client, fast_api_app
|
||||
):
|
||||
@@ -461,7 +469,7 @@ class TestDeleteHealthSleep:
|
||||
assert response.status_code == 204
|
||||
mock_delete.assert_called_once_with(1, 1, ANY)
|
||||
|
||||
@patch("health_sleep.router.health_sleep_crud.delete_health_sleep")
|
||||
@patch("health.health_sleep.router.health_sleep_crud.delete_health_sleep")
|
||||
def test_delete_health_sleep_not_found(
|
||||
self, mock_delete, fast_api_client, fast_api_app
|
||||
):
|
||||
|
||||
@@ -3,7 +3,7 @@ from datetime import datetime, date as datetime_date
|
||||
from decimal import Decimal
|
||||
from pydantic import ValidationError
|
||||
|
||||
import health_sleep.schema as health_sleep_schema
|
||||
import health.health_sleep.schema as health_sleep_schema
|
||||
|
||||
|
||||
class TestHealthSleepSchema:
|
||||
|
||||
@@ -2,8 +2,8 @@ import pytest
|
||||
from datetime import datetime
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import health_sleep.sleep_scoring as sleep_scoring
|
||||
import health_sleep.schema as health_sleep_schema
|
||||
import health.health_sleep.sleep_scoring as sleep_scoring
|
||||
import health.health_sleep.schema as health_sleep_schema
|
||||
|
||||
|
||||
class TestCalculateSleepDurationHours:
|
||||
|
||||
@@ -4,9 +4,9 @@ from unittest.mock import MagicMock, patch
|
||||
from fastapi import HTTPException, status
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
|
||||
import health_steps.crud as health_steps_crud
|
||||
import health_steps.schema as health_steps_schema
|
||||
import health_steps.models as health_steps_models
|
||||
import health.health_steps.crud as health_steps_crud
|
||||
import health.health_steps.schema as health_steps_schema
|
||||
import health.health_steps.models as health_steps_models
|
||||
|
||||
|
||||
class TestGetHealthStepsNumber:
|
||||
@@ -283,7 +283,7 @@ class TestCreateHealthSteps:
|
||||
mock_db.commit.assert_called_once()
|
||||
mock_db.refresh.assert_called_once()
|
||||
|
||||
@patch("health_steps.crud.func")
|
||||
@patch("health.health_steps.crud.func")
|
||||
def test_create_health_steps_with_none_date(self, mock_func, mock_db):
|
||||
"""
|
||||
Test creation with None date sets current date.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import pytest
|
||||
from datetime import date as datetime_date
|
||||
|
||||
import health_steps.models as health_steps_models
|
||||
import health.health_steps.models as health_steps_models
|
||||
|
||||
|
||||
class TestHealthStepsModel:
|
||||
|
||||
@@ -3,8 +3,8 @@ from datetime import date as datetime_date
|
||||
from unittest.mock import MagicMock, patch, ANY
|
||||
from fastapi import HTTPException, status
|
||||
|
||||
import health_steps.schema as health_steps_schema
|
||||
import health_steps.models as health_steps_models
|
||||
import health.health_steps.schema as health_steps_schema
|
||||
import health.health_steps.models as health_steps_models
|
||||
|
||||
|
||||
class TestReadHealthStepsAll:
|
||||
@@ -12,8 +12,10 @@ class TestReadHealthStepsAll:
|
||||
Test suite for read_health_steps_all endpoint.
|
||||
"""
|
||||
|
||||
@patch("health_steps.router.health_steps_crud.get_health_steps_number")
|
||||
@patch("health_steps.router.health_steps_crud.get_all_health_steps_by_user_id")
|
||||
@patch("health.health_steps.router.health_steps_crud.get_health_steps_number")
|
||||
@patch(
|
||||
"health.health_steps.router.health_steps_crud.get_all_health_steps_by_user_id"
|
||||
)
|
||||
def test_read_health_steps_all_success(
|
||||
self, mock_get_all, mock_get_number, fast_api_client, fast_api_app
|
||||
):
|
||||
@@ -50,8 +52,10 @@ class TestReadHealthStepsAll:
|
||||
assert data["total"] == 2
|
||||
assert len(data["records"]) == 2
|
||||
|
||||
@patch("health_steps.router.health_steps_crud.get_health_steps_number")
|
||||
@patch("health_steps.router.health_steps_crud.get_all_health_steps_by_user_id")
|
||||
@patch("health.health_steps.router.health_steps_crud.get_health_steps_number")
|
||||
@patch(
|
||||
"health.health_steps.router.health_steps_crud.get_all_health_steps_by_user_id"
|
||||
)
|
||||
def test_read_health_steps_all_empty(
|
||||
self, mock_get_all, mock_get_number, fast_api_client, fast_api_app
|
||||
):
|
||||
@@ -80,8 +84,10 @@ class TestReadHealthStepsAllPagination:
|
||||
Test suite for read_health_steps_all_pagination endpoint.
|
||||
"""
|
||||
|
||||
@patch("health_steps.router.health_steps_crud.get_health_steps_number")
|
||||
@patch("health_steps.router.health_steps_crud.get_health_steps_with_pagination")
|
||||
@patch("health.health_steps.router.health_steps_crud.get_health_steps_number")
|
||||
@patch(
|
||||
"health.health_steps.router.health_steps_crud.get_health_steps_with_pagination"
|
||||
)
|
||||
def test_read_health_steps_all_pagination_success(
|
||||
self, mock_get_paginated, mock_get_number, fast_api_client, fast_api_app
|
||||
):
|
||||
@@ -113,8 +119,10 @@ class TestReadHealthStepsAllPagination:
|
||||
assert data["page_number"] == 1
|
||||
assert len(data["records"]) == 1
|
||||
|
||||
@patch("health_steps.router.health_steps_crud.get_health_steps_number")
|
||||
@patch("health_steps.router.health_steps_crud.get_health_steps_with_pagination")
|
||||
@patch("health.health_steps.router.health_steps_crud.get_health_steps_number")
|
||||
@patch(
|
||||
"health.health_steps.router.health_steps_crud.get_health_steps_with_pagination"
|
||||
)
|
||||
def test_read_health_steps_all_pagination_different_page(
|
||||
self, mock_get_paginated, mock_get_number, fast_api_client, fast_api_app
|
||||
):
|
||||
@@ -146,8 +154,8 @@ class TestCreateHealthSteps:
|
||||
Test suite for create_health_steps endpoint.
|
||||
"""
|
||||
|
||||
@patch("health_steps.router.health_steps_crud.create_health_steps")
|
||||
@patch("health_steps.router.health_steps_crud.get_health_steps_by_date")
|
||||
@patch("health.health_steps.router.health_steps_crud.create_health_steps")
|
||||
@patch("health.health_steps.router.health_steps_crud.get_health_steps_by_date")
|
||||
def test_create_health_steps_success(
|
||||
self,
|
||||
mock_get_by_date,
|
||||
@@ -183,8 +191,8 @@ class TestCreateHealthSteps:
|
||||
data = response.json()
|
||||
assert data["steps"] == 10000
|
||||
|
||||
@patch("health_steps.router.health_steps_crud.edit_health_steps")
|
||||
@patch("health_steps.router.health_steps_crud.get_health_steps_by_date")
|
||||
@patch("health.health_steps.router.health_steps_crud.edit_health_steps")
|
||||
@patch("health.health_steps.router.health_steps_crud.get_health_steps_by_date")
|
||||
def test_create_health_steps_updates_existing(
|
||||
self, mock_get_by_date, mock_edit, fast_api_client, fast_api_app
|
||||
):
|
||||
@@ -241,7 +249,7 @@ class TestEditHealthSteps:
|
||||
Test suite for edit_health_steps endpoint.
|
||||
"""
|
||||
|
||||
@patch("health_steps.router.health_steps_crud.edit_health_steps")
|
||||
@patch("health.health_steps.router.health_steps_crud.edit_health_steps")
|
||||
def test_edit_health_steps_success(self, mock_edit, fast_api_client, fast_api_app):
|
||||
"""
|
||||
Test successful edit of health steps entry.
|
||||
@@ -271,7 +279,7 @@ class TestEditHealthSteps:
|
||||
data = response.json()
|
||||
assert data["steps"] == 12000
|
||||
|
||||
@patch("health_steps.router.health_steps_crud.edit_health_steps")
|
||||
@patch("health.health_steps.router.health_steps_crud.edit_health_steps")
|
||||
def test_edit_health_steps_not_found(
|
||||
self, mock_edit, fast_api_client, fast_api_app
|
||||
):
|
||||
@@ -304,7 +312,7 @@ class TestDeleteHealthSteps:
|
||||
Test suite for delete_health_steps endpoint.
|
||||
"""
|
||||
|
||||
@patch("health_steps.router.health_steps_crud.delete_health_steps")
|
||||
@patch("health.health_steps.router.health_steps_crud.delete_health_steps")
|
||||
def test_delete_health_steps_success(
|
||||
self, mock_delete, fast_api_client, fast_api_app
|
||||
):
|
||||
@@ -324,7 +332,7 @@ class TestDeleteHealthSteps:
|
||||
assert response.status_code == 204
|
||||
mock_delete.assert_called_once_with(1, 1, ANY)
|
||||
|
||||
@patch("health_steps.router.health_steps_crud.delete_health_steps")
|
||||
@patch("health.health_steps.router.health_steps_crud.delete_health_steps")
|
||||
def test_delete_health_steps_not_found(
|
||||
self, mock_delete, fast_api_client, fast_api_app
|
||||
):
|
||||
|
||||
@@ -2,7 +2,7 @@ import pytest
|
||||
from datetime import date as datetime_date
|
||||
from pydantic import ValidationError
|
||||
|
||||
import health_steps.schema as health_steps_schema
|
||||
import health.health_steps.schema as health_steps_schema
|
||||
|
||||
|
||||
class TestHealthStepsSchema:
|
||||
|
||||
@@ -3,9 +3,9 @@ from unittest.mock import MagicMock, patch
|
||||
from fastapi import HTTPException, status
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
|
||||
import health_targets.crud as health_targets_crud
|
||||
import health_targets.schema as health_targets_schema
|
||||
import health_targets.models as health_targets_models
|
||||
import health.health_targets.crud as health_targets_crud
|
||||
import health.health_targets.schema as health_targets_schema
|
||||
import health.health_targets.models as health_targets_models
|
||||
|
||||
|
||||
class TestGetHealthTargetsByUserId:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import pytest
|
||||
|
||||
import health_targets.models as health_targets_models
|
||||
import health.health_targets.models as health_targets_models
|
||||
|
||||
|
||||
class TestHealthTargetsModel:
|
||||
|
||||
@@ -2,8 +2,8 @@ import pytest
|
||||
from unittest.mock import MagicMock, patch, ANY
|
||||
from fastapi import HTTPException, status
|
||||
|
||||
import health_targets.schema as health_targets_schema
|
||||
import health_targets.models as health_targets_models
|
||||
import health.health_targets.schema as health_targets_schema
|
||||
import health.health_targets.models as health_targets_models
|
||||
|
||||
|
||||
class TestReadHealthTargetsAll:
|
||||
@@ -11,7 +11,9 @@ class TestReadHealthTargetsAll:
|
||||
Test suite for read_health_targets_all endpoint.
|
||||
"""
|
||||
|
||||
@patch("health_targets.router.health_targets_crud.get_health_targets_by_user_id")
|
||||
@patch(
|
||||
"health.health_targets.router.health_targets_crud.get_health_targets_by_user_id"
|
||||
)
|
||||
def test_read_health_targets_all_success(
|
||||
self, mock_get_targets, fast_api_client, fast_api_app
|
||||
):
|
||||
@@ -41,7 +43,9 @@ class TestReadHealthTargetsAll:
|
||||
assert data["steps"] == 10000
|
||||
assert data["sleep"] == 28800
|
||||
|
||||
@patch("health_targets.router.health_targets_crud.get_health_targets_by_user_id")
|
||||
@patch(
|
||||
"health.health_targets.router.health_targets_crud.get_health_targets_by_user_id"
|
||||
)
|
||||
def test_read_health_targets_all_not_found(
|
||||
self, mock_get_targets, fast_api_client, fast_api_app
|
||||
):
|
||||
@@ -61,7 +65,9 @@ class TestReadHealthTargetsAll:
|
||||
assert response.status_code == 200
|
||||
assert response.json() is None
|
||||
|
||||
@patch("health_targets.router.health_targets_crud.get_health_targets_by_user_id")
|
||||
@patch(
|
||||
"health.health_targets.router.health_targets_crud.get_health_targets_by_user_id"
|
||||
)
|
||||
def test_read_health_targets_all_partial_data(
|
||||
self, mock_get_targets, fast_api_client, fast_api_app
|
||||
):
|
||||
@@ -97,7 +103,7 @@ class TestUpdateHealthTargets:
|
||||
Test suite for update_health_targets endpoint.
|
||||
"""
|
||||
|
||||
@patch("health_targets.router.health_targets_crud.edit_health_target")
|
||||
@patch("health.health_targets.router.health_targets_crud.edit_health_target")
|
||||
def test_update_health_targets_success(
|
||||
self, mock_edit, fast_api_client, fast_api_app
|
||||
):
|
||||
@@ -132,7 +138,7 @@ class TestUpdateHealthTargets:
|
||||
assert data["steps"] == 12000
|
||||
assert data["sleep"] == 32400
|
||||
|
||||
@patch("health_targets.router.health_targets_crud.edit_health_target")
|
||||
@patch("health.health_targets.router.health_targets_crud.edit_health_target")
|
||||
def test_update_health_targets_partial_update(
|
||||
self, mock_edit, fast_api_client, fast_api_app
|
||||
):
|
||||
@@ -163,7 +169,7 @@ class TestUpdateHealthTargets:
|
||||
data = response.json()
|
||||
assert data["weight"] == 75.0
|
||||
|
||||
@patch("health_targets.router.health_targets_crud.edit_health_target")
|
||||
@patch("health.health_targets.router.health_targets_crud.edit_health_target")
|
||||
def test_update_health_targets_clear_values(
|
||||
self, mock_edit, fast_api_client, fast_api_app
|
||||
):
|
||||
@@ -198,7 +204,7 @@ class TestUpdateHealthTargets:
|
||||
assert data["steps"] is None
|
||||
assert data["sleep"] is None
|
||||
|
||||
@patch("health_targets.router.health_targets_crud.edit_health_target")
|
||||
@patch("health.health_targets.router.health_targets_crud.edit_health_target")
|
||||
def test_update_health_targets_not_found(
|
||||
self, mock_edit, fast_api_client, fast_api_app
|
||||
):
|
||||
@@ -223,7 +229,7 @@ class TestUpdateHealthTargets:
|
||||
# Assert
|
||||
assert response.status_code == 404
|
||||
|
||||
@patch("health_targets.router.health_targets_crud.edit_health_target")
|
||||
@patch("health.health_targets.router.health_targets_crud.edit_health_target")
|
||||
def test_update_health_targets_with_all_fields(
|
||||
self, mock_edit, fast_api_client, fast_api_app
|
||||
):
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import pytest
|
||||
from pydantic import ValidationError
|
||||
|
||||
import health_targets.schema as health_targets_schema
|
||||
import health.health_targets.schema as health_targets_schema
|
||||
|
||||
|
||||
class TestHealthTargetsSchema:
|
||||
|
||||
@@ -4,9 +4,9 @@ from unittest.mock import MagicMock, patch
|
||||
from fastapi import HTTPException, status
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
|
||||
import health_weight.crud as health_weight_crud
|
||||
import health_weight.schema as health_weight_schema
|
||||
import health_weight.models as health_weight_models
|
||||
import health.health_weight.crud as health_weight_crud
|
||||
import health.health_weight.schema as health_weight_schema
|
||||
import health.health_weight.models as health_weight_models
|
||||
|
||||
|
||||
class TestGetAllHealthWeight:
|
||||
@@ -260,7 +260,7 @@ class TestCreateHealthWeight:
|
||||
Test suite for create_health_weight function.
|
||||
"""
|
||||
|
||||
@patch("health_weight.crud.health_weight_utils.calculate_bmi")
|
||||
@patch("health.health_weight.crud.health_weight_utils.calculate_bmi")
|
||||
def test_create_health_weight_success(self, mock_calculate_bmi, mock_db):
|
||||
"""
|
||||
Test successful creation of health weight entry.
|
||||
@@ -302,8 +302,8 @@ class TestCreateHealthWeight:
|
||||
mock_db.commit.assert_called_once()
|
||||
mock_db.refresh.assert_called_once()
|
||||
|
||||
@patch("health_weight.crud.health_weight_utils.calculate_bmi")
|
||||
@patch("health_weight.crud.func")
|
||||
@patch("health.health_weight.crud.health_weight_utils.calculate_bmi")
|
||||
@patch("health.health_weight.crud.func")
|
||||
def test_create_health_weight_with_none_date(
|
||||
self, mock_func, mock_calculate_bmi, mock_db
|
||||
):
|
||||
@@ -392,7 +392,7 @@ class TestEditHealthWeight:
|
||||
Test suite for edit_health_weight function.
|
||||
"""
|
||||
|
||||
@patch("health_weight.crud.health_weight_utils.calculate_bmi")
|
||||
@patch("health.health_weight.crud.health_weight_utils.calculate_bmi")
|
||||
def test_edit_health_weight_success(self, mock_calculate_bmi, mock_db):
|
||||
"""
|
||||
Test successful edit of health weight entry.
|
||||
|
||||
@@ -2,7 +2,7 @@ import pytest
|
||||
from datetime import date as datetime_date
|
||||
from decimal import Decimal
|
||||
|
||||
import health_weight.models as health_weight_models
|
||||
import health.health_weight.models as health_weight_models
|
||||
|
||||
|
||||
class TestHealthWeightModel:
|
||||
|
||||
@@ -4,8 +4,8 @@ from unittest.mock import MagicMock, patch, ANY
|
||||
from fastapi import HTTPException, status
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
import health_weight.schema as health_weight_schema
|
||||
import health_weight.models as health_weight_models
|
||||
import health.health_weight.schema as health_weight_schema
|
||||
import health.health_weight.models as health_weight_models
|
||||
|
||||
|
||||
class TestReadHealthWeightAll:
|
||||
@@ -13,9 +13,10 @@ class TestReadHealthWeightAll:
|
||||
Test suite for read_health_weight_all endpoint.
|
||||
"""
|
||||
|
||||
@patch("health_weight.router.health_weight_crud.get_health_weight_number")
|
||||
@patch("health.health_weight.router.health_weight_crud.get_health_weight_number")
|
||||
@patch(
|
||||
"health_weight.router.health_weight_crud." "get_all_health_weight_by_user_id"
|
||||
"health.health_weight.router.health_weight_crud."
|
||||
"get_all_health_weight_by_user_id"
|
||||
)
|
||||
def test_read_health_weight_all_success(
|
||||
self, mock_get_all, mock_get_number, fast_api_client, fast_api_app
|
||||
@@ -55,9 +56,10 @@ class TestReadHealthWeightAll:
|
||||
assert data["total"] == 2
|
||||
assert len(data["records"]) == 2
|
||||
|
||||
@patch("health_weight.router.health_weight_crud.get_health_weight_number")
|
||||
@patch("health.health_weight.router.health_weight_crud.get_health_weight_number")
|
||||
@patch(
|
||||
"health_weight.router.health_weight_crud." "get_all_health_weight_by_user_id"
|
||||
"health.health_weight.router.health_weight_crud."
|
||||
"get_all_health_weight_by_user_id"
|
||||
)
|
||||
def test_read_health_weight_all_empty(
|
||||
self, mock_get_all, mock_get_number, fast_api_client, fast_api_app
|
||||
@@ -87,9 +89,10 @@ class TestReadHealthWeightAllPagination:
|
||||
Test suite for read_health_weight_all_pagination endpoint.
|
||||
"""
|
||||
|
||||
@patch("health_weight.router.health_weight_crud.get_health_weight_number")
|
||||
@patch("health.health_weight.router.health_weight_crud.get_health_weight_number")
|
||||
@patch(
|
||||
"health_weight.router.health_weight_crud." "get_health_weight_with_pagination"
|
||||
"health.health_weight.router.health_weight_crud."
|
||||
"get_health_weight_with_pagination"
|
||||
)
|
||||
def test_read_health_weight_all_pagination_success(
|
||||
self, mock_get_paginated, mock_get_number, fast_api_client, fast_api_app
|
||||
@@ -123,9 +126,10 @@ class TestReadHealthWeightAllPagination:
|
||||
assert data["page_number"] == 1
|
||||
assert len(data["records"]) == 1
|
||||
|
||||
@patch("health_weight.router.health_weight_crud.get_health_weight_number")
|
||||
@patch("health.health_weight.router.health_weight_crud.get_health_weight_number")
|
||||
@patch(
|
||||
"health_weight.router.health_weight_crud." "get_health_weight_with_pagination"
|
||||
"health.health_weight.router.health_weight_crud."
|
||||
"get_health_weight_with_pagination"
|
||||
)
|
||||
def test_read_health_weight_all_pagination_different_page(
|
||||
self, mock_get_paginated, mock_get_number, fast_api_client, fast_api_app
|
||||
@@ -158,8 +162,8 @@ class TestCreateHealthWeight:
|
||||
Test suite for create_health_weight endpoint.
|
||||
"""
|
||||
|
||||
@patch("health_weight.router.health_weight_crud.create_health_weight")
|
||||
@patch("health_weight.router.health_weight_crud.get_health_weight_by_date")
|
||||
@patch("health.health_weight.router.health_weight_crud.create_health_weight")
|
||||
@patch("health.health_weight.router.health_weight_crud.get_health_weight_by_date")
|
||||
def test_create_health_weight_success(
|
||||
self,
|
||||
mock_get_by_date,
|
||||
@@ -196,8 +200,8 @@ class TestCreateHealthWeight:
|
||||
data = response.json()
|
||||
assert data["weight"] == 75.5
|
||||
|
||||
@patch("health_weight.router.health_weight_crud.edit_health_weight")
|
||||
@patch("health_weight.router.health_weight_crud.get_health_weight_by_date")
|
||||
@patch("health.health_weight.router.health_weight_crud.edit_health_weight")
|
||||
@patch("health.health_weight.router.health_weight_crud.get_health_weight_by_date")
|
||||
def test_create_health_weight_updates_existing(
|
||||
self, mock_get_by_date, mock_edit, fast_api_client, fast_api_app
|
||||
):
|
||||
@@ -238,7 +242,7 @@ class TestEditHealthWeight:
|
||||
Test suite for edit_health_weight endpoint.
|
||||
"""
|
||||
|
||||
@patch("health_weight.router.health_weight_crud.edit_health_weight")
|
||||
@patch("health.health_weight.router.health_weight_crud.edit_health_weight")
|
||||
def test_edit_health_weight_success(self, mock_edit, fast_api_client, fast_api_app):
|
||||
"""
|
||||
Test successful edit of health weight entry.
|
||||
@@ -269,7 +273,7 @@ class TestEditHealthWeight:
|
||||
data = response.json()
|
||||
assert data["weight"] == 76.0
|
||||
|
||||
@patch("health_weight.router.health_weight_crud.edit_health_weight")
|
||||
@patch("health.health_weight.router.health_weight_crud.edit_health_weight")
|
||||
def test_edit_health_weight_not_found(
|
||||
self, mock_edit, fast_api_client, fast_api_app
|
||||
):
|
||||
@@ -302,7 +306,7 @@ class TestDeleteHealthWeight:
|
||||
Test suite for delete_health_weight endpoint.
|
||||
"""
|
||||
|
||||
@patch("health_weight.router.health_weight_crud.delete_health_weight")
|
||||
@patch("health.health_weight.router.health_weight_crud.delete_health_weight")
|
||||
def test_delete_health_weight_success(
|
||||
self, mock_delete, fast_api_client, fast_api_app
|
||||
):
|
||||
@@ -322,7 +326,7 @@ class TestDeleteHealthWeight:
|
||||
assert response.status_code == 204
|
||||
mock_delete.assert_called_once_with(1, 1, ANY)
|
||||
|
||||
@patch("health_weight.router.health_weight_crud.delete_health_weight")
|
||||
@patch("health.health_weight.router.health_weight_crud.delete_health_weight")
|
||||
def test_delete_health_weight_not_found(
|
||||
self, mock_delete, fast_api_client, fast_api_app
|
||||
):
|
||||
|
||||
@@ -2,7 +2,7 @@ import pytest
|
||||
from datetime import date as datetime_date
|
||||
from pydantic import ValidationError
|
||||
|
||||
import health_weight.schema as health_weight_schema
|
||||
import health.health_weight.schema as health_weight_schema
|
||||
|
||||
|
||||
class TestHealthWeightSchema:
|
||||
|
||||
@@ -3,8 +3,8 @@ from datetime import date as datetime_date
|
||||
from unittest.mock import MagicMock, patch
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
import health_weight.utils as health_weight_utils
|
||||
import health_weight.schema as health_weight_schema
|
||||
import health.health_weight.utils as health_weight_utils
|
||||
import health.health_weight.schema as health_weight_schema
|
||||
import users.user.schema as user_schema
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ class TestCalculateBMI:
|
||||
Test suite for calculate_bmi function.
|
||||
"""
|
||||
|
||||
@patch("health_weight.utils.users_crud.get_user_by_id")
|
||||
@patch("health.health_weight.utils.users_crud.get_user_by_id")
|
||||
def test_calculate_bmi_success(self, mock_get_user):
|
||||
"""
|
||||
Test successful BMI calculation.
|
||||
@@ -39,7 +39,7 @@ class TestCalculateBMI:
|
||||
assert abs(result.bmi - expected_bmi) < 0.01
|
||||
mock_get_user.assert_called_once_with(user_id, mock_db)
|
||||
|
||||
@patch("health_weight.utils.users_crud.get_user_by_id")
|
||||
@patch("health.health_weight.utils.users_crud.get_user_by_id")
|
||||
def test_calculate_bmi_user_not_found(self, mock_get_user):
|
||||
"""
|
||||
Test BMI calculation when user not found.
|
||||
@@ -59,7 +59,7 @@ class TestCalculateBMI:
|
||||
# Assert
|
||||
assert result.bmi is None
|
||||
|
||||
@patch("health_weight.utils.users_crud.get_user_by_id")
|
||||
@patch("health.health_weight.utils.users_crud.get_user_by_id")
|
||||
def test_calculate_bmi_no_height(self, mock_get_user):
|
||||
"""
|
||||
Test BMI calculation when user has no height.
|
||||
@@ -82,7 +82,7 @@ class TestCalculateBMI:
|
||||
# Assert
|
||||
assert result.bmi is None
|
||||
|
||||
@patch("health_weight.utils.users_crud.get_user_by_id")
|
||||
@patch("health.health_weight.utils.users_crud.get_user_by_id")
|
||||
def test_calculate_bmi_no_weight(self, mock_get_user):
|
||||
"""
|
||||
Test BMI calculation when health weight has no weight.
|
||||
@@ -105,7 +105,7 @@ class TestCalculateBMI:
|
||||
# Assert
|
||||
assert result.bmi is None
|
||||
|
||||
@patch("health_weight.utils.users_crud.get_user_by_id")
|
||||
@patch("health.health_weight.utils.users_crud.get_user_by_id")
|
||||
def test_calculate_bmi_various_heights_and_weights(self, mock_get_user):
|
||||
"""
|
||||
Test BMI calculation with various heights and weights.
|
||||
@@ -145,9 +145,12 @@ class TestCalculateBMIAllUserEntries:
|
||||
Test suite for calculate_bmi_all_user_entries function.
|
||||
"""
|
||||
|
||||
@patch("health_weight.utils.health_weight_crud.edit_health_weight")
|
||||
@patch("health_weight.utils.health_weight_crud." "get_all_health_weight_by_user_id")
|
||||
@patch("health_weight.utils.calculate_bmi")
|
||||
@patch("health.health_weight.utils.health_weight_crud.edit_health_weight")
|
||||
@patch(
|
||||
"health.health_weight.utils.health_weight_crud."
|
||||
"get_all_health_weight_by_user_id"
|
||||
)
|
||||
@patch("health.health_weight.utils.calculate_bmi")
|
||||
def test_calculate_bmi_all_user_entries_success(
|
||||
self, mock_calculate_bmi, mock_get_all, mock_edit
|
||||
):
|
||||
@@ -206,7 +209,10 @@ class TestCalculateBMIAllUserEntries:
|
||||
assert mock_calculate_bmi.call_count == 2
|
||||
assert mock_edit.call_count == 2
|
||||
|
||||
@patch("health_weight.utils.health_weight_crud." "get_all_health_weight_by_user_id")
|
||||
@patch(
|
||||
"health.health_weight.utils.health_weight_crud."
|
||||
"get_all_health_weight_by_user_id"
|
||||
)
|
||||
def test_calculate_bmi_all_user_entries_no_entries(self, mock_get_all):
|
||||
"""
|
||||
Test BMI calculation when user has no entries.
|
||||
@@ -222,7 +228,10 @@ class TestCalculateBMIAllUserEntries:
|
||||
# Assert
|
||||
mock_get_all.assert_called_once_with(user_id, mock_db)
|
||||
|
||||
@patch("health_weight.utils.health_weight_crud." "get_all_health_weight_by_user_id")
|
||||
@patch(
|
||||
"health.health_weight.utils.health_weight_crud."
|
||||
"get_all_health_weight_by_user_id"
|
||||
)
|
||||
def test_calculate_bmi_all_user_entries_empty_list(self, mock_get_all):
|
||||
"""
|
||||
Test BMI calculation when user has empty list of entries.
|
||||
@@ -238,9 +247,12 @@ class TestCalculateBMIAllUserEntries:
|
||||
# Assert
|
||||
mock_get_all.assert_called_once_with(user_id, mock_db)
|
||||
|
||||
@patch("health_weight.utils.health_weight_crud.edit_health_weight")
|
||||
@patch("health_weight.utils.health_weight_crud." "get_all_health_weight_by_user_id")
|
||||
@patch("health_weight.utils.calculate_bmi")
|
||||
@patch("health.health_weight.utils.health_weight_crud.edit_health_weight")
|
||||
@patch(
|
||||
"health.health_weight.utils.health_weight_crud."
|
||||
"get_all_health_weight_by_user_id"
|
||||
)
|
||||
@patch("health.health_weight.utils.calculate_bmi")
|
||||
def test_calculate_bmi_all_user_entries_with_all_fields(
|
||||
self, mock_calculate_bmi, mock_get_all, mock_edit
|
||||
):
|
||||
|
||||
Reference in New Issue
Block a user