-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests to achieve 100% Test Coverage (#91)
* create patch_settings fixture * 100% test coverage --------- Co-authored-by: Ben Beecher <[email protected]> Co-authored-by: Eddy Brown <[email protected]> Co-authored-by: Thijs Kramer <[email protected]> Co-authored-by: Niicck <[email protected]>
- Loading branch information
1 parent
b9c94ad
commit 5cf2c06
Showing
21 changed files
with
819 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class DjangoViteManifestError(RuntimeError): | ||
"""Manifest parsing failed.""" | ||
|
||
pass | ||
|
||
|
||
class DjangoViteAssetNotFoundError(RuntimeError): | ||
"""Vite Asset could not be found.""" | ||
|
||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from typing import Dict, Any | ||
import pytest | ||
from importlib import reload | ||
from django.apps import apps | ||
from django_vite.templatetags import django_vite | ||
|
||
|
||
def reload_django_vite(): | ||
reload(django_vite) | ||
django_vite_app_config = apps.get_app_config("django_vite") | ||
django_vite_app_config.ready() | ||
|
||
|
||
@pytest.fixture() | ||
def patch_settings(settings): | ||
""" | ||
1. Patch new settings into django.conf.settings. | ||
2. Reload django_vite module so that variables on the module level that use settings | ||
get recalculated. | ||
3. Restore the original settings once the test is over. | ||
TODO: refactor django_vite so that we don't set variables on the module level using | ||
settings. | ||
""" | ||
__PYTEST_EMPTY__ = "__PYTEST_EMPTY__" | ||
original_settings_cache = {} | ||
|
||
def _patch_settings(new_settings: Dict[str, Any]): | ||
for key, value in new_settings.items(): | ||
original_settings_cache[key] = getattr(settings, key, __PYTEST_EMPTY__) | ||
setattr(settings, key, value) | ||
reload_django_vite() | ||
|
||
yield _patch_settings | ||
|
||
for key, value in original_settings_cache.items(): | ||
if value == __PYTEST_EMPTY__: | ||
delattr(settings, key) | ||
else: | ||
setattr(settings, key, value) | ||
reload_django_vite() | ||
|
||
|
||
@pytest.fixture() | ||
def dev_mode_off(patch_settings): | ||
patch_settings({"DJANGO_VITE_DEV_MODE": False}) |
24 changes: 24 additions & 0 deletions
24
tests/data/staticfiles/custom-motif-polyfills-manifest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"../../vite/custom-motif-legacy": { | ||
"file": "assets/polyfills-legacy-6e7a4b9c.js", | ||
"isEntry": true, | ||
"src": "../../vite/custom-motif-legacy" | ||
}, | ||
"src/entry-legacy.ts": { | ||
"file": "assets/entry-legacy-4c50596f.js", | ||
"isEntry": true, | ||
"src": "src/entry-legacy.ts" | ||
}, | ||
"src/entry.css": { | ||
"file": "assets/entry-5e7d9c21.css", | ||
"src": "src/entry.css" | ||
}, | ||
"src/entry.ts": { | ||
"css": [ | ||
"assets/entry-5e7d9c21.css" | ||
], | ||
"file": "assets/entry-8a2f6b3d.js", | ||
"isEntry": true, | ||
"src": "src/entry.ts" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
{ | ||
"src/entry.ts": { | ||
"css": ["assets/entry-74d0d5dd.css"], | ||
"file": "assets/entry-29e38a60.js", | ||
"imports": [ | ||
"_vue.esm-bundler-96356fb1.js", | ||
"_index-62f37ad0.js", | ||
"_vue.esm-bundler-49e6b475.js", | ||
"__plugin-vue_export-helper-c27b6911.js", | ||
"_messages-a0a9e13b.js", | ||
"_use-outside-click-224980bf.js", | ||
"_use-resolve-button-type-c5656cba.js", | ||
"_use-event-listener-153dc639.js", | ||
"_hidden-84ddb9a5.js", | ||
"_apiClient-01d20438.js", | ||
"_pinia-5d7892fd.js" | ||
], | ||
"isEntry": true, | ||
"src": "entry.ts" | ||
}, | ||
"src/entry.css": { | ||
"file": "assets/entry-74d0d5dd.css", | ||
"src": "entry.css" | ||
}, | ||
"src/extra.css": { | ||
"file": "assets/extra-a9f3b2c1.css", | ||
"src": "extra.css" | ||
}, | ||
"_vue.esm-bundler-96356fb1.js": { | ||
"file": "vue.esm-bundler-96356fb1.js" | ||
}, | ||
"_index-62f37ad0.js": { | ||
"file": "index-62f37ad0.js", | ||
"imports": ["_vue.esm-bundler-49e6b475.js"] | ||
}, | ||
"_vue.esm-bundler-49e6b475.js": { | ||
"file": "vue.esm-bundler-49e6b475.js", | ||
"imports": ["_vue.esm-bundler-96356fb1.js"] | ||
}, | ||
"__plugin-vue_export-helper-c27b6911.js": { | ||
"file": "_plugin-vue_export-helper-c27b6911.js" | ||
}, | ||
"_messages-a0a9e13b.js": { | ||
"css": ["assets/extra-a9f3b2c1.css"], | ||
"file": "messages-a0a9e13b.js", | ||
"imports": ["_pinia-5d7892fd.js", "_vue.esm-bundler-96356fb1.js"] | ||
}, | ||
"_pinia-5d7892fd.js": { | ||
"file": "pinia-5d7892fd.js", | ||
"imports": ["_vue.esm-bundler-96356fb1.js"] | ||
}, | ||
"_use-outside-click-224980bf.js": { | ||
"file": "use-outside-click-224980bf.js", | ||
"imports": ["_vue.esm-bundler-96356fb1.js"] | ||
}, | ||
"_use-resolve-button-type-c5656cba.js": { | ||
"file": "use-resolve-button-type-c5656cba.js", | ||
"imports": ["_vue.esm-bundler-96356fb1.js", "_use-outside-click-224980bf.js"] | ||
}, | ||
"_use-event-listener-153dc639.js": { | ||
"file": "use-event-listener-153dc639.js", | ||
"imports": ["_vue.esm-bundler-96356fb1.js", "_use-outside-click-224980bf.js"] | ||
}, | ||
"_hidden-84ddb9a5.js": { | ||
"file": "hidden-84ddb9a5.js", | ||
"imports": ["_vue.esm-bundler-96356fb1.js", "_use-outside-click-224980bf.js"] | ||
}, | ||
"_apiClient-01d20438.js": { | ||
"css": ["assets/extra-a9f3b2c1.css"], | ||
"file": "apiClient-01d20438.js" | ||
} | ||
} |
Oops, something went wrong.