55import pytest
66from mongoengine import fields as base_fields
77from pytest_mock import MockerFixture
8- from wtforms import validators as wtf_validators_
98
109from flask_mongoengine import db_fields , documents
1110
11+ try :
12+ from wtforms import validators as wtf_validators_
13+
14+ wtforms_not_installed = False
15+ except ImportError :
16+ wtf_validators_ = None
17+ wtforms_not_installed = True
18+
1219
1320@pytest .fixture
1421def local_app (app ):
@@ -44,6 +51,7 @@ class Model(request.param):
4451
4552 return Model
4653
54+ @pytest .mark .skipif (condition = wtforms_not_installed , reason = "No WTF CI/CD chain" )
4755 def test__get_fields_names__is_called_by_to_wtf_form_call (
4856 self , TempDocument , mocker : MockerFixture
4957 ):
@@ -79,6 +87,7 @@ def test__to_wtf_form__is_called_by_mixin_child_model(
7987 TempDocument .to_wtf_form ()
8088 to_wtf_spy .assert_called_once ()
8189
90+ @pytest .mark .skipif (condition = wtforms_not_installed , reason = "No WTF CI/CD chain" )
8291 def test__to_wtf_form__logs_error (self , caplog , TempDocument ):
8392 TempDocument .to_wtf_form ()
8493
@@ -225,6 +234,7 @@ def test__wtf_field_class__return__user_provided_value__if_set(self):
225234
226235 assert issubclass (field .wtf_field_class , str )
227236
237+ @pytest .mark .skipif (condition = wtforms_not_installed , reason = "No WTF CI/CD chain" )
228238 @pytest .mark .parametrize (
229239 ["user_dict" , "expected_result" ],
230240 [
@@ -245,6 +255,7 @@ def test__wtf_field_options__overwrite_generated_options_with_user_provided(
245255 field = db_fields .WtfFieldMixin (wtf_options = user_dict )
246256 assert field .wtf_field_options == expected_result
247257
258+ @pytest .mark .skipif (condition = wtforms_not_installed , reason = "No WTF CI/CD chain" )
248259 def test__wtf_generated_options__correctly_retrieve_label_from_parent_class (self ):
249260 """Test based on base class for all fields."""
250261 default_call = self .WTFieldBaseMRO ()
@@ -254,6 +265,7 @@ def test__wtf_generated_options__correctly_retrieve_label_from_parent_class(self
254265 assert default_call .wtf_generated_options ["label" ] == "set not by init"
255266 assert with_option_call .wtf_generated_options ["label" ] == "fake"
256267
268+ @pytest .mark .skipif (condition = wtforms_not_installed , reason = "No WTF CI/CD chain" )
257269 def test__wtf_generated_options__correctly_retrieve_description_from_parent_class (
258270 self ,
259271 ):
@@ -263,13 +275,15 @@ def test__wtf_generated_options__correctly_retrieve_description_from_parent_clas
263275 assert default_call .wtf_generated_options ["description" ] == ""
264276 assert with_option_call .wtf_generated_options ["description" ] == "fake"
265277
278+ @pytest .mark .skipif (condition = wtforms_not_installed , reason = "No WTF CI/CD chain" )
266279 def test__wtf_generated_options__correctly_retrieve_default_from_parent_class (self ):
267280 default_call = self .WTFieldBaseMRO ()
268281 with_option_call = self .WTFieldBaseMRO (default = "fake" )
269282
270283 assert default_call .wtf_generated_options ["default" ] is None
271284 assert with_option_call .wtf_generated_options ["default" ] == "fake"
272285
286+ @pytest .mark .skipif (condition = wtforms_not_installed , reason = "No WTF CI/CD chain" )
273287 def test__wtf_generated_options__correctly_retrieve_validators_from_parent_class__and__add_optional_validator__if_field_not_required (
274288 self ,
275289 ):
@@ -286,6 +300,7 @@ def test__wtf_generated_options__correctly_retrieve_validators_from_parent_class
286300 wtf_validators_ .Optional ,
287301 )
288302
303+ @pytest .mark .skipif (condition = wtforms_not_installed , reason = "No WTF CI/CD chain" )
289304 def test__wtf_generated_options__correctly_retrieve_validators_from_parent_class__and__add_required__if_field_required (
290305 self ,
291306 ):
@@ -302,13 +317,15 @@ def test__wtf_generated_options__correctly_retrieve_validators_from_parent_class
302317 wtf_validators_ .InputRequired ,
303318 )
304319
320+ @pytest .mark .skipif (condition = wtforms_not_installed , reason = "No WTF CI/CD chain" )
305321 def test__wtf_generated_options__correctly_retrieve_filters_from_parent_class (self ):
306322 default_call = self .WTFieldBaseMRO ()
307323 with_option_call = self .WTFieldBaseMRO (wtf_filters = [str , list ])
308324
309325 assert default_call .wtf_generated_options ["filters" ] == []
310326 assert with_option_call .wtf_generated_options ["filters" ] == [str , list ]
311327
328+ @pytest .mark .skipif (condition = wtforms_not_installed , reason = "No WTF CI/CD chain" )
312329 def test__wtf_generated_options__correctly_handle_choices_settings (self ):
313330 default_call = self .WTFieldBaseMRO (choices = [1 , 2 ])
314331 with_option_call = self .WTFieldBaseMRO (choices = [1 , 2 ], wtf_choices_coerce = list )
@@ -318,6 +335,7 @@ def test__wtf_generated_options__correctly_handle_choices_settings(self):
318335 assert with_option_call .wtf_generated_options ["choices" ] == [1 , 2 ]
319336 assert with_option_call .wtf_generated_options ["coerce" ] is list
320337
338+ @pytest .mark .skipif (condition = wtforms_not_installed , reason = "No WTF CI/CD chain" )
321339 def test__to_wtf_field__does_not_modify_anything_if_options_not_provided (self ):
322340 # Setting base validators to exclude patching of .wtf_generated_options()
323341 field = self .WTFieldBaseMRO (wtf_options = {"validators" : ["ignore" ]})
@@ -328,6 +346,7 @@ def test__to_wtf_field__does_not_modify_anything_if_options_not_provided(self):
328346
329347 field .DEFAULT_WTF_FIELD .assert_called_with (** field_options )
330348
349+ @pytest .mark .skipif (condition = wtforms_not_installed , reason = "No WTF CI/CD chain" )
331350 def test__to_wtf_field__update_field_class_if_related_option_provided (self ):
332351 # Setting base validators to exclude patching of .wtf_generated_options()
333352 will_be_called = Mock ()
@@ -340,6 +359,7 @@ def test__to_wtf_field__update_field_class_if_related_option_provided(self):
340359 will_not_be_called .assert_not_called ()
341360 will_be_called .assert_called_with (** field_options )
342361
362+ @pytest .mark .skipif (condition = wtforms_not_installed , reason = "No WTF CI/CD chain" )
343363 def test__to_wtf_field__update_field_kwargs_if_related_option_provided (self ):
344364 # Setting base validators to exclude patching of .wtf_generated_options()
345365 will_be_called = Mock ()
0 commit comments