File size: 739 Bytes
2aaf2a2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import sys
import os
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')))

import pytest
from unittest.mock import patch
from utils import currency_utils

def test_get_usd_sgd_rate_success():
    with patch('yfinance.download') as mock_download:
        import pandas as pd
        df = pd.DataFrame({'Close': [1.3, 1.35]}, index=pd.date_range('2020-01-01', periods=2))
        mock_download.return_value = df
        rate = currency_utils.get_usd_sgd_rate()
        assert rate == 1.35

def test_get_usd_sgd_rate_fail():
    with patch('yfinance.download') as mock_download:
        mock_download.side_effect = Exception('fail')
        rate = currency_utils.get_usd_sgd_rate()
        assert rate == 1.0