"""Product handler tests.""" import json from owsresponse import response from participant.handlers import product # noqa from participant.logic import label_participant as label_participant_logic mock_participations_response = [ { 'role': 'performer', 'labelParticipant': { 'id': 786281, 'name': 'L.G. Wise', 'vendorId': 8759, 'subaccountId': 0, 'spotifyId': '5xaT2601i5MC4h6yZa7EOD', 'appleMusicId': 111000530, }, } ] def test_get_label_participant_by_product_id(mocker, test_client): """Test label participant get by related product id success.""" product_id = 1 vendor_id = 24503 subaccount_id = 777 mocker.patch( 'participant.logic.label_participant.get_label_participants_by_related_product_id', # noqa return_value=response.Response(mock_participations_response, status=202), ) handler_response = test_client.get( f'/products/{product_id}/label-participants?' + f'vendor_id={vendor_id}&subaccount_id={subaccount_id}' ) result = json.loads(handler_response.data.decode()) label_participant_logic.get_label_participants_by_related_product_id.assert_called_with( # noqa 1, 24503, 777 ) assert handler_response.status_code == 202 assert result == mock_participations_response def test_get_label_participant_by_product_id_sends_400(mocker, test_client): """Test participant get by related product id sends 400 on non int id.""" product_id = '1wrong' vendor_id = 24503 subaccount_id = 777 mocker.patch( 'participant.logic.label_participant.get_label_participants_by_related_product_id', # noqa return_value=response.Response(mock_participations_response, status=202), ) handler_response = test_client.get( f'/products/{product_id}/label-participants?' + f'vendor_id={vendor_id}&subaccount_id={subaccount_id}' ) label_participant_logic.get_label_participants_by_related_product_id.assert_not_called() # noqa assert handler_response.status_code == 400 def test_get_participant_by_product_id(mocker, test_client): """Test the legacy participant get by related product id success.""" product_id = 1 vendor_id = 24503 subaccount_id = 777 mocker.patch( 'participant.logic.label_participant.get_label_participants_by_related_product_id', # noqa return_value=response.Response(mock_participations_response, status=202), ) handler_response = test_client.get( f'/products/{product_id}/participants?' + f'vendor_id={vendor_id}&subaccount_id={subaccount_id}' ) result = json.loads(handler_response.data.decode()) label_participant_logic.get_label_participants_by_related_product_id.assert_called_with( # noqa 1, 24503, 777 ) assert handler_response.status_code == 202 assert result == mock_participations_response