1# -*- coding: utf-8 -*-
2import pytest
3
4import validators
5
6
7@pytest.mark.parametrize(('value', 'min', 'max'), [
8    ('password', 2, 10),
9    ('password', None, 10),
10    ('password', 2, None),
11    ('password', 8, 8)
12])
13def test_returns_true_on_valid_length(value, min, max):
14    assert validators.length(value, min=min, max=max)
15
16
17@pytest.mark.parametrize(('value', 'min', 'max'), [
18    ('something', 13, 12),
19    ('something', -1, None),
20    ('something', -1, None),
21    ('something', -3, -2)
22])
23def test_raises_assertion_error_for_invalid_args(value, min, max):
24    with pytest.raises(AssertionError):
25        assert validators.length(value, min=min, max=max)
26
27
28@pytest.mark.parametrize(('value', 'min', 'max'), [
29    ('something', 13, 14),
30    ('something', None, 6),
31    ('something', 13, None)
32])
33def test_returns_failed_validation_on_invalid_range(value, min, max):
34    assert isinstance(
35        validators.length(value, min=min, max=max),
36        validators.ValidationFailure
37    )
38