-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathtest_validator.py
43 lines (36 loc) · 1.18 KB
/
test_validator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""Tests for the uritemplate.Validator class."""
import uritemplate
from uritemplate import exceptions
import pytest
@pytest.mark.parametrize('template', [
'https://github.com{/user}',
'https://github.com/sigmavirus24{/repository}',
'{foo}',
'?{bar}',
'https://example.com',
])
def test_valid_uris(template):
"""Verify we don't raise an exception."""
urit = uritemplate.URITemplate(template)
uritemplate.Validator().validate(urit)
@pytest.mark.parametrize('template', [
'https://github.com{/user',
'https://github.com/sigmavirus24/repository}',
'{foo}}',
'?{{bar}',
])
def test_invalid_uris(template):
"""Verify we catch invalid URITemplates."""
urit = uritemplate.URITemplate(template)
with pytest.raises(exceptions.InvalidTemplate):
uritemplate.Validator().validate(urit)
@pytest.mark.parametrize('template', [
'https://github.com{/user',
'https://github.com/sigmavirus24/repository}',
'{foo}}',
'?{{bar}',
])
def test_allow_invalid_uris(template):
"""Verify we allow invalid URITemplates."""
urit = uritemplate.URITemplate(template)
uritemplate.Validator().allow_unbalanced_braces().validate(urit)