"""Tests for API utils.""" from backend.constants import api as api_consts from backend.constants import error as error_consts from backend.utils import api as api_utils def test_create_get_list_response(): """Test create_get_list_response.""" items = [{}, {}, {}] response = api_utils.create_get_list_response(items) resp_items = response.message[api_consts.ITEMS] resp_pagination = response.message[api_consts.PAGINATION] assert resp_items == items assert resp_pagination == { 'type': api_consts.PAGINATION_TYPE_NONE, 'total_records': 3 } def test_create_validation_error_response(): """Test create_validation_error_response.""" response = api_utils.create_validation_error_response() assert response.errors['code'] == error_consts.VALIDATION_ERROR_CODE assert response.errors['message'] == error_consts.VALIDATION_ERROR_MSG assert response.message is None def test_create_validation_error_custom_msg_response(): """Test create_validation_error_response with custom message.""" msg = 'Meow' response = api_utils.create_validation_error_response(message=msg) assert response.errors['code'] == error_consts.VALIDATION_ERROR_CODE assert response.errors['message'] == msg assert response.message is None