@@ -60,6 +60,37 @@ def test_simple(self):
6060 self .assertEqual (result [0 ], "remote_host" )
6161 self .assertEqual (result [1 ], "remote_port" )
6262
63+ def test_dir_with_files (self ):
64+ mock_file1 = MagicMock ()
65+ mock_file1 .is_file .return_value = True
66+ mock_file1 .is_dir .return_value = False
67+ mock_file1 .open .return_value .__enter__ .return_value .readlines .return_value = ["testhost1: remote_host1:remote_port1" ]
68+
69+ mock_file2 = MagicMock ()
70+ mock_file2 .is_file .return_value = True
71+ mock_file2 .is_dir .return_value = False
72+ mock_file2 .open .return_value .__enter__ .return_value .readlines .return_value = ["testhost2: remote_host2:remote_port2" ]
73+
74+ mock_dir = MagicMock ()
75+ mock_dir .is_dir .return_value = True
76+ mock_dir .is_file .return_value = False
77+
78+ mock_source_dir = MagicMock ()
79+ mock_source_dir .is_dir .return_value = True
80+ mock_source_dir .iterdir .return_value = [mock_file1 , mock_file2 , mock_dir ]
81+
82+ with patch ("websockify.token_plugins.Path" ) as mock_path :
83+ mock_path .return_value = mock_source_dir
84+ plugin = ReadOnlyTokenFile ('configdir' )
85+ result1 = plugin .lookup ('testhost1' )
86+ result2 = plugin .lookup ('testhost2' )
87+
88+ mock_path .assert_called_once_with ('configdir' )
89+ self .assertIsNotNone (result1 )
90+ self .assertIsNotNone (result2 )
91+ self .assertEqual (result1 , ["remote_host1" , "remote_port1" ])
92+ self .assertEqual (result2 , ["remote_host2" , "remote_port2" ])
93+
6394 def test_tabs (self ):
6495 mock_source_file = MagicMock ()
6596 mock_source_file .is_dir .return_value = False
0 commit comments