Exemple #1
0
 def test_any_field_dumps_enforce_type(self):
     field = AnyField(enforce_type=True)
     for value in [1, 1.2, True, "foo", object(), {}, []]:
         self.assertEqual(value, field.dumps(value))
Exemple #2
0
def test_no_enforce_variable_no_checks_variable_type(mocker):
    mock_check_type = mocker.patch('datastorm.fields.AnyField.check_type')
    field = AnyField(enforce_type=False)
    field.dumps("test")
    assert not mock_check_type.called
Exemple #3
0
def test_enforce_variable_incorrect_type_raises_value_error(mocker):
    mocker.patch('datastorm.fields.AnyField.check_type', return_value=False)
    field = AnyField(enforce_type=True)
    with pytest.raises(ValueError):
        field.dumps("test")
Exemple #4
0
def test_enforce_variable_checks_variable_type(mocker):
    mock_check_type = mocker.patch('datastorm.fields.AnyField.check_type',
                                   return_value=True)
    field = AnyField(enforce_type=True)
    field.dumps("test")
    assert mock_check_type.called