|
9 | 9 |
|
10 | 10 | from django_bird.conf import DJANGO_BIRD_BUILTINS |
11 | 11 | from django_bird.conf import DJANGO_BIRD_FINDER |
12 | | -from django_bird.conf import AppSettings |
13 | 12 | from django_bird.conf import AutoConfigurator |
14 | 13 | from django_bird.conf import app_settings |
15 | 14 |
|
16 | 15 |
|
| 16 | +@pytest.fixture(autouse=True) |
| 17 | +def reset_settings(): |
| 18 | + template_options = settings.TEMPLATES[0]["OPTIONS"] |
| 19 | + |
| 20 | + assert DJANGO_BIRD_BUILTINS in template_options["builtins"] |
| 21 | + assert DJANGO_BIRD_FINDER in settings.STATICFILES_FINDERS |
| 22 | + |
| 23 | + with override_settings( |
| 24 | + STATICFILES_FINDERS=[ |
| 25 | + finder |
| 26 | + for finder in settings.STATICFILES_FINDERS |
| 27 | + if finder != DJANGO_BIRD_FINDER |
| 28 | + ], |
| 29 | + TEMPLATES=[ |
| 30 | + settings.TEMPLATES[0] |
| 31 | + | { |
| 32 | + **settings.TEMPLATES[0], |
| 33 | + "OPTIONS": { |
| 34 | + "builtins": [ |
| 35 | + builtin |
| 36 | + for builtin in template_options["builtins"] |
| 37 | + if builtin != DJANGO_BIRD_BUILTINS |
| 38 | + ], |
| 39 | + }, |
| 40 | + } |
| 41 | + ], |
| 42 | + ): |
| 43 | + options = settings.TEMPLATES[0]["OPTIONS"] |
| 44 | + |
| 45 | + assert DJANGO_BIRD_BUILTINS not in options["builtins"] |
| 46 | + assert DJANGO_BIRD_FINDER not in settings.STATICFILES_FINDERS |
| 47 | + |
| 48 | + yield |
| 49 | + |
| 50 | + |
17 | 51 | @pytest.mark.default_app_settings |
18 | 52 | def test_app_settings(): |
19 | 53 | assert app_settings.COMPONENT_DIRS == [] |
20 | 54 | assert app_settings.ENABLE_AUTO_CONFIG is True |
21 | 55 |
|
22 | 56 |
|
| 57 | +def test_autoconfigure_disabled(): |
| 58 | + template_options = settings.TEMPLATES[0]["OPTIONS"] |
| 59 | + |
| 60 | + with override_settings( |
| 61 | + DJANGO_BIRD={ |
| 62 | + "ENABLE_AUTO_CONFIG": False, |
| 63 | + } |
| 64 | + ): |
| 65 | + app_settings.autoconfigure() |
| 66 | + |
| 67 | + assert DJANGO_BIRD_BUILTINS not in template_options["builtins"] |
| 68 | + assert DJANGO_BIRD_FINDER not in settings.STATICFILES_FINDERS |
| 69 | + |
| 70 | + |
23 | 71 | class TestAutoConfigurator: |
24 | 72 | @pytest.fixture |
25 | 73 | def configurator(self): |
26 | 74 | return AutoConfigurator(app_settings) |
27 | 75 |
|
28 | | - @pytest.fixture(autouse=True) |
29 | | - def reset_settings(self): |
| 76 | + def test_autoconfigure(self, configurator): |
30 | 77 | template_options = settings.TEMPLATES[0]["OPTIONS"] |
31 | 78 |
|
| 79 | + configurator.autoconfigure() |
| 80 | + |
32 | 81 | assert DJANGO_BIRD_BUILTINS in template_options["builtins"] |
33 | 82 | assert DJANGO_BIRD_FINDER in settings.STATICFILES_FINDERS |
34 | 83 |
|
| 84 | + def test_non_django_template_engine(self, configurator): |
| 85 | + template_options = settings.TEMPLATES[0]["OPTIONS"] |
| 86 | + |
35 | 87 | with override_settings( |
36 | | - STATICFILES_FINDERS=[ |
37 | | - finder |
38 | | - for finder in settings.STATICFILES_FINDERS |
39 | | - if finder != DJANGO_BIRD_FINDER |
40 | | - ], |
41 | 88 | TEMPLATES=[ |
42 | | - settings.TEMPLATES[0] |
43 | | - | { |
44 | | - **settings.TEMPLATES[0], |
45 | | - "OPTIONS": { |
46 | | - "builtins": [ |
47 | | - builtin |
48 | | - for builtin in template_options["builtins"] |
49 | | - if builtin != DJANGO_BIRD_BUILTINS |
50 | | - ], |
51 | | - }, |
| 89 | + { |
| 90 | + "BACKEND": "django.template.backends.jinja2.Jinja2", |
52 | 91 | } |
53 | 92 | ], |
54 | 93 | ): |
55 | | - options = settings.TEMPLATES[0]["OPTIONS"] |
56 | | - |
57 | | - assert DJANGO_BIRD_BUILTINS not in options["builtins"] |
58 | | - assert DJANGO_BIRD_FINDER not in settings.STATICFILES_FINDERS |
59 | | - |
60 | | - yield |
61 | | - |
62 | | - def test_autoconfigure(self, configurator): |
63 | | - template_options = settings.TEMPLATES[0]["OPTIONS"] |
64 | | - |
65 | | - configurator.autoconfigure() |
66 | | - |
67 | | - assert DJANGO_BIRD_BUILTINS in template_options["builtins"] |
68 | | - assert DJANGO_BIRD_FINDER in settings.STATICFILES_FINDERS |
69 | | - |
70 | | - @override_settings( |
71 | | - DJANGO_BIRD={ |
72 | | - "ENABLE_AUTO_CONFIG": False, |
73 | | - } |
74 | | - ) |
75 | | - def test_autoconfigure_disabled(self): |
76 | | - app_settings = AppSettings() |
77 | | - template_options = settings.TEMPLATES[0]["OPTIONS"] |
| 94 | + configurator.configure_templates() |
78 | 95 |
|
79 | | - assert app_settings.ENABLE_AUTO_CONFIG is False |
80 | 96 | assert DJANGO_BIRD_BUILTINS not in template_options["builtins"] |
81 | | - assert DJANGO_BIRD_FINDER not in settings.STATICFILES_FINDERS |
82 | 97 |
|
83 | 98 | def test_configure_builtins(self, configurator): |
84 | 99 | template_options = settings.TEMPLATES[0]["OPTIONS"] |
|
0 commit comments