Skip to content

Commit 492e74e

Browse files
committed
test: Add tests for dandi.utils.is_url
1 parent 352e85e commit 492e74e

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

dandi/tests/test_utils.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
get_utcnow_datetime,
3030
is_page2_url,
3131
is_same_time,
32+
is_url,
3233
on_windows,
3334
post_upload_size_check,
3435
under_paths,
@@ -589,3 +590,67 @@ def test_post_upload_size_check_erroring(
589590
logging.ERROR,
590591
f"Size of {p} was 42 at start of upload but is now 19 after upload",
591592
) in caplog.record_tuples
593+
594+
595+
class TestIsUrl:
596+
@pytest.mark.parametrize(
597+
"s",
598+
[
599+
# Standard valid HTTP/FTP URLs
600+
"http://example.com",
601+
"https://example.com",
602+
"https://example.com/path",
603+
"https://example.com/path?query=1#frag",
604+
"https://example.com:8443/path",
605+
"http://127.0.0.1:8000",
606+
"ftp://example.com/path/file.txt",
607+
"ftp://user:pass@example.com/dir",
608+
# These pass pydantic validation but are not very useful URLs
609+
"http:/example.com",
610+
# Typical DANDI Archive dandiset URLs (also valid HTTP URLs)
611+
"https://dandiarchive.org/dandiset/000027",
612+
"https://dandiarchive.org/dandiset/000027/draft",
613+
"https://dandiarchive.org/dandiset/000027/0.210428.2206",
614+
# DANDI identifiers and ids
615+
"DANDI:123456",
616+
"DANDI:123456/draft",
617+
"DANDI:123456/1.123456.1234",
618+
"DANDI-SANDBOX:123456",
619+
"DANDI-SANDBOX:123456/draft",
620+
"DANDI-SANDBOX:123456/1.123456.1234",
621+
# Customized DANDI URLs
622+
"dandi://dandi/123456",
623+
"dandi://dandi/123456/draft",
624+
"dandi://dandi/123456/1.123456.1234",
625+
"dandi://dandi-sandbox/123456",
626+
"dandi://dandi-sandbox/123456/draft",
627+
"dandi://dandi-sandbox/123456/1.123456.1234",
628+
],
629+
)
630+
def test_valid_urls(self, s: str) -> None:
631+
assert is_url(s) is True
632+
633+
@pytest.mark.parametrize(
634+
"s",
635+
[
636+
# Clearly invalid URLs
637+
"not a url",
638+
"example",
639+
"example .com",
640+
"://example.com",
641+
"",
642+
" ",
643+
# DANDI-like string that should not be treated as a valid DANDI URL
644+
"dandi://not-a-real-dandiset",
645+
# Invalid DANDI identifiers and ids because of unknown instance name
646+
"FAKEDANDI:123456",
647+
"FAKEDANDI:123456/draft",
648+
"FAKEDANDI:123456/1.123456.1234",
649+
# Customized DANDI URLs
650+
"dandi://fakedandi/123456",
651+
"dandi://fakedandi/123456/draft",
652+
"dandi://fakedandi/123456/1.123456.1234",
653+
],
654+
)
655+
def test_invalid_urls(self, s: str) -> None:
656+
assert is_url(s) is False

0 commit comments

Comments
 (0)