File size: 1,553 Bytes
faa3050
 
d79b7f7
faa3050
 
d79b7f7
faa3050
 
d79b7f7
 
 
faa3050
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d79b7f7
faa3050
d79b7f7
faa3050
d79b7f7
faa3050
 
d79b7f7
faa3050
 
 
d79b7f7
faa3050
d79b7f7
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
from unittest.mock import patch
from pathlib import Path
import sys
import os

# Add src to path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../src')))

from pipeline import process_invoice

# --- MOCK DATA ---
# This is what we pretend the ML model returned
MOCK_ML_RESPONSE = {
    "vendor": "MOCKED VENDOR INC",
    "date": "2023-01-01",
    "total_amount": "100.00",
    "receipt_number": "MOCK-123",
    "address": "123 Mock Street",
    "bill_to": "Mock Customer",
    "items": [],
    "raw_text": "Mocked raw text content"
}

@patch('pipeline.extract_rule_based')
def test_pipeline_rule_based(mock_extract):
    mock_extract.return_value = MOCK_ML_RESPONSE

    with patch('pathlib.Path.exists', return_value=True):
        result = process_invoice("fake_invoice.jpg", method="rules")

    assert result['vendor'] == "MOCKED VENDOR INC"
    assert result['validation_status'] == "passed"
    mock_extract.assert_called_once()

@patch('pipeline.extract_ml_based')
def test_pipeline_ml_mocked(mock_extract):
    """

    Tests the ML pipeline WITHOUT loading the heavy model.

    """
    mock_extract.return_value = MOCK_ML_RESPONSE

    with patch('pathlib.Path.exists', return_value=True):
        result = process_invoice("fake_invoice.jpg", method="ml")

    assert result['vendor'] == "MOCKED VENDOR INC"
    assert result['receipt_number'] == "MOCK-123"
    assert result['validation_status'] == "passed"

    mock_extract.assert_called_once()