瀏覽代碼

Create basic test to get host from link

pull/3011/head
Matheus Felipe 2 年之前
父節點
當前提交
ef8c4f04e5
沒有發現已知的金鑰在資料庫的簽署中 GPG 金鑰 ID: AA785C523274872F
共有 1 個檔案被更改,包括 23 行新增0 行删除
  1. +23
    -0
      scripts/tests/test_validate_links.py

+ 23
- 0
scripts/tests/test_validate_links.py 查看文件

@@ -3,6 +3,7 @@
import unittest

from validate.links import find_links_in_text
from validate.links import get_host_from_link


class TestValidateLinks(unittest.TestCase):
@@ -42,3 +43,25 @@ class TestValidateLinks(unittest.TestCase):
find_links_in_text()
find_links_in_text(1)
find_links_in_text(True)
def test_get_host_from_link(self):
links = [
'example.com',
'https://example.com',
'https://www.example.com',
'https://www.example.com.br',
'https://www.example.com/route',
'https://www.example.com?p=1&q=2',
'https://www.example.com#anchor'
]

for link in links:
host = get_host_from_link(link)

with self.subTest():
self.assertIsInstance(host, str)

self.assertNotIn('://', host)
self.assertNotIn('/', host)
self.assertNotIn('?', host)
self.assertNotIn('#', host)

Loading…
取消
儲存