File: test_system.py

package info (click to toggle)
a2d 2.0.5-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,088 kB
  • sloc: javascript: 4,806; python: 1,873; xml: 49; sh: 44; makefile: 17
file content (36 lines) | stat: -rw-r--r-- 1,186 bytes parent folder | download
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
import pytest
from unittest.mock import patch
from flask import Flask
from a2d.routes.system import system_routes

@pytest.fixture
def client():
    app = create_app()
    app.register_blueprint(system_routes)

    with app.test_client() as client:
        with app.app_context():
            yield client

def create_app():
    app = Flask(__name__)
    app.config['TESTING'] = True
    app.secret_key = 'your_secret_key'  # Example secret key for session
    return app

def test_system_info(client):
    with client.session_transaction() as sess:
        sess['user_id'] = 1  # Example user ID

    # Mocking get_cpu_temperature, get_system_memory_usage, and get_cpu_load
    with patch('a2d.routes.system.get_cpu_temperature', return_value=50.0), \
         patch('a2d.routes.system.get_system_memory_usage', return_value=50.0), \
         patch('a2d.routes.system.get_cpu_load', return_value=50.0):

        rv = client.get('/system-info')
        assert rv.status_code == 302  # Expecting a redirect

def test_system_info_no_login(client):
    # User not logged in
    rv = client.get('/system-info')
    assert rv.status_code == 302  # Redirect to login page or another location