"""Tests for Currency model.""" from unittest.mock import patch from sqlalchemy.exc import SQLAlchemyError from ows_accounting.models import currency def test_get_currency_by_id(db_fixture): """Test getting currency by id.""" expected_response = { 'id': 1, 'code': 'USD', 'symbol': '$', 'name': 'United States Dollar', } response = currency.get_currency_by_id(1) assert response.status assert response.message == expected_response def test_get_currency_by_id_from_cache_list(db_fixture): """Test getting currency by id from cached list.""" expected_response = { 'id': 5, 'code': 'GBP', 'symbol': '£', 'name': 'British Pound', } currency._cached_currencies.append( currency.Currency( currency_id=5, code='GBP', symbol='£', name='British Pound').as_dict()) response = currency.get_currency_by_id(5) assert response.status assert response.message == expected_response def test_get_currency_by_id_not_found(db_fixture): """Test getting no currency.""" response = currency.get_currency_by_id(105) assert response.status == 404 @patch('ows_accounting.utils.mysql.db_session', side_effect=SQLAlchemyError()) def test_get_currency_by_id_exception(monkeypatch): """Test getting currency with exception.""" response = currency.get_currency_by_id(100) assert response.status == 500