"""Test for RomeConventionCountry 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_delivery_history from tests.testutils import db @db.test_schema @pytest.mark.parametrize('description,label_ids', [ ('Label history found', [101, 102, 103]), ('Label history not found', [104, 105, 106])]) def test_get_last_delivery_by_vendor_and_society_id( description, label_ids): """Test get_last_delivery_by_vendor_and_society_id for success.""" society_id = 1 response = label_delivery_history.\ get_last_delivery_by_vendor_and_society_id(society_id, label_ids) assert response.status == http_status.OK assert response.message @patch('prs.connectors.mysql.ppb_database_session') def test_get_last_delivery_by_vendor_and_society_id_db_failure( ppb_db_session): """Test fatal db error while querying for get last delivery data.""" session = MagicMock() session.query = MagicMock(side_effect=SQLAlchemyError()) ppb_db_session.return_value = session society_id = 1 label_ids = [101, 102, 103] result = label_delivery_history.\ get_last_delivery_by_vendor_and_society_id(society_id, label_ids) assert result.status == http_status.INTERNAL_ERROR