asset-class-comparison / tests /unit /test_currency_utils.py
prasanth.thangavel
First commit of the app
2aaf2a2
raw
history blame
739 Bytes
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