Coverage for tests / unit / utils / test_plugins_handler.py: 0%

32 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-03-20 10:09 -0400

1import pytest 

2from pathlib import Path 

3from unittest.mock import patch, MagicMock 

4from graphqler.utils import plugins_handler 

5from graphqler.utils.protocols.request_utils_protocol import RequestUtilsProtocol 

6 

7@pytest.fixture 

8def mock_plugin_path(): 

9 return Path(__file__).parent / "mock_plugins" 

10 

11def test_does_plugin_exist(mock_plugin_path): 

12 with patch('graphqler.config.PLUGINS_PATH', mock_plugin_path): 

13 assert plugins_handler.does_plugin_exist("request_utils.py") 

14 assert not plugins_handler.does_plugin_exist("nonexistent.py") 

15 

16def test_get_plugin_path(): 

17 plugin_name = "test_plugin.py" 

18 path = plugins_handler.get_plugin_path(plugin_name) 

19 assert isinstance(path, Path) 

20 assert path.name == plugin_name 

21 

22def test_get_request_utils_with_valid_plugin(mock_plugin_path): 

23 with patch('graphqler.config.PLUGINS_PATH', mock_plugin_path): 

24 utils = plugins_handler.get_request_utils() 

25 assert isinstance(utils, RequestUtilsProtocol) 

26 # Test actual mock implementation 

27 response = utils.send_graphql_request("http://example.com", {"query": "test"}) 

28 assert response[0] == {"data": {"message": "Success"}} 

29 

30def test_get_plugin_fallback_to_default(): 

31 with patch('graphqler.utils.plugins_handler.does_plugin_exist', return_value=False): # Fixed path 

32 plugin = plugins_handler.get_plugin("request_utils.py") 

33 assert plugin == plugins_handler.POSSIBLE_PLUGINS["request_utils.py"] 

34 

35def test_invalid_plugin_structure(): 

36 with pytest.raises(AssertionError): 

37 with patch('graphqler.utils.plugins_handler.get_plugin') as mock_get_plugin: # Fixed path 

38 mock_get_plugin.return_value = MagicMock(spec=[]) # Empty plugin without required methods 

39 plugins_handler.get_request_utils()