File: test_reset.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 (83 lines) | stat: -rw-r--r-- 2,907 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
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
import pytest
from unittest.mock import patch
from flask import Flask
from a2d.routes.reset import reset_routes

@pytest.fixture
def app():
    """Fixture to create a Flask app instance."""
    app = Flask(__name__)
    app.config['TESTING'] = True
    app.register_blueprint(reset_routes)
    app.secret_key = 'test_secret_key'  # Set a secret key for session management
    return app

@pytest.fixture
def client(app):
    """Fixture to create a test client with app context."""
    with app.test_client() as client:
        with app.app_context():
            yield client

def test_reset_account(client):
    """Test case for resetting account with valid passphrase."""
    with client.session_transaction() as sess:
        sess['user_id'] = 1  # Example user ID

    # Mock passphrase verification and form data
    with patch('a2d.routes.reset.verify_passphrase', return_value=True):
        data = {
            'passphrase': 'testpassphrase',
            'reset_confirm': 'delete',
            'self_ssl_delete': 'true',
            'ca_ssl_delete': 'false'
        }
        rv = client.post('/reset-portal', data=data)
        
        assert rv.status_code == 302  # Expecting redirect upon successful reset

def test_reset_account_invalid_passphrase(client):
    """Test case for resetting account with invalid passphrase."""
    with client.session_transaction() as sess:
        sess['user_id'] = 1  # Example user ID

    # Mock invalid passphrase verification
    with patch('a2d.routes.reset.verify_passphrase', return_value=False):
        data = {
            'passphrase': 'wrongpass',
            'reset_confirm': 'delete',
            'self_ssl_delete': 'true',
            'ca_ssl_delete': 'false'
        }
        rv = client.post('/reset-portal', data=data)
        
        assert rv.status_code == 302  # Expecting redirect upon failure due to invalid passphrase

def test_reset_account_no_confirmation(client):
    """Test case for resetting account without confirmation."""
    with client.session_transaction() as sess:
        sess['user_id'] = 1  # Example user ID

    # No confirmation provided
    data = {
        'passphrase': 'testpassphrase',
        'reset_confirm': '',
        'self_ssl_delete': 'false',
        'ca_ssl_delete': 'false'
    }
    rv = client.post('/reset-portal', data=data)
    
    assert rv.status_code == 302  # Expecting redirect or another appropriate status code

def test_reset_account_no_login(client):
    """Test case for resetting account without user logged in."""
    # No user logged in scenario
    data = {
        'passphrase': 'testpassphrase',
        'reset_confirm': 'delete',
        'self_ssl_delete': 'true',
        'ca_ssl_delete': 'false'
    }
    rv = client.post('/reset-portal', data=data, follow_redirects=True)
    
    assert rv.status_code == 404  # Expecting 404 when endpoint is not reachable without login