mirror of
https://github.com/django-components/django-components.git
synced 2025-08-31 11:17:21 +00:00
feat: add decorator for writing component tests (#1008)
* feat: add decorator for writing component tests * refactor: udpate changelog + update deps pins * refactor: fix deps * refactor: make cached_ref into generic and fix linter errors * refactor: fix coverage testing * refactor: use global var instead of env var for is_testing state
This commit is contained in:
parent
81ac59f7fb
commit
7dfcb447c4
62 changed files with 4428 additions and 3661 deletions
|
@ -2,9 +2,10 @@ import re
|
|||
from pathlib import Path
|
||||
|
||||
from django.contrib.staticfiles.management.commands.collectstatic import Command
|
||||
from django.test import SimpleTestCase, override_settings
|
||||
from django.test import SimpleTestCase
|
||||
|
||||
from .django_test_setup import setup_test_config
|
||||
from django_components.testing import djc_test
|
||||
from .testutils import setup_test_config
|
||||
|
||||
setup_test_config({"autodiscover": False})
|
||||
|
||||
|
@ -76,14 +77,16 @@ COMPONENTS = {
|
|||
|
||||
|
||||
class StaticFilesFinderTests(SimpleTestCase):
|
||||
@override_settings(
|
||||
**common_settings,
|
||||
COMPONENTS=COMPONENTS,
|
||||
STATICFILES_FINDERS=[
|
||||
# Default finders
|
||||
"django.contrib.staticfiles.finders.FileSystemFinder",
|
||||
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
|
||||
],
|
||||
@djc_test(
|
||||
django_settings={
|
||||
**common_settings,
|
||||
"STATICFILES_FINDERS": [
|
||||
# Default finders
|
||||
"django.contrib.staticfiles.finders.FileSystemFinder",
|
||||
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
|
||||
],
|
||||
},
|
||||
components_settings=COMPONENTS,
|
||||
)
|
||||
def test_python_and_html_included(self):
|
||||
collected = do_collect()
|
||||
|
@ -97,16 +100,18 @@ class StaticFilesFinderTests(SimpleTestCase):
|
|||
self.assertListEqual(collected["unmodified"], [])
|
||||
self.assertListEqual(collected["post_processed"], [])
|
||||
|
||||
@override_settings(
|
||||
**common_settings,
|
||||
COMPONENTS=COMPONENTS,
|
||||
STATICFILES_FINDERS=[
|
||||
# Default finders
|
||||
"django.contrib.staticfiles.finders.FileSystemFinder",
|
||||
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
|
||||
# Django components
|
||||
"django_components.finders.ComponentsFileSystemFinder",
|
||||
],
|
||||
@djc_test(
|
||||
django_settings={
|
||||
**common_settings,
|
||||
"STATICFILES_FINDERS": [
|
||||
# Default finders
|
||||
"django.contrib.staticfiles.finders.FileSystemFinder",
|
||||
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
|
||||
# Django components
|
||||
"django_components.finders.ComponentsFileSystemFinder",
|
||||
],
|
||||
},
|
||||
components_settings=COMPONENTS,
|
||||
)
|
||||
def test_python_and_html_omitted(self):
|
||||
collected = do_collect()
|
||||
|
@ -120,22 +125,24 @@ class StaticFilesFinderTests(SimpleTestCase):
|
|||
self.assertListEqual(collected["unmodified"], [])
|
||||
self.assertListEqual(collected["post_processed"], [])
|
||||
|
||||
@override_settings(
|
||||
**common_settings,
|
||||
COMPONENTS={
|
||||
@djc_test(
|
||||
django_settings={
|
||||
**common_settings,
|
||||
"STATICFILES_FINDERS": [
|
||||
# Default finders
|
||||
"django.contrib.staticfiles.finders.FileSystemFinder",
|
||||
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
|
||||
# Django components
|
||||
"django_components.finders.ComponentsFileSystemFinder",
|
||||
],
|
||||
},
|
||||
components_settings={
|
||||
**COMPONENTS,
|
||||
"static_files_allowed": [
|
||||
".js",
|
||||
],
|
||||
"static_files_forbidden": [],
|
||||
},
|
||||
STATICFILES_FINDERS=[
|
||||
# Default finders
|
||||
"django.contrib.staticfiles.finders.FileSystemFinder",
|
||||
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
|
||||
# Django components
|
||||
"django_components.finders.ComponentsFileSystemFinder",
|
||||
],
|
||||
)
|
||||
def test_set_static_files_allowed(self):
|
||||
collected = do_collect()
|
||||
|
@ -149,9 +156,18 @@ class StaticFilesFinderTests(SimpleTestCase):
|
|||
self.assertListEqual(collected["unmodified"], [])
|
||||
self.assertListEqual(collected["post_processed"], [])
|
||||
|
||||
@override_settings(
|
||||
**common_settings,
|
||||
COMPONENTS={
|
||||
@djc_test(
|
||||
django_settings={
|
||||
**common_settings,
|
||||
"STATICFILES_FINDERS": [
|
||||
# Default finders
|
||||
"django.contrib.staticfiles.finders.FileSystemFinder",
|
||||
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
|
||||
# Django components
|
||||
"django_components.finders.ComponentsFileSystemFinder",
|
||||
],
|
||||
},
|
||||
components_settings={
|
||||
**COMPONENTS,
|
||||
"static_files_allowed": [
|
||||
re.compile(r".*"),
|
||||
|
@ -160,13 +176,6 @@ class StaticFilesFinderTests(SimpleTestCase):
|
|||
re.compile(r"\.(?:js)$"),
|
||||
],
|
||||
},
|
||||
STATICFILES_FINDERS=[
|
||||
# Default finders
|
||||
"django.contrib.staticfiles.finders.FileSystemFinder",
|
||||
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
|
||||
# Django components
|
||||
"django_components.finders.ComponentsFileSystemFinder",
|
||||
],
|
||||
)
|
||||
def test_set_forbidden_files(self):
|
||||
collected = do_collect()
|
||||
|
@ -180,9 +189,18 @@ class StaticFilesFinderTests(SimpleTestCase):
|
|||
self.assertListEqual(collected["unmodified"], [])
|
||||
self.assertListEqual(collected["post_processed"], [])
|
||||
|
||||
@override_settings(
|
||||
**common_settings,
|
||||
COMPONENTS={
|
||||
@djc_test(
|
||||
django_settings={
|
||||
**common_settings,
|
||||
"STATICFILES_FINDERS": [
|
||||
# Default finders
|
||||
"django.contrib.staticfiles.finders.FileSystemFinder",
|
||||
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
|
||||
# Django components
|
||||
"django_components.finders.ComponentsFileSystemFinder",
|
||||
],
|
||||
},
|
||||
components_settings={
|
||||
**COMPONENTS,
|
||||
"static_files_allowed": [
|
||||
".js",
|
||||
|
@ -192,13 +210,6 @@ class StaticFilesFinderTests(SimpleTestCase):
|
|||
".js",
|
||||
],
|
||||
},
|
||||
STATICFILES_FINDERS=[
|
||||
# Default finders
|
||||
"django.contrib.staticfiles.finders.FileSystemFinder",
|
||||
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
|
||||
# Django components
|
||||
"django_components.finders.ComponentsFileSystemFinder",
|
||||
],
|
||||
)
|
||||
def test_set_both_allowed_and_forbidden_files(self):
|
||||
collected = do_collect()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue