@@ -97,6 +97,72 @@ def test_get_version_with_official_repo_and_version_3(settings: SettingsWrapper)
9797 get_version ()
9898
9999
100+ def test_get_version_with_daisyui_enabled_latest (settings : SettingsWrapper , mocker : MockerFixture ):
101+ """Test that DaisyUI uses the correct repository and correctly parses version."""
102+ # Clear any existing cache
103+ from django_tailwind_cli .config import _get_cache_path
104+ from semver import Version
105+
106+ cache_path = _get_cache_path ()
107+ if cache_path .exists ():
108+ cache_path .unlink ()
109+
110+ settings .TAILWIND_CLI_USE_DAISY_UI = True
111+ settings .TAILWIND_CLI_VERSION = "latest"
112+
113+ # Mock successful redirect to a generic valid DaisyUI version
114+ test_version = "9.8.7"
115+ request_get = mocker .patch ("django_tailwind_cli.utils.http.fetch_redirect_location" )
116+ request_get .return_value = (
117+ True ,
118+ f"https://github.com/dobicinaitis/tailwind-cli-extra/releases/tag/v{ test_version } " ,
119+ )
120+
121+ r_version_str , r_version = get_version ()
122+
123+ # Test that version string is correctly extracted (without 'v' prefix)
124+ assert r_version_str == test_version
125+
126+ # Test that version is correctly parsed as semantic version
127+ assert isinstance (r_version , Version )
128+ assert str (r_version ) == test_version
129+
130+ # Verify the correct DaisyUI repository URL was used (not standard Tailwind)
131+ request_get .assert_called_once_with (
132+ "https://github.com/dobicinaitis/tailwind-cli-extra/releases/latest/" , timeout = 10
133+ )
134+
135+
136+ def test_get_version_with_daisyui_fallback_when_network_fails (settings : SettingsWrapper , mocker : MockerFixture ):
137+ """Test fallback behavior when DaisyUI is enabled but network request fails."""
138+ # Clear any existing cache
139+ from django_tailwind_cli .config import _get_cache_path , FALLBACK_VERSION
140+ from semver import Version
141+
142+ cache_path = _get_cache_path ()
143+ if cache_path .exists ():
144+ cache_path .unlink ()
145+
146+ settings .TAILWIND_CLI_USE_DAISY_UI = True
147+ settings .TAILWIND_CLI_VERSION = "latest"
148+
149+ # Mock failed network request
150+ request_get = mocker .patch ("django_tailwind_cli.utils.http.fetch_redirect_location" )
151+ request_get .return_value = (False , None )
152+
153+ r_version_str , r_version = get_version ()
154+
155+ # Should fall back to the configured fallback version
156+ assert r_version_str == FALLBACK_VERSION
157+ assert isinstance (r_version , Version )
158+ assert str (r_version ) == FALLBACK_VERSION
159+
160+ # Verify the correct DaisyUI repository URL was still used in the attempt
161+ request_get .assert_called_once_with (
162+ "https://github.com/dobicinaitis/tailwind-cli-extra/releases/latest/" , timeout = 10
163+ )
164+
165+
100166def test_get_version_with_unofficial_repo_and_version_3 (settings : SettingsWrapper ):
101167 settings .TAILWIND_CLI_VERSION = "3.4.13"
102168 settings .TAILWIND_CLI_SRC_REPO = "oliverandrich/my-tailwindcss-cli"
@@ -296,18 +362,25 @@ def test_daisy_ui_support(
296362 settings : SettingsWrapper ,
297363 mocker : MockerFixture ,
298364):
365+ from semver import Version
366+
299367 settings .TAILWIND_CLI_USE_DAISY_UI = True
368+ test_version = "7.6.5"
300369 request_get = mocker .patch ("django_tailwind_cli.utils.http.fetch_redirect_location" )
301- request_get .return_value = (True , "https://github.com/dobicinaitis/tailwind-cli-extra/releases/tag/v2.1.4" )
370+ request_get .return_value = (
371+ True ,
372+ f"https://github.com/dobicinaitis/tailwind-cli-extra/releases/tag/v{ test_version } " ,
373+ )
302374
303375 c = get_config ()
304376
377+ # Test DaisyUI configuration is properly applied
305378 assert c .use_daisy_ui
306379 assert "tailwindcss-extra" in str (c .cli_path )
307380 assert "dobicinaitis/tailwind-cli-extra" in c .download_url
308381
382+ # Test version parsing works correctly
309383 r_version_str , r_version = get_version ()
310- assert r_version_str == "2.1.4"
311- assert r_version .major == 2
312- assert r_version .minor == 1
313- assert r_version .patch == 4
384+ assert r_version_str == test_version
385+ assert isinstance (r_version , Version )
386+ assert str (r_version ) == test_version
0 commit comments