"""Test for RomeConventionCountry and RomeConventionUnsigned models.""" from unittest.mock import MagicMock from unittest.mock import patch from oto import status as http_status import pytest from sqlalchemy.exc import SQLAlchemyError from prs.models.rome_convention import get_rome_convention_countries from prs.models.rome_convention import get_rome_convention_unsigned from tests.testutils import db @db.test_schema @pytest.mark.parametrize('method_name', [ get_rome_convention_countries, get_rome_convention_unsigned]) def test_get_rome_convention_models(method_name): """Test get_rome_convention_countries and get_rome_convention_unsigned.""" country_ids = [(1,), (2,)] expected_response = {'country_ids': country_ids} response = method_name() assert response.status == http_status.OK assert response.message == expected_response @patch('prs.connectors.mysql.ppb_database_session') @pytest.mark.parametrize('method_name', [ get_rome_convention_countries, get_rome_convention_unsigned]) def test_get_rome_convention_models_db_failure( ppb_db_session, method_name): """Test fatal db error. Test db error while calling get_rome_convention_countries and get_rome_convention_unsigned methods """ session = MagicMock() session.query = MagicMock(side_effect=SQLAlchemyError()) ppb_db_session.return_value = session response = method_name() assert response.status == http_status.INTERNAL_ERROR