forked from MrBin99/django-vite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add customizable app_client_class config value
- Loading branch information
Showing
6 changed files
with
124 additions
and
36 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
Empty file.
Empty file.
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,72 @@ | ||
import pytest | ||
|
||
from django_vite.core.asset_loader import ( | ||
DjangoViteAppClient, | ||
DjangoViteAssetLoader, | ||
ManifestClient, | ||
) | ||
|
||
|
||
def mock_get_manifest_from_url(): | ||
""" | ||
Pretend that we're fetching manifest.json from an external source. | ||
""" | ||
return { | ||
"src/mock_external_entry.js": { | ||
"css": ["assets/entry-0ed1a6fd.css"], | ||
"file": "assets/entry-5c085aac.js", | ||
"isEntry": True, | ||
"src": "entry.js", | ||
}, | ||
"src/mock_external_entry.css": { | ||
"file": "assets/entry-0ed1a6fd.css", | ||
"src": "entry.css", | ||
}, | ||
} | ||
|
||
|
||
class CustomManifestClient(ManifestClient): | ||
""" | ||
Custom ManifestClient that loads manifest.json from an external source. | ||
""" | ||
|
||
def load_manifest(self): | ||
return mock_get_manifest_from_url() | ||
|
||
|
||
class CustomAppClient(DjangoViteAppClient): | ||
""" | ||
Custom AppClient with a Custom ManifestClient. | ||
""" | ||
|
||
ManifestClient = CustomManifestClient | ||
|
||
|
||
def test_app_client_class(patch_settings): | ||
patch_settings( | ||
{ | ||
"DJANGO_VITE": { | ||
"default": { | ||
"app_client_class": "tests.tests.test_custom_app_client_class.CustomAppClient", | ||
} | ||
} | ||
} | ||
) | ||
DjangoViteAssetLoader._instance = None | ||
assert ( | ||
"src/mock_external_entry.js" | ||
in DjangoViteAssetLoader.instance()._apps["default"].manifest._entries | ||
) | ||
|
||
|
||
def test_invalid_app_client_class(patch_settings): | ||
with pytest.raises(ModuleNotFoundError): | ||
patch_settings( | ||
{ | ||
"DJANGO_VITE": { | ||
"default": { | ||
"app_client_class": "django_vite.invalid.CustomAppClient", | ||
} | ||
} | ||
} | ||
) |
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