aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBobby <[email protected]>2022-11-27 12:07:34 -0500
committerBobby <[email protected]>2022-11-27 12:07:34 -0500
commitf5cb8a4d14c48f458039d608f6bd38bea13a881c (patch)
tree058eabbcdbca3bd98533e0130dc7e348a0ea460a /tests
parent3dfdd675e661f32f7373a521ad66ab56f637e0c4 (diff)
downloadedify-f5cb8a4d14c48f458039d608f6bd38bea13a881c.tar.xz
edify-f5cb8a4d14c48f458039d608f6bd38bea13a881c.zip
added url validator
Diffstat (limited to 'tests')
-rw-r--r--tests/test_url.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/test_url.py b/tests/test_url.py
new file mode 100644
index 0000000..d3acc78
--- /dev/null
+++ b/tests/test_url.py
@@ -0,0 +1,57 @@
+from edify.library import url
+
+urls = [
+ "example.com",
+ "www.example.com",
+ "www.example.com/path/to/file",
+ "http://www.example.com",
+ "http://example.com",
+ "http://www.example.com/path/to/page",
+ "https://example.com",
+ "https://www.example.com/",
+ "https://www.example.com/path/to/page",
+ "//example.com",
+]
+
+def test_all_protocols():
+ match_list = ["proto", "no_proto"]
+ expected = [True] * 9 + [False]
+ for uri, expectation in zip(urls, expected):
+ assert url(uri, match=match_list) == expectation
+
+def test_proto_only():
+ match_list = ["proto"]
+ expected = [False] * 3 + [True] * 6 + [False]
+ for uri, expectation in zip(urls, expected):
+ print(uri, expectation)
+ assert url(uri, match=match_list) == expectation
+
+def test_no_proto_only():
+ match_list = ["no_proto"]
+ expected = [True] * 3 + [False] * 7
+ for uri, expectation in zip(urls, expected):
+ assert url(uri, match=match_list) == expectation
+
+def test_invalid_protocol():
+ match_list = ["invalid"]
+ for uri in urls:
+ try:
+ url(uri, match=match_list)
+ except ValueError:
+ assert True
+
+def test_invalid_match_type():
+ match_list = "invalid"
+ for uri in urls:
+ try:
+ url(uri, match=match_list)
+ except TypeError:
+ assert True
+
+def test_empty_match_list():
+ match_list = []
+ for uri in urls:
+ try:
+ url(uri, match=match_list)
+ except ValueError:
+ assert True