File size: 1,582 Bytes
447ebeb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 json
import os
import sys

import pytest
from fastapi.testclient import TestClient

sys.path.insert(
    0, os.path.abspath("../../../..")
)  # Adds the parent directory to the system path


import json
import os
import sys
import time

import pytest
from fastapi.testclient import TestClient

import litellm


def test_check_migration_out_of_sync(mocker):
    """
    Test that the check_prisma_schema_diff function
    - 🚨 [IMPORTANT] Does NOT Raise an Exception when the Prisma schema is out of sync with the database.
    - logs an error when the Prisma schema is out of sync with the database.
    """
    # Mock the logger BEFORE importing the function
    mock_logger = mocker.patch("litellm._logging.verbose_logger")

    # Import the function after mocking the logger
    from litellm.proxy.db.check_migration import check_prisma_schema_diff

    # Mock the helper function to simulate out-of-sync state
    mock_diff_helper = mocker.patch(
        "litellm.proxy.db.check_migration.check_prisma_schema_diff_helper",
        return_value=(True, ["ALTER TABLE users ADD COLUMN new_field TEXT;"]),
    )

    # Run the function - it should not raise an error
    try:
        check_prisma_schema_diff(db_url="mock_url")
    except Exception as e:
        pytest.fail(f"check_prisma_schema_diff raised an unexpected exception: {e}")

    # Verify the logger was called with the expected message
    mock_logger.exception.assert_called_once()
    actual_message = mock_logger.exception.call_args[0][0]
    assert "prisma schema out of sync with db" in actual_message