File size: 1,107 Bytes
4a30717
 
7a2cc57
 
 
 
4a30717
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# tests/test_analyzer.py
import pytest
from modules.analyzer import Analyzer

def test_analyzer_init():
    analyzer = Analyzer(base_url="https://test.api", api_key="test_key")
    assert analyzer.client.base_url == "https://test.api/"
    assert analyzer.client.api_key == "test_key"

def test_analyzer_analyze(monkeypatch):
    # Mock the OpenAI client response
    class MockChoice:
        def __init__(self):
            self.message = MockMessage()

    class MockMessage:
        def __init__(self):
            self.content = "Test analysis result"

    class MockResponse:
        def __init__(self):
            self.choices = [MockChoice()]

    class MockClient:
        def chat.completions.create(self, *args, **kwargs):
            return MockResponse()

    def mock_openai_init(*args, **kwargs):
        return MockClient()

    monkeypatch.setattr("modules.analyzer.OpenAI", mock_openai_init)
    
    analyzer = Analyzer(base_url="https://test.api", api_key="test_key")
    result = analyzer.analyze("test query", [{"content": "test content"}])
    assert result == "Test analysis result"