"""Tests for physical product logic.""" from unittest.mock import MagicMock from unittest.mock import patch from sqlalchemy.exc import OperationalError from ows_product_physical.constant import error from ows_product_physical.logic import product_physical @patch('sqlalchemy.orm.session.Session.execute', MagicMock()) def test_healthcheck_success(): """Test healthcheck success.""" resp = product_physical.healthcheck() assert resp.status == 200 assert resp.message == dict(status='ok') @patch( 'sqlalchemy.orm.session.Session.execute', MagicMock( side_effect=OperationalError('a', 'b', 'c'))) def test_healthcheck_error(): """Test healthcheck: error.""" resp = product_physical.healthcheck() assert resp.status == 503 assert resp.errors.get('code') == error.INTERNAL_ERROR