"""Test for model product.""" from unittest.mock import patch import pytest from owsresponse import response from notifications.models import product from tests.unit.conftest import get_session_mock @pytest.mark.parametrize( 'data, expected_result', [ ( { 'product': {'product': 'details'}, 'project': {'project': 'details'}, 'artist': {'artist': 'details'}, }, response.Response( { 'product': 'details', 'artist': {'artist': 'details'}, 'project': {'project': 'details'}, } ), ), ({}, response.create_not_found_response('No product found with id 1234.')), ( { 'product': {'product': 'details', 'deletions': True}, 'project': {'project': 'details'}, 'artist': {'artist': 'details'}, }, response.create_not_found_response('Product with id 1234 is deleted.'), ), ], ) def test_get_product_details_by_id(data, expected_result): """Test get_product_details_by_id.""" product_id = '1234' session_mock = get_session_mock([data]) with patch('notifications.models.product.get_session', return_value=session_mock): result = product.get_product_details_by_id(product_id) assert result.status == expected_result.status if expected_result: assert result.message == expected_result.message else: assert result.errors == expected_result.errors assert session_mock.run.call_count == 1 assert session_mock.run.call_args[0] == ( 'MATCH (p:Product)<-[r:INCLUDES]-(pr:Project)-[ha:HAS_ARTIST]->(ai:ArtistInfo) WHERE p.id = $productId RETURN p as product, pr as project, ai as artist', # noqa: E501 ) assert session_mock.run.call_args[1] == {'productId': int(product_id)}