| 1 |
import pytest |
| 2 |
from unittest.mock import patch |
| 3 |
from flask import Flask |
| 4 |
from a2d.routes.system import system_routes |
| 5 |
|
| 6 |
@pytest.fixture |
| 7 |
def client(): |
| 8 |
app = create_app() |
| 9 |
app.register_blueprint(system_routes) |
| 10 |
|
| 11 |
with app.test_client() as client: |
| 12 |
with app.app_context(): |
| 13 |
yield client |
| 14 |
|
| 15 |
def create_app(): |
| 16 |
app = Flask(__name__) |
| 17 |
app.config['TESTING'] = True |
| 18 |
app.secret_key = 'your_secret_key' # Example secret key for session |
| 19 |
return app |
| 20 |
|
| 21 |
def test_system_info(client): |
| 22 |
with client.session_transaction() as sess: |
| 23 |
sess['user_id'] = 1 # Example user ID |
| 24 |
|
| 25 |
# Mocking get_cpu_temperature, get_system_memory_usage, and get_cpu_load |
| 26 |
with patch('a2d.routes.system.get_cpu_temperature', return_value=50.0), \ |
| 27 |
patch('a2d.routes.system.get_system_memory_usage', return_value=50.0), \ |
| 28 |
patch('a2d.routes.system.get_cpu_load', return_value=50.0): |
| 29 |
|
| 30 |
rv = client.get('/system-info') |
| 31 |
assert rv.status_code == 302 # Expecting a redirect |
| 32 |
|
| 33 |
def test_system_info_no_login(client): |
| 34 |
# User not logged in |
| 35 |
rv = client.get('/system-info') |
| 36 |
assert rv.status_code == 302 # Redirect to login page or another location |