From d4123dcd9c784956efa6c9a88260bc423cf03224 Mon Sep 17 00:00:00 2001 From: Dylan Verheul Date: Sun, 12 Dec 2021 14:36:44 +0100 Subject: [PATCH] Move url tests and reformat --- tests/test_urls_valid.py | 36 ------------------------------------ 1 file changed, 36 deletions(-) delete mode 100644 tests/test_urls_valid.py diff --git a/tests/test_urls_valid.py b/tests/test_urls_valid.py deleted file mode 100644 index b2b6c94c..00000000 --- a/tests/test_urls_valid.py +++ /dev/null @@ -1,36 +0,0 @@ -from base64 import b64decode -import hashlib -import logging -import urllib.request - -from django.test import TestCase -from django_bootstrap5.core import get_bootstrap_setting - -class UrlValidityTestCase(TestCase): - def test_get_bootstrap_setting(self): - """ Tests that it's possible to pull the URLs listed in the settings, and the hashes match. """ - - logger = logging.getLogger(__name__) - - jsurl = get_bootstrap_setting("javascript_url") - cssurl = get_bootstrap_setting("css_url") - - for link in (jsurl, cssurl): - req = urllib.request.Request(url=link.get("url"), method='GET') - - hashtype, hash = link.get("integrity").split("-") - - # Test that it's a valid hash type - self.assertTrue(hasattr(hashlib, hashtype)) - - with urllib.request.urlopen(req) as request: - logger.debug(f"Status for {link.get('url')}: {request.status}") - - # Test that we're getting a "valid" response code from the specified URL - self.assertLess(request.status,400) - - # Test that the integrity hash matches - hasher = hashlib.new(hashtype, request.read()) - - self.assertEqual(hasher.digest(), b64decode(hash)) -