| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
import pytest |
| 6 |
import webbrowser |
| 7 |
import tempfile |
| 8 |
import platform |
| 9 |
import os |
| 10 |
from unittest.mock import patch |
| 11 |
|
| 12 |
|
| 13 |
from scalene.launchbrowser import launch_browser_insecure |
| 14 |
|
| 15 |
|
| 16 |
@pytest.fixture |
| 17 |
def mock_platform_system(): |
| 18 |
with patch("platform.system") as mock: |
| 19 |
yield mock |
| 20 |
|
| 21 |
|
| 22 |
@pytest.fixture |
| 23 |
def mock_webbrowser_register(): |
| 24 |
with patch("webbrowser.register") as mock: |
| 25 |
yield mock |
| 26 |
|
| 27 |
|
| 28 |
@pytest.fixture |
| 29 |
def mock_webbrowser_get(): |
| 30 |
with patch("webbrowser.get") as mock: |
| 31 |
yield mock |
| 32 |
|
| 33 |
|
| 34 |
def test_launch_browser_insecure( |
| 35 |
mock_platform_system, mock_webbrowser_register, mock_webbrowser_get |
| 36 |
): |
| 37 |
|
| 38 |
mock_platform_system.return_value = "Linux" |
| 39 |
|
| 40 |
mock_webbrowser_get.return_value.open.return_value = True |
| 41 |
|
| 42 |
test_url = "http://example.com" |
| 43 |
launch_browser_insecure(test_url) |
| 44 |
|
| 45 |
|
| 46 |
mock_webbrowser_register.assert_called_once() |
| 47 |
args, kwargs = mock_webbrowser_register.call_args |
| 48 |
assert args[0] == "chrome_with_flags" |
| 49 |
assert args[2] is not None |
| 50 |
assert kwargs["preferred"] is True |
| 51 |
|
| 52 |
|
| 53 |
mock_webbrowser_get.assert_called_once_with(args[2].name) |
| 54 |
mock_webbrowser_get.return_value.open.assert_called_once_with(test_url) |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|