"""Test for collection_society model.""" from unittest.mock import MagicMock from unittest.mock import patch from oto import status as http_status from sqlalchemy.exc import SQLAlchemyError from prs.connectors.mysql import ppb_db_session from prs.models import collection_society from tests.testutils import db @db.test_schema def test_get_society_id_by_country_id_success(): """Test get_society_id_by_country_id for success scenario.""" expected_response = {'society_id': 1} db.insert_to_table_raw(ppb_db_session(), db.INSERT_COLLECTION_SOCIETY) response = collection_society.get_society_id_by_country_id(1) assert response.status == http_status.OK assert response.message == expected_response @db.test_schema def test_get_society_id_by_country_id_not_found(): """Test get_society_id_by_country_id for not found scenario.""" expected_response = 'Society for country id:3 not found.' response = collection_society.get_society_id_by_country_id(3) assert response.status == http_status.NOT_FOUND assert response.errors['message'] == expected_response @patch('prs.connectors.mysql.ar_database_session') def test_get_society_id_by_country_id_db_failure( ar_db_session, mocker): """Test fatal db error when performing query for get society id.""" session = MagicMock() session.query = MagicMock(side_effect=SQLAlchemyError()) ar_db_session.return_value = session result = collection_society.get_society_id_by_country_id(1) assert result.status == http_status.INTERNAL_ERROR