"""Test for LabelTerritoryException model.""" 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 import label_territory_exception from tests.testutils import db @db.test_schema @pytest.mark.parametrize('description, label_id_list, country_id', [ ('Label ids found', [(101,), (102,), (103,)], 1), ('Label ids not found', [], 2)]) def test_get_label_id_by_country_id( description, label_id_list, country_id, monkeypatch): """Test get_label_id_by_country_id.""" expected_response = {'label_ids': label_id_list} response = label_territory_exception.get_label_id_by_country_id(country_id) assert response.status == http_status.OK assert response.message == expected_response @patch('prs.connectors.mysql.ppb_database_session') def test_get_label_id_by_country_id_db_failure( ppb_db_session, mocker): """Test fatal db error when performing query for get label ids.""" session = MagicMock() session.query = MagicMock(side_effect=SQLAlchemyError()) ppb_db_session.return_value = session result = label_territory_exception.get_label_id_by_country_id(1) assert result.status == http_status.INTERNAL_ERROR