"""Tests for validation module.""" from unittest import mock import pytest from oto import status as http_status from timed_release.constants import field_const from timed_release.validation import json_schema from timed_release.validation.schema import ( post_request_schema, put_product_schedule_ws, ) @pytest.fixture def valid_post_timed_release_body(): """Return valid POST and PUT timed release body. Returns: dict: Body dict. """ return { field_const.PRODUCT_ID: 1, field_const.TIME_OF_DAY_PRODUCT: '23:00:00', field_const.TIME_ZONE: 'GMT', field_const.STORE_IDS: [1, 2, 3]} def test_validate_body_success(monkeypatch, valid_post_timed_release_body): """Assert that validate_body succeeds when request body is valid.""" request = mock.Mock() request.get_json.return_value = valid_post_timed_release_body @json_schema.validate_body(request, post_request_schema.schema) def handler_method(): return 'test_result' assert 'test_result' == handler_method() @pytest.mark.parametrize( 'description, invalid_request_body, validation_schema', [ ('Time_of_day_product missing', {'product_id': 1, 'time_of_day_product': '', 'time_zone': 'local', 'store_ids': [286]}, post_request_schema.schema), ('Invalid time', {'product_id': 1, 'time_of_day_product': '80:10:00', 'time_zone': 'local', 'store_ids': [286]}, post_request_schema.schema), ('Store_id has negative value', { 'product_id': 1, 'time_of_day_product': '10:10:00', 'time_zone': 'local', 'store_ids': [-1]}, post_request_schema.schema), ('Time Zone with other than local or GMT', { 'product_id': 1, 'time_of_day_product': '10:10:00', 'time_zone': 'test', 'store_ids': [286]}, post_request_schema.schema), ('Invalid product id', { 'product_id': 'aaa', 'time_of_day_product': '10:10:00', 'time_zone': 'GMT', 'store_ids': [286]}, post_request_schema.schema), ('Invalid sales start datetime', { 'sales_start_datetime': '2025-12-09T08:00:00'}, put_product_schedule_ws.schema)]) def test_validate_body_failure( monkeypatch, description, invalid_request_body, validation_schema): """Assert that validate_body fails when request body is invalid.""" request = mock.Mock() request.get_json.return_value = invalid_request_body @json_schema.validate_body(request, validation_schema) def handler_method(): return 'test_result' assert http_status.BAD_REQUEST == handler_method(request).status_code