Spaces:
Sleeping

File size: 1,386 Bytes
a289188
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8625b3d
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
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
from models.database import get_connection, query_db, execute_db


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


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


class TestDatabaseConnection:
    def test_connection(self):
        conn = get_connection()
        assert conn is not None
        conn.close()

    def test_query_db(self):
        result = query_db("SELECT 1 as test")
        assert result is not None

    def test_get_all_tables(self):
        from models.database import get_all_tables
        tables = get_all_tables()
        assert isinstance(tables, list)


class TestSchema:
    def test_tables_exist_after_init(self, app):
        with app.app_context():
            from models.database import table_exists
            expected = ['model_metrics', 'pipeline_runs', 'api_logs', 'stream_events']
            for table in expected:
                assert table_exists(table), f"Table {table} should exist"

    def test_row_count(self, app):
        with app.app_context():
            from models.database import get_row_count
            count = get_row_count('model_metrics')
            assert isinstance(count, int)
            assert count >= 0