bookwyrm/bookwyrm/tests/test_utils.py

27 lines
783 B
Python
Raw Normal View History

2022-07-06 22:07:46 +00:00
""" test searching for books """
import re
from django.test import TestCase
from bookwyrm.settings import BASE_URL
2022-07-06 22:07:46 +00:00
from bookwyrm.utils import regex
2022-12-30 16:55:47 +00:00
from bookwyrm.utils.validate import validate_url_domain
2022-07-06 22:07:46 +00:00
class TestUtils(TestCase):
"""utility functions"""
def test_regex(self):
"""Regexes used throughout the app"""
self.assertTrue(re.match(regex.DOMAIN, "xn--69aa8bzb.xn--y9a3aq"))
2022-12-30 16:55:47 +00:00
def test_valid_url_domain(self):
"""Check with a valid URL"""
legit = f"{BASE_URL}/legit-book-url/"
self.assertEqual(validate_url_domain(legit), legit)
2022-12-30 16:55:47 +00:00
def test_invalid_url_domain(self):
"""Check with an invalid URL"""
self.assertIsNone(
validate_url_domain("https://up-to-no-good.tld/bad-actor.exe")
2022-12-30 16:55:47 +00:00
)