Spaces:
Sleeping

File size: 3,092 Bytes
a289188
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8625b3d
 
 
 
a289188
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
96
import pytest
import os
import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from app import create_app


@pytest.fixture
def app():
    app = create_app()
    app.config['TESTING'] = True
    return app


@pytest.fixture
def client(app):
    return app.test_client()


class TestPageRoutes:
    """Test that all page routes return 200."""
    pages = ['/', '/ingestion', '/sql', '/python', '/eda', '/visualization',
             '/bigdata', '/architecture', '/dataflow', '/webscraping',
             '/warehouse', '/pipeline', '/outofcore', '/distributed',
             '/streaming', '/probability', '/supervised', '/unsupervised',
             '/timeseries', '/deployment', '/admin']

    @pytest.mark.parametrize('page', pages)
    def test_page_loads(self, client, page):
        response = client.get(page)
        assert response.status_code == 200, f"Page {page} returned {response.status_code}"


class TestAPIEndpoints:
    def test_summary(self, client):
        response = client.get('/api/summary')
        assert response.status_code == 200
        data = response.get_json()
        assert 'tables' in data

    def test_housing(self, client):
        response = client.get('/api/housing')
        assert response.status_code == 200
        data = response.get_json()
        assert 'data' in data

    def test_transport(self, client):
        response = client.get('/api/transport')
        assert response.status_code == 200

    def test_eda(self, client):
        response = client.get('/api/eda')
        assert response.status_code == 200

    def test_validate(self, client):
        response = client.get('/api/validate')
        assert response.status_code == 200

    def test_sql_select(self, client):
        response = client.post('/api/sql/execute',
                               json={'query': 'SELECT 1 as test'})
        assert response.status_code == 200
        data = response.get_json()
        assert 'results' in data

    def test_sql_blocks_write(self, client):
        """SQL endpoint must block write operations."""
        dangerous_queries = [
            'DROP TABLE test_table',
            'DELETE FROM test_table',
            'INSERT INTO test_table VALUES (1)',
            'UPDATE test_table SET col="X"',
        ]
        for q in dangerous_queries:
            response = client.post('/api/sql/execute', json={'query': q})
            assert response.status_code == 400, f"Should block: {q}"

    def test_feedback(self, client):
        response = client.post('/api/feedback', json={
            'module': 'test',
            'rating': 5,
            'comment': 'Great module!'
        })
        assert response.status_code == 200

    def test_stream_generate(self, client):
        response = client.post('/api/stream/generate', json={'count': 5})
        assert response.status_code == 200
        data = response.get_json()
        assert 'events' in data

    def test_stream_stats(self, client):
        response = client.get('/api/stream/stats')
        assert response.status_code == 200