Skip to content

Commit

Permalink
FS-4919 - Moving round forms tests out of general test_routes and mov…
Browse files Browse the repository at this point in the history
…ing general test_routes under tests/blueprints/index
  • Loading branch information
wjrm500 committed Dec 24, 2024
1 parent 515a07a commit a89797c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 28 deletions.
27 changes: 0 additions & 27 deletions tests/test_routes.py → tests/blueprints/index/test_routes.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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)

0 comments on commit a89797c

Please sign in to comment.