-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Relative links source validation is tested
- Loading branch information
1 parent
30bbef0
commit bc298c2
Showing
3 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import argparse | ||
|
||
import pytest | ||
|
||
from cc2olx.validators.cli import LinkSourceValidator | ||
|
||
|
||
class TestLinkSourceValidator: | ||
""" | ||
Test link source validator. | ||
""" | ||
|
||
@pytest.mark.parametrize( | ||
"links_source", | ||
( | ||
"http://example.com", | ||
"http://example.com/", | ||
"https://example.com", | ||
"http://192.168.0.1", | ||
"http://192.168.0.1:8000/", | ||
"https://[2001:0db8:85a3::8a2e:0370:7334]/", | ||
) | ||
) | ||
def test_original_value_is_returned_if_it_is_valid(self, links_source: str) -> None: | ||
""" | ||
Test whether the validator returns original value it is valid. | ||
""" | ||
assert LinkSourceValidator()(links_source) == links_source | ||
|
||
@pytest.mark.parametrize( | ||
"links_source", | ||
( | ||
"ftp://example.com", | ||
"ws://example.com", | ||
"just_string", | ||
"http://192.168.0.1.9", | ||
"http://192.168.0.1:-56", | ||
"http://192.999.0.1", | ||
"https://m192.168.0.1", | ||
"https://2001:0db8:85a3::8a2e:0370:7334/", | ||
"https://[2001:db8:85a3::8a2e:0370:7334::]/", | ||
) | ||
) | ||
def test_wrong_values_are_detected(self, links_source) -> None: | ||
""" | ||
Test whether the validator raises an error if the value is invalid. | ||
""" | ||
with pytest.raises(argparse.ArgumentTypeError, match="Enter a valid URL."): | ||
LinkSourceValidator()(links_source) |