-
Notifications
You must be signed in to change notification settings - Fork 2.9k
19615 append extra query params to static template tag #20455
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6491035
19615 append extra query params to static template tag
arthanson 6a3bd9a
19615 append extra query params to static template tag
arthanson c67355a
19615 log if duplicated params
arthanson ec365bf
19615 log if duplicated params
arthanson 0665146
19615 temp change for git
arthanson e5174bb
Merge branch 'main' into 19615-static-s3
arthanson afa2560
20542 update doc string
arthanson e283893
20542 add tests
arthanson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,48 @@ | ||
| from unittest.mock import patch | ||
|
|
||
| from django.test import TestCase, override_settings | ||
|
|
||
| from utilities.templatetags.builtins.tags import static_with_params | ||
|
|
||
|
|
||
| class StaticWithParamsTest(TestCase): | ||
| """ | ||
| Test the static_with_params template tag functionality. | ||
| """ | ||
|
|
||
| def test_static_with_params_basic(self): | ||
| """Test basic parameter appending to static URL.""" | ||
| result = static_with_params('test.js', v='1.0.0') | ||
| self.assertIn('test.js', result) | ||
| self.assertIn('v=1.0.0', result) | ||
|
|
||
| @override_settings(STATIC_URL='https://cdn.example.com/static/') | ||
| def test_static_with_params_existing_query_params(self): | ||
| """Test appending parameters to URL that already has query parameters.""" | ||
| # Mock the static() function to return a URL with existing query parameters | ||
| with patch('utilities.templatetags.builtins.tags.static') as mock_static: | ||
| mock_static.return_value = 'https://cdn.example.com/static/test.js?existing=param' | ||
|
|
||
| result = static_with_params('test.js', v='1.0.0') | ||
|
|
||
| # Should contain both existing and new parameters | ||
| self.assertIn('existing=param', result) | ||
| self.assertIn('v=1.0.0', result) | ||
| # Should not have double question marks | ||
| self.assertEqual(result.count('?'), 1) | ||
|
|
||
| @override_settings(STATIC_URL='https://cdn.example.com/static/') | ||
| def test_static_with_params_duplicate_parameter_warning(self): | ||
| """Test that a warning is logged when parameters conflict.""" | ||
| with patch('utilities.templatetags.builtins.tags.static') as mock_static: | ||
| mock_static.return_value = 'https://cdn.example.com/static/test.js?v=old_version' | ||
|
|
||
| with self.assertLogs('netbox.utilities.templatetags.tags', level='WARNING') as cm: | ||
| result = static_with_params('test.js', v='new_version') | ||
|
|
||
| # Check that warning was logged | ||
| self.assertIn("Parameter 'v' already exists", cm.output[0]) | ||
|
|
||
| # Check that new parameter value is used | ||
| self.assertIn('v=new_version', result) | ||
| self.assertNotIn('v=old_version', result) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.