@@ -692,3 +692,157 @@ def test_command_error_handling_decorator_edge_cases(self, settings: LazySetting
692
692
# Test with unknown command - should raise SystemExit or CommandError
693
693
with pytest .raises ((CommandError , SystemExit )):
694
694
call_command ("tailwind" , "nonexistent_command" )
695
+
696
+
697
+ class TestErrorSuggestionScenarios :
698
+ """Test error suggestion functions that provide user guidance."""
699
+
700
+ def test_suggest_command_error_solutions_staticfiles_dirs (self , capsys : CaptureFixture [str ]):
701
+ """Test error suggestions for STATICFILES_DIRS issues."""
702
+ from django_tailwind_cli .management .commands .tailwind import _suggest_command_error_solutions
703
+
704
+ _suggest_command_error_solutions ("Error: STATICFILES_DIRS is not configured properly" )
705
+
706
+ captured = capsys .readouterr ()
707
+ assert "💡 Solution:" in captured .out
708
+ assert "STATICFILES_DIRS" in captured .out
709
+ assert "BASE_DIR / 'assets'" in captured .out
710
+
711
+ def test_suggest_command_error_solutions_base_dir (self , capsys : CaptureFixture [str ]):
712
+ """Test error suggestions for BASE_DIR issues."""
713
+ from django_tailwind_cli .management .commands .tailwind import _suggest_command_error_solutions
714
+
715
+ _suggest_command_error_solutions ("Error: BASE_DIR is not properly configured" )
716
+
717
+ captured = capsys .readouterr ()
718
+ assert "💡 Solution:" in captured .out
719
+ assert "BASE_DIR" in captured .out
720
+ assert "Path(__file__).resolve().parent.parent" in captured .out
721
+
722
+ def test_suggest_command_error_solutions_tailwind_css_3x (self , capsys : CaptureFixture [str ]):
723
+ """Test error suggestions for Tailwind CSS 3.x issues."""
724
+ from django_tailwind_cli .management .commands .tailwind import _suggest_command_error_solutions
725
+
726
+ _suggest_command_error_solutions ("Error: Tailwind CSS 3.x is not supported" )
727
+
728
+ captured = capsys .readouterr ()
729
+ assert "💡 Solution:" in captured .out
730
+ assert "django-tailwind-cli v2.21.1" in captured .out
731
+ assert "Tailwind CSS 3.x" in captured .out
732
+
733
+ def test_suggest_command_error_solutions_version (self , capsys : CaptureFixture [str ]):
734
+ """Test error suggestions for version issues."""
735
+ from django_tailwind_cli .management .commands .tailwind import _suggest_command_error_solutions
736
+
737
+ _suggest_command_error_solutions ("Error: invalid version specified" )
738
+
739
+ captured = capsys .readouterr ()
740
+ assert "💡 Solution:" in captured .out
741
+ assert "TAILWIND_CLI_VERSION" in captured .out
742
+ assert "'latest'" in captured .out
743
+
744
+ def test_suggest_command_error_solutions_no_match (self , capsys : CaptureFixture [str ]):
745
+ """Test error suggestions when no specific match is found."""
746
+ from django_tailwind_cli .management .commands .tailwind import _suggest_command_error_solutions
747
+
748
+ _suggest_command_error_solutions ("Some random error message" )
749
+
750
+ captured = capsys .readouterr ()
751
+ # Should not print any suggestions for unknown errors
752
+ assert captured .out == ""
753
+
754
+ def test_suggest_file_error_solutions_file_not_found (self , capsys : CaptureFixture [str ]):
755
+ """Test file error suggestions for file not found issues."""
756
+ from django_tailwind_cli .management .commands .tailwind import _suggest_file_error_solutions
757
+
758
+ _suggest_file_error_solutions ("Error: file not found: /path/to/missing/file.css" )
759
+
760
+ captured = capsys .readouterr ()
761
+ assert "💡 Suggestions:" in captured .out
762
+ assert "CSS input file" in captured .out
763
+
764
+ def test_suggest_file_error_solutions_permission_denied (self , capsys : CaptureFixture [str ]):
765
+ """Test file error suggestions for permission issues."""
766
+ from django_tailwind_cli .management .commands .tailwind import _suggest_file_error_solutions
767
+
768
+ _suggest_file_error_solutions ("Error: permission denied accessing file" )
769
+
770
+ captured = capsys .readouterr ()
771
+ assert "💡 Suggestions:" in captured .out
772
+ assert "file path is correct" in captured .out
773
+
774
+ def test_suggest_file_error_solutions_directory_not_found (self , capsys : CaptureFixture [str ]):
775
+ """Test file error suggestions for directory issues."""
776
+ from django_tailwind_cli .management .commands .tailwind import _suggest_file_error_solutions
777
+
778
+ _suggest_file_error_solutions ("Error: directory not found or invalid" )
779
+
780
+ captured = capsys .readouterr ()
781
+ assert "💡 Suggestions:" in captured .out
782
+ assert "directory exists" in captured .out
783
+
784
+
785
+ class TestSetupCommandScenarios :
786
+ """Test the setup command functionality."""
787
+
788
+ def test_setup_command_import_error_handling (
789
+ self , settings : LazySettings , tmp_path : Path , capsys : CaptureFixture [str ]
790
+ ):
791
+ """Test setup command when django-tailwind-cli cannot be imported."""
792
+ settings .STATICFILES_DIRS = [tmp_path / "assets" ]
793
+
794
+ # Mock the import of __version__ within the setup function
795
+ with patch ("django_tailwind_cli.__version__" , side_effect = ImportError ):
796
+ call_command ("tailwind" , "setup" )
797
+
798
+ captured = capsys .readouterr ()
799
+ assert "django-tailwind-cli not found" in captured .out or "Installation Check" in captured .out
800
+
801
+ def test_setup_command_missing_staticfiles_dirs (self , settings : LazySettings , capsys : CaptureFixture [str ]):
802
+ """Test setup command when STATICFILES_DIRS is not configured."""
803
+ settings .STATICFILES_DIRS = []
804
+ settings .INSTALLED_APPS = ["django_tailwind_cli" ]
805
+
806
+ call_command ("tailwind" , "setup" )
807
+
808
+ captured = capsys .readouterr ()
809
+ assert "STATICFILES_DIRS not configured" in captured .out
810
+
811
+ def test_setup_command_configuration_error (
812
+ self , settings : LazySettings , tmp_path : Path , capsys : CaptureFixture [str ]
813
+ ):
814
+ """Test setup command when configuration loading fails."""
815
+ settings .STATICFILES_DIRS = [tmp_path / "assets" ]
816
+ settings .INSTALLED_APPS = ["django_tailwind_cli" ]
817
+
818
+ with patch (
819
+ "django_tailwind_cli.management.commands.tailwind.get_config" ,
820
+ side_effect = Exception ("Config error" ),
821
+ ):
822
+ call_command ("tailwind" , "setup" )
823
+
824
+ captured = capsys .readouterr ()
825
+ assert "Configuration error" in captured .out
826
+
827
+ def test_setup_command_success (self , settings : LazySettings , tmp_path : Path , capsys : CaptureFixture [str ]):
828
+ """Test successful setup command execution."""
829
+ settings .BASE_DIR = tmp_path
830
+ settings .STATICFILES_DIRS = [tmp_path / "assets" ]
831
+ settings .INSTALLED_APPS = ["django_tailwind_cli" ]
832
+
833
+ # Create the assets directory
834
+ (tmp_path / "assets" ).mkdir (parents = True , exist_ok = True )
835
+
836
+ # Mock the CLI download and subprocess operations to prevent hanging
837
+ with patch ("django_tailwind_cli.management.commands.tailwind._download_cli" ):
838
+ with patch ("subprocess.run" ) as mock_subprocess :
839
+ # Mock successful subprocess run
840
+ mock_result = Mock ()
841
+ mock_result .returncode = 0
842
+ mock_subprocess .return_value = mock_result
843
+
844
+ call_command ("tailwind" , "setup" )
845
+
846
+ captured = capsys .readouterr ()
847
+ assert "Django Tailwind CLI Setup Guide" in captured .out
848
+ assert "Configuration loaded successfully" in captured .out
0 commit comments