File size: 2,245 Bytes
e8013a0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | import pytest
from unittest.mock import patch
from app import main
# Mock Streamlit and other dependencies within the app module
@pytest.fixture
def mock_st():
with patch('app.st') as mock:
yield mock
@pytest.fixture
def mock_render_navigation():
with patch('ui.navigation.render_navigation.render_navigation') as mock:
yield mock
@pytest.fixture
def mock_render_home():
with patch('ui.home.render_home.render_home') as mock:
yield mock
@pytest.fixture
def mock_render_infos():
with patch('ui.infos.render_infos.render_infos') as mock:
yield mock
@pytest.fixture
def mock_render_todos():
with patch('ui.todos.render_todos.render_todos') as mock:
yield mock
@pytest.fixture
def mock_setup_page_config():
with patch('configuration.config.setup_page_config') as mock:
yield mock
@pytest.fixture
def mock_documentations():
with patch('scr.documentation.documentations') as mock:
yield mock
@pytest.fixture
def mock_authenticate_user():
with patch('app.authenticate_user') as mock:
yield mock
def test_main_authenticated(
mock_st,
mock_authenticate_user,
mock_render_navigation,
mock_render_home,
mock_render_infos,
mock_render_todos,
mock_setup_page_config,
mock_documentations
):
mock_authenticate_user.return_value = True
result = main(run_setup=False, test_mode=True)
assert result is True
mock_setup_page_config.assert_not_called()
mock_authenticate_user.assert_called_once()
mock_render_navigation.assert_not_called()
mock_documentations.assert_not_called()
mock_render_home.assert_not_called()
mock_render_infos.assert_not_called()
mock_render_todos.assert_not_called()
def test_main_not_authenticated(
mock_st,
mock_authenticate_user,
mock_setup_page_config,
mock_documentations
):
mock_authenticate_user.return_value = False
result = main(run_setup=False, test_mode=True)
assert result is False
mock_setup_page_config.assert_not_called()
mock_authenticate_user.assert_called_once()
mock_documentations.assert_not_called()
mock_st.error.assert_not_called()
|