From a89797c6ed83f0a68ad4047bd829313d454a556e Mon Sep 17 00:00:00 2001 From: William May Date: Tue, 24 Dec 2024 01:17:14 +0000 Subject: [PATCH] FS-4919 - Moving round forms tests out of general test_routes and moving general test_routes under tests/blueprints/index --- tests/{ => blueprints/index}/test_routes.py | 27 ------------------- .../test_round.py => round/test_forms.py} | 26 +++++++++++++++++- 2 files changed, 25 insertions(+), 28 deletions(-) rename tests/{ => blueprints/index}/test_routes.py (67%) rename tests/blueprints/{fund_builder/forms/test_round.py => round/test_forms.py} (71%) diff --git a/tests/test_routes.py b/tests/blueprints/index/test_routes.py similarity index 67% rename from tests/test_routes.py rename to tests/blueprints/index/test_routes.py index 1bcabda0..88c10c3a 100644 --- a/tests/test_routes.py +++ b/tests/blueprints/index/test_routes.py @@ -1,31 +1,4 @@ -from unittest.mock import MagicMock - import pytest -from wtforms.validators import ValidationError - -from app.blueprints.round.forms import validate_json_field - - -@pytest.mark.parametrize("input_json_string", [(None), (""), ("{}"), (""), ("{}"), ('{"1":"2"}')]) -def test_validate_json_input_valid(input_json_string): - field = MagicMock() - field.data = input_json_string - validate_json_field(None, field) - - -@pytest.mark.parametrize( - "input_json_string, exp_error_msg", - [ - ('{"1":', "Expecting value: line 1 column 6 (char 5)]"), - ('{"1":"quotes not closed}', "Unterminated string starting at: line 1 column 6 (char 5)"), - ], -) -def test_validate_json_input_invalid(input_json_string, exp_error_msg): - field = MagicMock() - field.data = input_json_string - with pytest.raises(ValidationError) as error: - validate_json_field(None, field) - assert exp_error_msg in str(error) def test_index_redirects_to_login_for_unauthenticated_user(flask_test_client): diff --git a/tests/blueprints/fund_builder/forms/test_round.py b/tests/blueprints/round/test_forms.py similarity index 71% rename from tests/blueprints/fund_builder/forms/test_round.py rename to tests/blueprints/round/test_forms.py index f977402e..6a195db2 100644 --- a/tests/blueprints/fund_builder/forms/test_round.py +++ b/tests/blueprints/round/test_forms.py @@ -1,7 +1,9 @@ +from unittest.mock import MagicMock + import pytest from wtforms.validators import ValidationError -from app.blueprints.round.forms import validate_flexible_url +from app.blueprints.round.forms import validate_flexible_url, validate_json_field class MockField: @@ -64,3 +66,25 @@ def test_validate_flexible_url_none_value(): """Test that None value is handled gracefully""" field = MockField(None) validate_flexible_url(None, field) # Should not raise any exception + + +@pytest.mark.parametrize("input_json_string", [(None), (""), ("{}"), (""), ("{}"), ('{"1":"2"}')]) +def test_validate_json_input_valid(input_json_string): + field = MagicMock() + field.data = input_json_string + validate_json_field(None, field) + + +@pytest.mark.parametrize( + "input_json_string, exp_error_msg", + [ + ('{"1":', "Expecting value: line 1 column 6 (char 5)]"), + ('{"1":"quotes not closed}', "Unterminated string starting at: line 1 column 6 (char 5)"), + ], +) +def test_validate_json_input_invalid(input_json_string, exp_error_msg): + field = MagicMock() + field.data = input_json_string + with pytest.raises(ValidationError) as error: + validate_json_field(None, field) + assert exp_error_msg in str(error)